For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
主导航

网页搜索

使用 OpenAI 内置的网页搜索查找信息。

当您的智能体需要查找信息来回答问题或完成任务时,可以使用网页搜索。

示例:解释为什么火星看起来是红色的

将此 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模型从搜索中接收的信息量:lowmediumhigh使用 medium
allowed_domains搜索可以包含哪些网站。最多提供 100 个域名,例如 ["python.org", "docs.python.org"]不应用域名筛选。
location帮助根据地点调整结果。接受 countryregioncitytimezone不向搜索提供位置信息。缺少位置详情可能导致本地搜索结果的相关性降低,或无法找到有用的匹配结果。