网页工具

OpenClaw 附带两个轻量级网页工具:

  • web_search - 通过 Brave Search API(默认)、Perplexity Sonar 或带 Google Search grounding 的 Gemini 进行网页搜索。
  • web_fetch - HTTP 抓取 + 可读内容提取(HTML 或 markdown/text)。

这些不是浏览器自动化。对于 JS 密集型网站或登录,请使用浏览器工具

工作原理

  • web_search 调用你配置的 provider 并返回结果:
    • Brave(默认):返回结构化结果(标题、URL、摘要)。
    • Perplexity:返回来自实时网页搜索的 AI 综合答案及引用。
    • Gemini:返回基于 Google Search 的 AI 综合答案及引用。
  • 结果按查询缓存 15 分钟(可配置)。
  • web_fetch 执行普通 HTTP GET 并提取可读内容(HTML 或 markdown/text)。它不会执行 JavaScript。
  • web_fetch 默认启用(除非明确禁用)。

选择搜索 provider

Provider优点缺点API 密钥
Brave(默认)快速、结构化结果、有免费套餐传统搜索结果BRAVE_API_KEY
PerplexityAI 综合答案、引用、实?需?Perplexity ?OpenRouter 访问OPENROUTER_API_KEY ?PERPLEXITY_API_KEY
GeminiGoogle Search grounding、AI 综合答案需?Gemini API 密钥GEMINI_API_KEY

参见 Brave Search 设置 ?Perplexity Sonar 以获?provider 特定详情?

自动检?

如果没有明确设置 provider,OpenClaw 根据可用?API 密钥自动检测要使用?provider,按此顺序检查:

  1. Brave ?BRAVE_API_KEY 环境变量?search.apiKey 配置
  2. Gemini ?GEMINI_API_KEY 环境变量?search.gemini.apiKey 配置
  3. Perplexity ?PERPLEXITY_API_KEY / OPENROUTER_API_KEY 环境变量?search.perplexity.apiKey 配置
  4. Grok ?XAI_API_KEY 环境变量?search.grok.apiKey 配置

如果没有找到密钥,它回退?Brave(你会收到缺少密钥的错误,提示你配置一个)?

明确设置 provider

在配置中设置 provider?

{
  tools: {
    web: {
      search: {
        provider: "brave", // ?"perplexity" ?"gemini"
      },
    },
  },
}

示例:切换到 Perplexity Sonar(直?API):

{
  tools: {
    web: {
      search: {
        provider: "perplexity",
        perplexity: {
          apiKey: "pplx-...",
          baseUrl: "https://api.perplexity.ai",
          model: "perplexity/sonar-pro",
        },
      },
    },
  },
}

获取 Brave API 密钥

  1. ?https://brave.com/search/api/ 创建 Brave Search API 账户
  2. 在仪表板中,选择 Data for Search 计划(不?Data for AI”)并生成 API 密钥?
  3. 运行 openclaw configure --section web 将密钥存储在配置中(推荐),或在环境中设?BRAVE_API_KEY?

Brave 提供免费套餐和付费计划;请查?Brave API 门户以了解当前限制和定价?

设置密钥的位置(推荐?

**推荐?*运行 openclaw configure --section web。它将密钥存储在 ~/.openclaw/openclaw.json 下的 tools.web.search.apiKey 中?

**环境替代方案?*?Gateway 进程环境中设?BRAVE_API_KEY。对?gateway 安装,将其放?~/.openclaw/.env(或你的服务环境)。参见环境变量?

使用 Perplexity(直接或通过 OpenRouter?

Perplexity Sonar 模型具有内置的网页搜索功能,返回带有引用?AI 综合答案。你可以通过 OpenRouter 使用它们(无需信用卡——支持加密货?预付费)?

获取 OpenRouter API 密钥

  1. ?https://openrouter.ai/ 创建账户
  2. 添加信用额度(支持加密货币、预付费或信用卡?
  3. 在账户设置中生成 API 密钥

设置 Perplexity 搜索

{
  tools: {
    web: {
      search: {
        enabled: true,
        provider: "perplexity",
        perplexity: {
          // API 密钥(如果设置了 OPENROUTER_API_KEY ?PERPLEXITY_API_KEY 则可选)
          apiKey: "sk-or-v1-...",
          // Base URL(如果省略则根据密钥来源有默认值)
          baseUrl: "https://openrouter.ai/api/v1",
          // 模型(默认为 perplexity/sonar-pro?
          model: "perplexity/sonar-pro",
        },
      },
    },
  },
}

**环境替代方案?*?Gateway 环境中设?OPENROUTER_API_KEY ?PERPLEXITY_API_KEY。对?gateway 安装,将其放?~/.openclaw/.env?

如果没有设置 base URL,OpenClaw 根据 API 密钥来源选择默认值:

  • PERPLEXITY_API_KEY ?pplx-... ?https://api.perplexity.ai
  • OPENROUTER_API_KEY ?sk-or-... ?https://openrouter.ai/api/v1
  • 未知密钥格式 ?OpenRouter(安全回退?

可用?Perplexity 模型

模型描述适用?
perplexity/sonar带网页搜索的快速问?快速查?
perplexity/sonar-pro(默认)带网页搜索的多步推理复杂问题
perplexity/sonar-reasoning-pro思维链分?深度研究

使用 Gemini(Google Search grounding?

Gemini 模型支持内置?Google Search grounding,返回由实时 Google Search 结果支持?AI 综合答案及引用?

获取 Gemini API 密钥

  1. 前往 Google AI Studio
  2. 创建 API 密钥
  3. ?Gateway 环境中设?GEMINI_API_KEY,或配置 tools.web.search.gemini.apiKey

设置 Gemini 搜索

{
  tools: {
    web: {
      search: {
        provider: "gemini",
        gemini: {
          // API 密钥(如果设置了 GEMINI_API_KEY 则可选)
          apiKey: "AIza...",
          // 模型(默认为 "gemini-2.5-flash"?
          model: "gemini-2.5-flash",
        },
      },
    },
  },
}

**环境替代方案?*?Gateway 环境中设?GEMINI_API_KEY? 对于 gateway 安装,将其放?~/.openclaw/.env?

注意

  • Gemini grounding 的引?URL 会自动从 Google 的重定向 URL 解析为直?URL?
  • 重定向解析使?SSGuard 路径(HEAD + 重定向检?+ http/https 验证)然后返回最终引?URL?
  • 此重定向解析器遵循可信网络模型(默认允许私有/内部网络)以匹配 Gateway 操作者的信任假设?
  • 默认模型(gemini-2.5-flash)快速且具有成本效益? 任何支持 grounding ?Gemini 模型都可以使用?

使用你配置的 provider 搜索网页?

需?

  • tools.web.search.enabled 不能?false(默认:启用?
  • 你所?provider ?API 密钥?
    • BraveBRAVE_API_KEY ?tools.web.search.apiKey
    • PerplexityOPENROUTER_API_KEYPERPLEXITY_API_KEY ?tools.web.search.perplexity.apiKey

配置

{
  tools: {
    web: {
      search: {
        enabled: true,
        apiKey: "BRAVE_API_KEY_HERE", // 如果设置?BRAVE_API_KEY 则可?
        maxResults: 5,
        timeoutSeconds: 30,
        cacheTtlMinutes: 15,
      },
    },
  },
}

工具参数

  • query(必需?
  • count?-10;默认来自配置)
  • country(可选)? 个字母的国家/地区代码,用于特定地区结果(例如 “DE”?US”?ALL”)。如果省略,Brave 选择其默认地区?
  • search_lang(可选):搜索结果的 ISO 语言代码(例?“de”?en”?fr”?
  • ui_lang(可选):UI 元素?ISO 语言代码
  • freshness(可选):按发现时间过滤
    • Brave:pdpwpmpy ?YYYY-MM-DD ?YYYY-MM-DD
    • Perplexity:pdpwpmpy

*示例?

// 德国特定搜索
await web_search({
  query: "TV online schauen",
  count: 10,
  country: "DE",
  search_lang: "de",
});

// 法国搜索带法?UI
await web_search({
  query: "actualités",
  country: "FR",
  search_lang: "fr",
  ui_lang: "fr",
});

// 最近结果(过去一周)
await web_search({
  query: "TMBG interview",
  freshness: "pw",
});

web_fetch

抓取 URL 并提取可读内容?

web_fetch 需?

  • tools.web.fetch.enabled 不能?false(默认:启用?
  • 可选的 Firecrawl 回退:设?tools.web.fetch.firecrawl.apiKey ?FIRECRAWL_API_KEY?

web_fetch 配置

{
  tools: {
    web: {
      fetch: {
        enabled: true,
        maxChars: 50000,
        maxCharsCap: 50000,
        maxResponseBytes: 2000000,
        timeoutSeconds: 30,
        cacheTtlMinutes: 15,
        maxRedirects: 3,
        userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 14_7_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
        readability: true,
        firecrawl: {
          enabled: true,
          apiKey: "FIRECRAWL_API_KEY_HERE", // 如果设置?FIRECRAWL_API_KEY 则可?
          baseUrl: "https://api.firecrawl.dev",
          onlyMainContent: true,
          maxAgeMs: 86400000, // 毫秒? 天)
          timeoutSeconds: 60,
        },
      },
    },
  },
}

web_fetch 工具参数

  • url(必需,仅 http/https?
  • extractModemarkdown | text?
  • maxChars(截断长页面?

注意?

  • web_fetch 首先使用 Readability(主内容提取),然后?Firecrawl(如果配置)。如果两者都失败,工具返回错误?
  • Firecrawl 请求默认使用反机器人模式并缓存结果?
  • web_fetch 默认发送类?Chrome ?User-Agent ?Accept-Language;如需要可覆盖 userAgent?
  • web_fetch 阻止私有/内部主机名并重新检查重定向(用 maxRedirects 限制)?
  • maxChars 被限制到 tools.web.fetch.maxCharsCap?
  • web_fetch 将下载的响应体大小限制到 tools.web.fetch.maxResponseBytes 然后再解析;过大的响应会被截断并包含警告?
  • web_fetch 是尽力而为的提取;某些网站可能需要浏览器工具?
  • 参见 Firecrawl 以获取密钥设置和服务详情?
  • 响应被缓存(默认 15 分钟)以减少重复抓取?
  • 如果你使用工具配?白名单,添加 web_search/web_fetch ?group:web?
  • 如果缺少 Brave 密钥,web_search 返回包含文档链接的简短设置提示?