OpenClaw工具拆解之tavily+auxiliary
一、tavily 工具
1.1 工具概述
功能:AI 优化搜索引擎
核心特性:
-
• AI 优化搜索结果 -
• 支持搜索深度(basic/advanced) -
• 支持主题分类 -
• 需要 API Key
1.2 Schema 定义
constTavilySearchToolSchema = Type.Object({
query: Type.String({ description: "Search query" }),
searchDepth: Type.Optional(Type.String({
enum: ["basic", "advanced"],
description: "Search depth level"
})),
topic: Type.Optional(Type.String({
description: "Topic category for better results"
})),
maxResults: Type.Optional(Type.Number({
description: "Maximum number of results to return",
default: 10
}))
});
1.3 执行代码
functioncreateTavilyTool(options) {
const apiKey = options?.config?.tools?.tavily?.apiKey ?? process.env.TAVILY_API_KEY;
if (!apiKey) {
returnnull; // API Key 未配置,工具不可用
}
return {
label: "Tavily",
name: "tavily",
description: "AI-optimized search engine for research and fact-finding.",
parameters: TavilySearchToolSchema,
execute: async (_toolCallId, args) => {
const params = args;
// 1. 解析查询(必填)
const query = readStringParam$1(params, "query", { required: true });
// 2. 解析搜索深度
const searchDepth = params.searchDepth === "advanced" ? "advanced" : "basic";
// 3. 解析主题
const topic = readStringParam$1(params, "topic");
// 4. 解析结果数量
const maxResults = typeof params.maxResults === "number" ?
Math.max(1, Math.min(params.maxResults, 20)) : 10;
// 5. 调用 Tavily API
const response = awaitfetch("https://api.tavily.com/search", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKey}`
},
body: JSON.stringify({
query,
search_depth: searchDepth,
topic: topic || "general",
max_results: maxResults,
include_answer: true,
include_raw_content: false
})
});
if (!response.ok) {
thrownewError(`Tavily API error: ${response.status}${response.statusText}`);
}
const data = await response.json();
// 6. 返回结果
returnjsonResult({
query: data.query,
answer: data.answer,
results: data.results.map((r) => ({
title: r.title,
url: r.url,
content: r.content,
score: r.score
})),
total: data.results.length
});
}
};
}
1.4 返回结果格式
成功:
{
"query":"OpenClaw documentation",
"answer":"OpenClaw is an AI assistant framework...",
"results":[
{
"title":"OpenClaw Documentation",
"url":"https://docs.openclaw.ai",
"content":"Official documentation for OpenClaw...",
"score":0.95
}
],
"total":10
}
二、辅助工具
2.1 apply_patch(已在第 13 组涉及)
功能:应用补丁到多个文件
详细说明:见 apply_patch+sandboxed_read.md
2.2 image_generate(已在第 10 组涉及)
功能:生成图像(文生图/图生图)
详细说明:见 web_fetch+image_generate.md
2.3 sessions_history(已在第 03 组涉及)
功能:获取会话历史消息
详细说明:见 sessions_list+sessions_history.md
三、工具分类总览
3.1 完整工具列表(36 个)
|
|
|
|
| 核心基础工具 |
|
|
| 会话管理工具 |
|
|
| 网络工具 |
|
|
| 媒体工具 |
|
|
| OpenClaw 核心工具 |
|
|
| 沙盒工具 |
|
|
| Host 工具 |
|
|
| 补丁工具 |
|
|
3.2 文档覆盖情况
|
|
|
|
read+write.md |
|
|
edit+process.md |
|
|
sessions_list+sessions_history.md |
|
|
sessions_send+sessions_spawn.md |
|
|
sessions_yield+session_status.md |
|
|
subagents+gateway.md |
|
|
cron+nodes.md |
|
|
canvas+message.md |
|
|
tts+web_search.md |
|
|
web_fetch+image_generate.md |
|
|
image+pdf.md |
|
|
browser+agents_list.md |
|
|
apply_patch+sandboxed_read.md |
|
|
sandboxed_write+sandboxed_edit.md |
|
|
host_workspace_write+host_workspace_edit.md |
|
|
memory_search+memory_get.md |
|
|
tavily+auxiliary.md |
|
|
四、17 组(36 个工具)最终总结
已完成 17 组(36 个工具):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
总计:约 300KB 文档,覆盖 36 个核心工具!
五、使用指南
5.1 工具选择指南
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5.2 沙盒模式选择
沙盒模式启用时:
├─ 读取文件 → sandboxed_read
├─ 写入文件 → sandboxed_write
└─ 编辑文件 → sandboxed_edit
非沙盒模式时:
├─ 读取文件 → read
├─ 写入文件 → host_workspace_write
└─ 编辑文件 → host_workspace_edit
夜雨聆风