OpenClaw 内置两个轻量级 Web 工具,让 Agent 能够搜索互联网和抓取页面内容,无需启动完整浏览器。
两个工具概览
| 工具 | 功能 | 适用场景 |
|---|---|---|
web_search | 调用搜索 API,返回结构化结果 | 信息检索、新闻查询、知识搜索 |
web_fetch | HTTP 抓取 + 内容提取(HTML→Markdown) | 阅读特定页面、文档抓取 |
这两个工具不执行 JavaScript。JS 密集型页面或需要登录的页面,请使用 Browser 工具。
web_search:5 大搜索提供商
| 提供商 | 结果类型 | 特色 | API Key |
|---|---|---|---|
| Brave Search | 结构化结果+摘要 | 隐私优先,支持 LLM 模式 | BRAVE_API_KEY |
| Gemini | AI 合成答案+引用 | Google 搜索实时接地 | GEMINI_API_KEY |
| Grok | AI 合成答案+引用 | xAI 网络搜索 | XAI_API_KEY |
| Kimi | AI 合成答案+引用 | Moonshot 网络搜索 | KIMI_API_KEY |
| Perplexity | 结构化结果+摘要 | 支持域名过滤 | PERPLEXITY_API_KEY |
自动检测顺序
未设置 provider 时,按以下顺序检测可用 Key:
- Brave → 2. Gemini → 3. Grok → 4. Kimi → 5. Perplexity
没有找到任何 Key 时,回退到 Brave 并报错提示配置。
快速配置
bash
openclaw configure --section webBrave Search(推荐,隐私友好)
- 注册 Brave Search API,获取 API Key
- 免费额度:每月 5 美元(约 1000 次查询)
json
{
"tools": {
"web": {
"search": {
"enabled": true,
"provider": "brave",
"apiKey": "YOUR_BRAVE_API_KEY"
}
}
}
}Brave LLM Context 模式(返回页面内容片段而非摘要):
json
{
"tools": {
"web": {
"search": {
"provider": "brave",
"brave": { "mode": "llm-context" }
}
}
}
}注意:
llm-context模式不支持ui_lang、freshness、date_after、date_before
Gemini(Google 搜索接地)
json
{
"tools": {
"web": {
"search": {
"provider": "gemini",
"gemini": {
"apiKey": "YOUR_GEMINI_API_KEY",
"model": "gemini-2.5-flash"
}
}
}
}
}Gemini 返回 AI 合成答案并自动解析 Google 重定向 URL 为直接链接。
Perplexity Search
json
{
"tools": {
"web": {
"search": {
"provider": "perplexity",
"perplexity": { "apiKey": "pplx-..." }
}
}
}
}通过 OpenRouter 使用 Perplexity(无需单独注册):
json
{
"tools": {
"web": {
"search": {
"provider": "perplexity",
"perplexity": {
"apiKey": "sk-or-...",
"baseUrl": "https://openrouter.ai/api/v1",
"model": "perplexity/sonar-pro"
}
}
}
}
}web_search 参数参考
| 参数 | 说明 | 支持提供商 |
|---|---|---|
query | 搜索词(必填) | 全部 |
count | 返回数量(1-10,默认 5) | 全部 |
country | 2 字母国家码(如 CN、US) | Brave、Perplexity |
language | ISO 639-1 语言码(如 zh、en) | Brave、Perplexity |
freshness | 时效过滤(day/week/month/year) | Brave、Perplexity |
date_after | 起始日期(YYYY-MM-DD) | Brave、Perplexity |
date_before | 截止日期(YYYY-MM-DD) | Brave、Perplexity |
domain_filter | 域名白/黑名单(- 前缀排除) | Perplexity |
max_tokens | 总内容预算(默认 25000) | Perplexity |
搜索示例:
js
// 中文搜索
aweb_search({ query: "Claude Code 最新功能", country: "CN", language: "zh" })
// 最近一周的内容
aweb_search({ query: "OpenClaw 更新", freshness: "week" })
// 日期范围
aweb_search({ query: "AI 进展", date_after: "2026-01-01", date_before: "2026-03-01" })
// 指定域名(Perplexity)
aweb_search({ query: "机器学习研究", domain_filter: ["arxiv.org", "nature.com", "-reddit.com"] })web_fetch:页面内容提取
json
{
"tools": {
"web": {
"fetch": {
"enabled": true,
"maxChars": 50000,
"timeoutSeconds": 30,
"cacheTtlMinutes": 15,
"readability": true,
"firecrawl": {
"enabled": true,
"apiKey": "YOUR_FIRECRAWL_KEY",
"onlyMainContent": true
}
}
}
}
}参数:
url:目标 URL(必填,仅支持 http/https)extractMode:markdown(默认)或textmaxChars:截断长度
提取顺序:Readability(主内容提取)→ Firecrawl(配置了才用)→ 报错
安全限制:
- 阻止私有/内网 IP
- 重定向检查(最多
maxRedirects次) - 响应体大小上限:
maxResponseBytes(默认 2MB)
结果缓存
两个工具都默认缓存 15 分钟(cacheTtlMinutes: 15),避免重复请求:
json
{
"tools": {
"web": {
"search": { "cacheTtlMinutes": 30 },
"fetch": { "cacheTtlMinutes": 60 }
}
}
}工具权限配置
如果使用工具白名单,添加:
json
{
"tools": {
"allow": ["web_search", "web_fetch"]
}
}或使用工具组:group:web
原文:Web Tools - OpenClaw | 来源:OpenClaw 官方文档