當智慧體需要查找資訊來回答問題或完成任務時,可以使用網頁搜尋。
範例:解釋火星為什麼看起來是紅色的
將這份 JSON 主體傳送至 POST /v1/agents/sessions,即可建立工作階段並以串流方式傳回答案。這會啟用 live 模式的網頁搜尋:
{
"agent": {
"model": "gpt-6-astra",
"reasoning": { "effort": "low" },
"tools": [{ "type": "web_search", "mode": "live" }]
},
"environment": { "type": "none" },
"input": "Search NASA's website for why Mars looks red. Explain it in two sentences and include a source link.",
"stream": true
}
結果
在 2026 年 9 月 10 日的一次測試中,智慧體搜尋了 NASA 網站,並以串流方式傳回以下答案:
Mars looks red because iron minerals in its soil oxidize, or rust, giving the surface a reddish color. This rusty appearance is why it’s called the “Red Planet,” according to NASA’s Mars Facts.
這是先前執行時記錄的範例。你收到的答案可能有所不同。
如果 agent.tools 中未包含 web_search,內建的網頁搜尋功能就不會啟用。在提示詞中要求搜尋,也不會啟用這項功能。
搜尋模式
live(預設):允許搜尋功能即時存取網際網路。當你加入web_search但未指定mode時,會使用此模式。cached:搜尋已儲存的網頁內容,不即時存取網際網路。disabled:關閉內建的網頁搜尋功能,效果與未加入此工具相同。
選用設定
將以下欄位加入同一個 web_search 項目:
| 設定 | 用途 | 省略時的行為 |
|---|---|---|
context_size | 模型從搜尋中接收的資訊量:low、medium 或 high。 | 使用 medium。 |
allowed_domains | 搜尋可涵蓋哪些網站。最多可提供 100 個網域名稱,例如 ["python.org", "docs.python.org"]。 | 不套用網域篩選條件。 |
location | 協助根據地點調整搜尋結果。接受 country、region、city 和 timezone。 | 不向搜尋功能提供位置資訊。缺少詳細位置資訊,可能使搜尋結果的相關性較低,或在搜尋當地資訊時找不到有用的結果。 |