Skip to Content
👋 欢迎来到 HowToUseMoltbot 快速入门
工具Web 工具

Web 工具

Moltbot 提供两个轻量 Web 工具:

  • web_search — 通过 Brave Search API(默认)或 Perplexity Sonar(直接或经 OpenRouter)进行网页搜索。
  • web_fetch — HTTP 抓取 + 可读内容提取(HTML → markdown/text)。

这些不是浏览器自动化。对重度 JS 或需登录的站点,请使用 Browser 工具

工作原理

  • web_search 调用你配置的提供商并返回结果。
    • Brave(默认):返回结构化结果(标题、URL、摘要)。
    • Perplexity:返回基于实时搜索的 AI 综合答案及引用。
  • 结果按查询缓存 15 分钟(可配置)。
  • web_fetch 执行普通 HTTP GET 并提取可读内容(HTML → markdown/text),执行 JavaScript。
  • web_fetch 默认启用(除非显式关闭)。

选择搜索提供商

提供商优点缺点API Key
Brave(默认)快速、结构化、有免费档传统搜索结果BRAVE_API_KEY
PerplexityAI 综合答案、引用、实时需 Perplexity 或 OpenRouterOPENROUTER_API_KEYPERPLEXITY_API_KEY

提供商详情见 Brave Search 设置Perplexity Sonar。在配置中设置提供商:

{ 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 Key

  1. https://brave.com/search/api/  创建 Brave Search API 账号。
  2. 在控制台选择 Data for Search 计划(非“Data for AI”),生成 API key。
  3. 运行 moltbot configure --section web 将 key 存入配置(推荐),或在环境中设置 BRAVE_API_KEY

Brave 提供免费档与付费计划;当前限额与定价请查看 Brave API 门户。

推荐设置位置

推荐:运行 moltbot configure --section web。key 会存入 ~/.clawdbot/moltbot.jsontools.web.search.apiKey环境替代:在网关进程环境中设置 BRAVE_API_KEY。若为网关安装,可放在 ~/.clawdbot/.env(或你的服务环境)。参见 环境变量

使用 Perplexity(直接或经 OpenRouter)

Perplexity Sonar 模型内置网页搜索能力,返回带引用的 AI 综合答案。可通过 OpenRouter 使用(无需信用卡,支持加密货币/预付)。

获取 OpenRouter API Key

  1. https://openrouter.ai/  注册。
  2. 充值(支持加密货币、预付或信用卡)。
  3. 在账号设置中生成 API key。

配置 Perplexity 搜索

{ tools: { web: { search: { enabled: true, provider: "perplexity", perplexity: { apiKey: "sk-or-v1-...", baseUrl: "https://openrouter.ai/api/v1", model: "perplexity/sonar-pro" } } } } }

环境替代:在网关环境中设置 OPENROUTER_API_KEYPERPLEXITY_API_KEY。若为网关安装,放在 ~/.clawdbot/.env。若未设置 base URL,Moltbot 根据 API key 来源选择默认:PERPLEXITY_API_KEYpplx-...https://api.perplexity.aiOPENROUTER_API_KEYsk-or-...https://openrouter.ai/api/v1;未知格式 → OpenRouter(安全回退)。

可用 Perplexity 模型

模型说明适用
perplexity/sonar带网页搜索的快速问答快速查询
perplexity/sonar-pro(默认)带网页搜索的多步推理复杂问题
perplexity/sonar-reasoning-pro链式思考分析深度研究

使用你配置的提供商进行网页搜索。

要求

  • tools.web.search.enabled 不得为 false(默认启用)
  • 所选提供商的 API key:BraveBRAVE_API_KEYtools.web.search.apiKeyPerplexityOPENROUTER_API_KEYPERPLEXITY_API_KEYtools.web.search.perplexity.apiKey

配置

{ tools: { web: { search: { enabled: true, apiKey: "BRAVE_API_KEY_HERE", maxResults: 5, timeoutSeconds: 30, cacheTtlMinutes: 15 } } } }

工具参数

  • query(必填)
  • count(1–10;默认来自配置)
  • country(可选):两字母国家代码,用于地区结果(如 “DE”、“US”、“ALL”)。省略时 Brave 使用默认地区。
  • search_lang(可选):搜索结果的 ISO 语言代码(如 “de”、“en”、“fr”)
  • ui_lang(可选):UI 元素的 ISO 语言代码
  • freshness(可选,仅 Brave):按发现时间过滤(pdpwpmpyYYYY-MM-DDtoYYYY-MM-DD

示例:

// 德语搜索 await web_search({ query: "TV online schauen", count: 10, country: "DE", search_lang: "de" }); // 最近一周结果 await web_search({ query: "TMBG interview", freshness: "pw" });

web_fetch

抓取 URL 并提取可读内容。

要求

  • tools.web.fetch.enabled 不得为 false(默认启用)
  • 可选 Firecrawl 回退:设置 tools.web.fetch.firecrawl.apiKeyFIRECRAWL_API_KEY

配置

{ tools: { web: { fetch: { enabled: true, maxChars: 50000, timeoutSeconds: 30, cacheTtlMinutes: 15, maxRedirects: 3, userAgent: "Mozilla/5.0 ...", readability: true, firecrawl: { enabled: true, apiKey: "FIRECRAWL_API_KEY_HERE", baseUrl: "https://api.firecrawl.dev", onlyMainContent: true, maxAgeMs: 86400000, timeoutSeconds: 60 } } } } }

工具参数

  • url(必填,仅 http/https)
  • extractModemarkdown | text
  • maxChars(截断长页)

说明:web_fetch 先使用 Readability(主内容提取),再使用 Firecrawl(若已配置)。两者都失败时工具返回错误。Firecrawl 请求使用反爬模式并默认缓存。web_fetch 默认发送类 Chrome User-Agent 和 Accept-Language;可按需覆盖 userAgentweb_fetch 会阻止私有/内网主机名并检查重定向(可用 maxRedirects 限制)。提取为尽力而为;部分站点需配合浏览器工具。Firecrawl 的 key 与服务详情见 Firecrawl。响应会缓存(默认 15 分钟)以减少重复抓取。若使用工具配置/白名单,请加入 web_search/web_fetchgroup:web。若未设置 Brave key,web_search 会返回简短设置提示及文档链接。

最后更新于: