OpenClaw 工具链全览:exec/browser/message/nodes
开篇导语
OpenClaw 的强大之处在于其丰富的工具链。从执行 shell 命令到控制浏览器,从发送消息到管理设备,OpenClaw 提供了一套完整的工具集,让 AI Agent 能够与真实世界交互。本文将全面解析 OpenClaw 的核心工具,帮助你理解每个工具的能力和使用场景。
---
一、工具链概览
1.1 核心工具列表
| 工具 | 功能 | 使用频率 |
|------|------|----------|
| exec | 执行 shell 命令 | ⭐⭐⭐⭐⭐ |
| read | 读取文件内容 | ⭐⭐⭐⭐⭐ |
| write | 写入文件内容 | ⭐⭐⭐⭐⭐ |
| edit | 编辑文件内容 | ⭐⭐⭐⭐ |
| browser | 控制浏览器 | ⭐⭐⭐⭐ |
| message | 发送消息 | ⭐⭐⭐ |
| nodes | 管理设备节点 | ⭐⭐⭐ |
| web_search | 搜索网络 | ⭐⭐⭐⭐ |
| web_fetch | 抓取网页 | ⭐⭐⭐ |
| sessions_spawn | 生成子 Agent | ⭐⭐ |
1.2 工具分类
OpenClaw 工具链
├── 文件操作
│ ├── read - 读取文件
│ ├── write - 写入文件
│ └── edit - 编辑文件
│
├── 系统操作
│ ├── exec - 执行命令
│ └── process - 管理进程
│
├── 网络操作
│ ├── browser - 浏览器控制
│ ├── web_search - 网络搜索
│ └── web_fetch - 网页抓取
│
├── 通信操作
│ ├── message - 消息发送
│ ├── sessions_send - 会话通信
│ └── tts - 语音合成
│
├── 设备操作
│ └── nodes - 设备管理
│
└── Agent 协作
├── sessions_spawn - 生成子 Agent
├── subagents - 管理子 Agent
└── sessions_list - 会话列表
二、文件操作工具
2.1 read - 读取文件
功能:读取文件内容,支持文本和图片
基本用法:
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
注意事项:
- 文本文件限制:2000 行或 50KB
- 大文件使用 offset/limit 分页读取
- 支持图片格式:jpg, png, gif, webp
2.2 write - 写入文件
功能:创建或覆盖文件
基本用法:
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任务完成..."
特性:
- 自动创建不存在的目录
- 覆盖已存在的文件
- 支持任意文本内容
2.3 edit - 编辑文件
功能:精确编辑文件内容
基本用法:
tool: edit
parameters:
path: "/path/to/file.txt"
oldText: "要替换的原文"
newText: "替换后的内容"
使用场景:
- 修改配置项
- 修复代码 bug
- 更新文档内容
- 精确替换文本
示例:
# 修改版本号
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)"
注意事项:
- oldText 必须完全匹配(包括空格)
- 适合精确的小范围修改
- 大范围修改建议用 write 重写
三、系统操作工具
3.1 exec - 执行命令
功能:执行 shell 命令
基本用法:
tool: exec
parameters:
command: "ls -la"
timeout: 60 # 可选,超时时间(秒)
pty: true # 可选,伪终端模式
yieldMs: 10000 # 可选,后台等待时间
使用场景:
- 文件操作(ls, cp, mv, rm)
- Git 操作(git status, commit, push)
- 安装依赖(npm install, pip install)
- 运行脚本(node, python, bash)
- 系统查询(df, top, ps)
示例:
# 查看目录
exec:
command: "ls -la ./src"
Git 操作
exec:
command: "git status"
运行脚本
exec:
command: "npm run build"
timeout: 300
需要 TTY 的命令
exec:
command: "htop"
pty: true
高级选项:
- pty: 伪终端模式,用于交互式命令
- timeout: 命令超时时间
- yieldMs: 长时间任务后台运行
- background: 后台运行
- workdir: 工作目录
3.2 process - 管理进程
功能:管理后台 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"]
四、网络操作工具
4.1 browser - 浏览器控制
功能:控制浏览器进行 UI 自动化
基本用法:
tool: browser
parameters:
action: "open" # open/snapshot/click/type/navigate等
url: "https://..." # 打开网址
profile: "chrome" # chrome/openclaw
使用场景:
- 网页自动化测试
- 填写表单
- 抓取动态内容
- 截图和 PDF
示例:
# 打开网页
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: "搜索内容"
高级功能:
- snapshot: 获取页面结构和元素引用
- act: 执行各种操作(click/type/hover 等)
- screenshot: 页面截图
- pdf: 生成 PDF
- profile: 使用 Chrome 扩展或独立浏览器
4.2 web_search - 网络搜索
功能:使用 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" # 德语
参数说明:
- query: 搜索关键词
- count: 结果数量(1-10)
- country: 国家代码(US/DE/CN 等)
- freshness: pd(天)/pw(周)/pm(月)/py(年)
- search_lang: 搜索语言(en/de/fr 等)
4.3 web_fetch - 网页抓取
功能:提取网页可读内容
基本用法:
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
五、通信工具
5.1 message - 消息发送
功能:通过渠道插件发送消息
基本用法:
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: "月度报告"
5.2 sessions_send - 会话通信
功能:向其他会话发送消息
基本用法:
tool: sessions_send
parameters:
sessionKey: "xxx"
message: "消息内容"
使用场景:
- 与子 Agent 通信
- 跨会话协作
- 任务分发
5.3 tts - 语音合成
功能:文本转语音
基本用法:
tool: tts
parameters:
text: "要转换的文本"
channel: "telegram" # 可选,指定输出格式
六、设备工具
6.1 nodes - 设备管理
功能:管理配对的设备节点
基本用法:
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 协作工具
7.1 sessions_spawn - 生成子 Agent
功能:生成隔离的子 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"
7.2 subagents - 管理子 Agent
功能:列出、控制子 Agent
基本用法:
tool: subagents
parameters:
action: "list" # list/kill/steer
target: "agent-id"
message: "指导消息"
八、工具选择指南
8.1 场景 - 工具映射
| 场景 | 推荐工具 |
|------|----------|
| 读取文件 | read |
| 创建文件 | write |
| 修改文件 | edit / write |
| 执行命令 | exec |
| 浏览网页 | browser |
| 搜索信息 | web_search |
| 抓取内容 | web_fetch |
| 发送通知 | message |
| 设备控制 | nodes |
| 复杂任务 | sessions_spawn |
8.2 最佳实践
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 分解复杂任务
核心原则:
- 使用专用工具而非通用命令
- 大文件分页处理
- 长时间任务后台运行
- 复杂任务分解给子 Agent
掌握这些工具,你的 AI Agent 将能够完成从简单文件操作到复杂工作流自动化的各种任务。
本文属于「OpenClaw 小龙虾专区」系列专题
最后更新:2026 年 4 月
社区评论
登录后参与讨论,评论经审核后公开显示。