當智慧體需要查找資訊才能回答問題或完成任務時,可以使用網頁搜尋。
範例:解釋火星為什麼看起來是紅色的
將以下 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 網站,並以串流方式傳回以下回答:
火星土壤中的含鐵礦物會氧化,也就是生鏽,使火星表面呈現紅色。根據 NASA 的火星介紹,火星正是因為這種鐵鏽般的色澤而得名「紅色行星」。
這是當次測試的紀錄。你收到的回答可能會有所不同。
如果未將 web_search 加入 agent.tools,內建網頁搜尋就會保持關閉。只在提示詞中要求搜尋,並不會啟用這項功能。
搜尋模式
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。 |
搜尋工具不會收到位置資訊。搜尋當地資訊時,若缺少位置細節,結果的相關性可能較低,也可能找不到有用的結果。 |