作者:mpoll.top 发布时间:2026-04-13 0 次浏览
OpenClaw 的强大之处在于其丰富的工具链。从执行 shell 命令到控制浏览器,从发送消息到管理设备,OpenClaw 提供了一套完整的工具集,让 AI Agent 能够与真实世界交互。本文将全面解析 OpenClaw 的核心工具,帮助你理解每个工具的能力和使用场景。
---
| 工具 | 功能 | 使用频率 |
|------|------|----------|
| exec | 执行 shell 命令 | ⭐⭐⭐⭐⭐ |
| read | 读取文件内容 | ⭐⭐⭐⭐⭐ |
| write | 写入文件内容 | ⭐⭐⭐⭐⭐ |
| edit | 编辑文件内容 | ⭐⭐⭐⭐ |
| browser | 控制浏览器 | ⭐⭐⭐⭐ |
| message | 发送消息 | ⭐⭐⭐ |
| nodes | 管理设备节点 | ⭐⭐⭐ |
| web_search | 搜索网络 | ⭐⭐⭐⭐ |
| web_fetch | 抓取网页 | ⭐⭐⭐ |
| sessions_spawn | 生成子 Agent | ⭐⭐ |
OpenClaw 工具链
├── 文件操作
│ ├── read - 读取文件
│ ├── write - 写入文件
│ └── edit - 编辑文件
│
├── 系统操作
│ ├── exec - 执行命令
│ └── process - 管理进程
│
├── 网络操作
│ ├── browser - 浏览器控制
│ ├── web_search - 网络搜索
│ └── web_fetch - 网页抓取
│
├── 通信操作
│ ├── message - 消息发送
│ ├── sessions_send - 会话通信
│ └── tts - 语音合成
│
├── 设备操作
│ └── nodes - 设备管理
│
└── Agent 协作
├── sessions_spawn - 生成子 Agent
├── subagents - 管理子 Agent
└── sessions_list - 会话列表
功能:读取文件内容,支持文本和图片
基本用法:
tool: read
parameters:
path: "/path/to/file.txt"
offset: 1 # 可选,从第几行开始
limit: 100 # 可选,最多读取多少行
使用场景:
示例:
# 读取完整文件
read:
path: "./config.json"
读取大文件的一部分
read:
path: "./large-log.txt"
offset: 1000
limit: 100
注意事项:
功能:创建或覆盖文件
基本用法:
tool: write
parameters:
path: "/path/to/file.txt"
content: "文件内容"
使用场景:
示例:
# 创建配置文件
write:
path: "./config/settings.json"
content: |
{
"name": "my-app",
"version": "1.0.0"
}
保存日志
write:
path: "./logs/run-2026-04-13.md"
content: "# 运行日志\n\n任务完成..."
特性:
功能:精确编辑文件内容
基本用法:
tool: edit
parameters:
path: "/path/to/file.txt"
oldText: "要替换的原文"
newText: "替换后的内容"
使用场景:
示例:
# 修改版本号
edit:
path: "./package.json"
oldText: '"version": "1.0.0"'
newText: '"version": "1.0.1"'
修复代码
edit:
path: "./src/app.js"
oldText: "console.log(old)"
newText: "console.log(new)"
注意事项:
功能:执行 shell 命令
基本用法:
tool: exec
parameters:
command: "ls -la"
timeout: 60 # 可选,超时时间(秒)
pty: true # 可选,伪终端模式
yieldMs: 10000 # 可选,后台等待时间
使用场景:
示例:
# 查看目录
exec:
command: "ls -la ./src"
Git 操作
exec:
command: "git status"
运行脚本
exec:
command: "npm run build"
timeout: 300
需要 TTY 的命令
exec:
command: "htop"
pty: true
高级选项:
功能:管理后台 exec 会话
基本用法:
tool: process
parameters:
action: "list" # list/poll/log/write/send-keys/kill
sessionId: "xxx" # 会话 ID
使用场景:
示例:
# 列出所有会话
process:
action: "list"
获取会话输出
process:
action: "poll"
sessionId: "abc123"
timeout: 5000
向会话发送输入
process:
action: "send-keys"
sessionId: "abc123"
keys: ["Enter"]
功能:控制浏览器进行 UI 自动化
基本用法:
tool: browser
parameters:
action: "open" # open/snapshot/click/type/navigate等
url: "https://..." # 打开网址
profile: "chrome" # chrome/openclaw
使用场景:
示例:
# 打开网页
browser:
action: "open"
url: "https://example.com"
获取页面快照
browser:
action: "snapshot"
refs: "aria"
点击元素
browser:
action: "act"
kind: "click"
ref: "e12"
输入文本
browser:
action: "act"
kind: "type"
ref: "e15"
text: "搜索内容"
高级功能:
功能:使用 Brave Search API 搜索网络
基本用法:
tool: web_search
parameters:
query: "搜索关键词"
count: 10 # 结果数量(1-10)
country: "US" # 国家代码
freshness: "pw" # 时间范围
使用场景:
示例:
# 基本搜索
web_search:
query: "AI agent framework"
count: 10
最新新闻
web_search:
query: "OpenAI announcement"
freshness: "pd" # 过去一天
count: 5
特定地区
web_search:
query: "AI regulations"
country: "DE" # 德国
search_lang: "de" # 德语
参数说明:
功能:提取网页可读内容
基本用法:
tool: web_fetch
parameters:
url: "https://..."
extractMode: "markdown" # markdown/text
maxChars: 10000 # 最大字符数
使用场景:
示例:
# 提取文章
web_fetch:
url: "https://example.com/article"
extractMode: "markdown"
获取纯文本
web_fetch:
url: "https://example.com/page"
extractMode: "text"
maxChars: 5000
功能:通过渠道插件发送消息
基本用法:
tool: message
parameters:
action: "send"
target: "channel-id"
message: "消息内容"
使用场景:
示例:
# 发送文本消息
message:
action: "send"
target: "telegram-channel"
message: "任务完成!"
发送文件
message:
action: "send"
target: "discord-channel"
filePath: "./report.pdf"
caption: "月度报告"
功能:向其他会话发送消息
基本用法:
tool: sessions_send
parameters:
sessionKey: "xxx"
message: "消息内容"
使用场景:
功能:文本转语音
基本用法:
tool: tts
parameters:
text: "要转换的文本"
channel: "telegram" # 可选,指定输出格式
功能:管理配对的设备节点
基本用法:
tool: nodes
parameters:
action: "status" # status/describe/notify等
node: "device-name"
使用场景:
示例:
# 查看设备状态
nodes:
action: "status"
发送通知
nodes:
action: "notify"
node: "my-phone"
title: "提醒"
body: "会议即将开始"
获取位置
nodes:
action: "location_get"
node: "my-phone"
功能:生成隔离的子 Agent 会话
基本用法:
tool: sessions_spawn
parameters:
task: "任务描述"
runtime: "subagent" # subagent/acp
mode: "run" # run/session
使用场景:
示例:
# 生成子 Agent 处理任务
sessions_spawn:
task: "分析这个代码库并生成文档"
runtime: "subagent"
mode: "session"
label: "doc-generator"
功能:列出、控制子 Agent
基本用法:
tool: subagents
parameters:
action: "list" # list/kill/steer
target: "agent-id"
message: "指导消息"
| 场景 | 推荐工具 |
|------|----------|
| 读取文件 | read |
| 创建文件 | write |
| 修改文件 | edit / write |
| 执行命令 | exec |
| 浏览网页 | browser |
| 搜索信息 | web_search |
| 抓取内容 | web_fetch |
| 发送通知 | message |
| 设备控制 | nodes |
| 复杂任务 | sessions_spawn |
1. 优先使用专用工具
# ✅ 好:使用专用工具
web_search:
query: "AI news"
❌ 差:用 exec 调用 curl
exec:
command: "curl 'https://api.brave.com/search?q=AI+news'"
2. 大文件分页读取
# ✅ 好:分页读取
read:
path: "./large-file.txt"
offset: 1
limit: 1000
继续读取
read:
path: "./large-file.txt"
offset: 1001
limit: 1000
3. 长时间任务后台运行
# ✅ 好:设置 yieldMs
exec:
command: "npm run build"
yieldMs: 30000
4. 精确编辑用 edit
# ✅ 好:精确替换
edit:
path: "./config.json"
oldText: '"version": "1.0.0"'
newText: '"version": "1.0.1"'
OpenClaw 的工具链提供了与真实世界交互的完整能力:
文件操作:read/write/edit 处理所有文件需求
系统操作:exec/process 执行任意命令
网络操作:browser/web_search/web_fetch 获取网络信息
通信操作:message/sessions_send/tts 发送消息
设备操作:nodes 管理配对的设备
Agent 协作:sessions_spawn/subagents 分解复杂任务
核心原则:
掌握这些工具,你的 AI Agent 将能够完成从简单文件操作到复杂工作流自动化的各种任务。
本文属于「OpenClaw 小龙虾专区」系列专题
最后更新:2026 年 4 月
上一篇: Google Gemini 架构解析:多模态大模型设计
没有了,已经是最新文章