OpenClaw Web 工具指南
概述
OpenClaw 附带两个轻量级 Web 工具:
web_search— 通过 Brave Search API(默认)或 Perplexity Sonar(直接或通过 OpenRouter)搜索 Webweb_fetch— HTTP 获取 + 可读提取(HTML → markdown/text)
这些不是浏览器自动化。对于 JS 重的网站或登录,使用 Browser 工具。
工作原理
web_search调用您配置的提供者并返回结果- Brave(默认): 返回结构化结果(标题、URL、片段)
- Perplexity: 返回 AI 合成的答案,带有实时 Web 搜索的引用
- 结果按查询缓存 15 分钟(可配置)
web_fetch执行普通 HTTP GET 并提取可读内容(HTML → markdown/text)。它不执行 JavaScript
选择搜索提供者
| 提供者 | 优点 | 缺点 | API 密钥 |
|---|---|---|---|
| Brave(默认) | 快速、结构化结果、免费层 | 传统搜索结果 | BRAVE_API_KEY |
| Perplexity | AI 合成答案、引用、实时 | 需要 Perplexity 或 OpenRouter 访问 | OPENROUTER_API_KEY 或 PERPLEXITY_API_KEY |
切换到 Perplexity Sonar
{
"tools": {
"web": {
"search": {
"provider": "perplexity",
"perplexity": {
"apiKey": "sk-or-v1-...",
"baseUrl": "https://openrouter.ai/api/v1",
"model": "perplexity/sonar-pro"
}
}
}
}
}获取 Brave API 密钥
- 在 https://brave.com/search/api/ 创建 Brave Search API 账户
- 在仪表板中,选择 Data for Search 计划(不是 “Data for AI”)并生成 API 密钥
- 运行
openclaw configure --section web将密钥存储在配置中,或在环境中设置BRAVE_API_KEY
web_search 工具
要求
tools.web.search.enabled不得为 false(默认:启用)- 您选择的提供者的 API 密钥
工具参数
| 参数 | 说明 |
|---|---|
query(必需) |
搜索查询 |
count |
1-10;默认来自配置 |
country |
2 字母国家代码(例如 “DE”、”US”) |
search_lang |
ISO 语言代码(例如 “de”、”en”) |
freshness |
按发现时间过滤(pd、pw、pm、py) |
示例
// 德国特定搜索
await web_search({
query: "TV online schauen",
count: 10,
country: "DE",
search_lang: "de"
});
// 最近结果(过去一周)
await web_search({
query: "TMBG interview",
freshness: "pw"
});web_fetch 工具
要求
tools.web.fetch.enabled不得为 false(默认:启用)- 可选的 Firecrawl 回退:设置
tools.web.fetch.firecrawl.apiKey或FIRECRAWL_API_KEY
工具参数
| 参数 | 说明 |
|---|---|
url(必需) |
仅 http/https |
extractMode |
markdown 或 text |
maxChars |
截断长页面 |
示例
await web_fetch({
url: "https://example.com/article",
extractMode: "markdown",
maxChars: 5000
});配置参考
{
"tools": {
"web": {
"search": {
"enabled": true,
"provider": "brave",
"apiKey": "BRAVE_API_KEY_HERE",
"maxResults": 5,
"timeoutSeconds": 30,
"cacheTtlMinutes": 15
},
"fetch": {
"enabled": true,
"maxChars": 50000,
"timeoutSeconds": 30,
"cacheTtlMinutes": 15,
"firecrawl": {
"enabled": true,
"apiKey": "FIRECRAWL_API_KEY_HERE"
}
}
}
}
}作者:十一张 创建时间:2026-03-08 22:33
最后编辑:十一张 更新时间:2026-03-28 11:56
最后编辑:十一张 更新时间:2026-03-28 11:56