Web 工具

Web 工具

OpenClaw 自带两个轻量级 Web 工具:

这些 不是 浏览器自动化。对于 JS 密集型站点或登录,使用
[浏览器工具(../tools/browser.html)。

工作原理

选择搜索 Provider

Provider 优点 缺点 API 密钥
Brave(默认) 快速、结构化结果、免费层 传统搜索结果 BRAVE_API_KEY
Perplexity AI 合成答案、引用、实时 需要 Perplexity 或 OpenRouter 访问 OPENROUTER_API_KEYPERPLEXITY_API_KEY

参见 Brave Search 设置Perplexity Sonar 了解 Provider 特定详情。

在配置中设置 Provider:

{
  tools: {
    web: {
      search: {
        provider: "brave"  // 或 "perplexity"
      }
    }
  }
}

示例:切换到 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.jsontools.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-...",
          // 基础 URL(如果省略则自动选择)
          baseUrl: "https://openrouter.ai/api/v1",
          // 模型(默认为 perplexity/sonar-pro)
          model: "perplexity/sonar-pro"
        }
      }
    }
  }
}

环境替代方案: 在 Gateway 环境中设置 OPENROUTER_API_KEYPERPLEXITY_API_KEY
对于 Gateway 安装,将其放在 ~/.openclaw/.env 中。

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

可用的 Perplexity 模型

模型 描述 最适合
perplexity/sonar 快速问答 + 网页搜索 快速查找
perplexity/sonar-pro(默认) 多步推理 + 网页搜索 复杂问题
perplexity/sonar-reasoning-pro 思维链分析 深度研究

web_search

使用你配置的 Provider 搜索网页。

要求

配置

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

工具参数

示例:

// 德语特定搜索
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 并提取可读内容。

要求

配置

{
  tools: {
    web: {
      fetch: {
        enabled: true,
        maxChars: 50000,
        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, // ms(1 天)
          timeoutSeconds: 60
        }
      }
    }
  }
}

工具参数

说明: