概述
OpenClaw 提供了两个核心的网络工具:web_search 用于搜索互联网内容,web_fetch 用于抓取特定网页的可读内容。这两个工具配合使用,可以让你的 AI 助手实时获取和分析互联网上的信息。
web_search 工具配置
获取 Brave Search API 密钥
web_search 工具使用 Brave Search API 作为搜索后端。首先需要获取 API 密钥:
- 访问 Brave Search API 注册账号
- 创建新的 API 密钥
- 免费方案每月提供 2000 次搜索请求
配置环境变量
# 在 .env 文件中设置
BRAVE_SEARCH_API_KEY=your_brave_api_key_here
或者在系统环境中设置:
export BRAVE_SEARCH_API_KEY="BSA-xxxxxxxxxxxxxxxx"
配置文件设置
{
tools: {
web_search: {
enabled: true,
// 搜索结果数量
maxResults: 5,
// 默认搜索区域
region: "zh-CN",
// 安全搜索级别
safeSearch: "moderate" // off | moderate | strict
}
}
}
使用示例
用户: 搜索一下最新的 Rust 语言更新
OpenClaw: [调用 web_search, query: "Rust programming language latest update 2026"]
根据搜索结果,Rust 最新的稳定版本为...
主要更新包括:
1. ...
2. ...
web_fetch 工具配置
基本配置
web_fetch 工具用于获取指定 URL 的网页内容,自动将 HTML 转换为可读的 Markdown 或纯文本格式:
{
tools: {
web_fetch: {
enabled: true,
// 输出格式
outputFormat: "markdown", // markdown | text | html
// 最大内容长度(字符数)
maxContentLength: 50000,
// 请求超时(毫秒)
timeout: 30000,
// 是否跟随重定向
followRedirects: true,
maxRedirects: 5
}
}
}
使用示例
用户: 帮我看看这篇文章说了什么 https://example.com/article
OpenClaw: [调用 web_fetch, url: "https://example.com/article"]
这篇文章主要讨论了...
内容转换选项
web_fetch 支持多种内容提取模式:
{
tools: {
web_fetch: {
enabled: true,
// 内容提取模式
extraction: {
// 自动移除导航、广告等无关内容
readability: true,
// 保留图片的 alt 文本描述
includeImageAlts: true,
// 保留链接
includeLinks: true,
// 保留表格
includeTables: true
}
}
}
}
搜索结果格式化
自定义搜索结果模板
控制搜索结果呈现给模型的格式:
{
tools: {
web_search: {
enabled: true,
resultFormat: {
// 包含的字段
includeTitle: true,
includeUrl: true,
includeSnippet: true,
includeDate: true,
// 结果之间的分隔符
separator: "\n---\n"
}
}
}
}
搜索结果示例输出:
标题: Rust 1.80 发布公告
链接: https://blog.rust-lang.org/2026/01/...
摘要: Rust 1.80 版本带来了多项重要改进,包括...
日期: 2026-01-05
---
标题: Rust 异步编程新特性
链接: https://example.com/rust-async-2026
摘要: 最新版本中的异步编程模型得到了显著改进...
日期: 2026-01-03
搜索与抓取的组合使用
最强大的用法是将搜索和抓取结合:
用户: 深入了解一下 WebAssembly 的最新发展
OpenClaw 的工作流程:
1. [web_search] 搜索 "WebAssembly latest developments 2026"
2. 从搜索结果中选择最相关的 2-3 个链接
3. [web_fetch] 逐个获取这些页面的完整内容
4. 综合所有信息生成详细报告
实际对话示例
用户: 帮我研究一下目前主流的向量数据库对比
OpenClaw:
我来帮你搜索并整理相关信息。
[web_search: "向量数据库 对比 2026 Milvus Pinecone Qdrant"]
找到了几篇相关文章,让我获取详细内容...
[web_fetch: "https://example.com/vector-db-comparison"]
[web_fetch: "https://example.com/milvus-vs-pinecone"]
根据我的调查,以下是目前主流向量数据库的对比:
| 特性 | Milvus | Pinecone | Qdrant |
|------|--------|----------|--------|
| 开源 | 是 | 否 | 是 |
| ... | ... | ... | ... |
高级配置
请求头自定义
{
tools: {
web_fetch: {
headers: {
"User-Agent": "OpenClaw/1.0",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8"
}
}
}
}
代理设置
在需要代理访问的网络环境中:
{
tools: {
web_search: {
proxy: "http://proxy.example.com:8080"
},
web_fetch: {
proxy: "http://proxy.example.com:8080"
}
}
}
故障排查
搜索返回空结果
# 验证 API 密钥是否有效
curl -s "https://api.search.brave.com/res/v1/web/search?q=test" \
-H "Accept: application/json" \
-H "X-Subscription-Token: $BRAVE_SEARCH_API_KEY"
# 检查 API 配额使用情况
openclaw tools status web_search
网页抓取失败
# 检查目标网站是否可达
curl -I https://target-website.com
# 查看抓取相关日志
openclaw logs --filter web_fetch --tail 20
常见错误代码
- 403 Forbidden:目标网站拒绝访问,尝试更换 User-Agent
- 429 Too Many Requests:API 调用频率过高,检查配额
- Timeout:增大 timeout 配置值,或检查网络连通性
合理使用网络搜索和抓取工具,可以让 OpenClaw 突破训练数据的时间限制,提供最新、最准确的信息。