Tools 与 Plugins(按官方工具策略)
官方方向
OpenClaw 官方文档明确强调:工具是 first-class 的 typed capability,推荐直接使用工具体系而不是依赖旧式命名约定。
参考:
- https://docs.openclaw.ai/tools/index.md
- https://docs.openclaw.ai/tools/exec.md
- https://docs.openclaw.ai/tools/exec-approvals.md
- https://docs.openclaw.ai/tools/plugin.md
工具体系概览
txt
┌─────────────────────────────────────────────────────────────┐
│ 工具类型 │
├─────────────────────────────────────────────────────────────┤
│ exec 执行命令(shell、脚本) │
│ browser 浏览器自动化(导航、点击、输入) │
│ web 网络请求(fetch、search) │
│ file 文件操作(read、write、edit) │
│ memory 记忆管理(recall、store) │
│ message 消息发送(reply、notify) │
│ nodes 节点管理(camera、screen、location) │
│ process 进程管理(spawn、kill、poll) │
│ canvas 画布展示(present、navigate、eval) │
│ session 会话管理(spawn、send、steer) │
│ subagents 子代理(list、steer、kill) │
└─────────────────────────────────────────────────────────────┘Tool 治理三层模型
1. Base profile
tools.profile 定义基础工具集:
yaml
tools:
profile: safe # minimal | safe | coding | messaging | full| Profile | 包含工具 | 适用场景 |
|---|---|---|
| minimal | web:fetch, memory | 只读、查询 |
| safe | minimal + web:search, file:read | 安全查询 |
| coding | safe + exec:standard, file:write | 开发场景 |
| messaging | minimal + message:* | 消息处理 |
| full | 所有工具 | 完全权限 |
2. Allow / deny
yaml
tools:
profile: coding
# 允许特定工具
allow:
- read:**
- web:**
# 禁止特定工具
deny:
- exec:elevated
- write:sensitive
# deny 优先级高于 allow3. By provider
yaml
tools:
profile: coding
# 针对 OpenAI 的限制
byProvider:
openai:
allow: ['*']
# 针对 Anthropic 的限制
anthropic:
deny:
- browser:*
- exec:*审批策略
yaml
tools:
approvals:
# exec 工具审批
exec:
mode: ask # off | on-miss | always
timeout: 300 # 秒
# 浏览器操作审批
browser:
mode: on-miss
rules:
- pattern: 'navigate:*'
auto_approve: false
- pattern: 'click:*'
auto_approve: true
# 文件写入审批
file:
write:
mode: ask
rules:
- pattern: 'write:*.yaml'
auto_approve: true
- pattern: 'write:*.env'
auto_approve: false推荐起步策略
阶段 1:只读模式
yaml
tools:
profile: minimal
allow:
- web:fetch
- memory:*阶段 2:开发模式
yaml
tools:
profile: coding
approvals:
exec:
mode: ask阶段 3:生产模式
yaml
tools:
profile: coding
allow:
- read:*
- web:*
- exec:standard
deny:
- exec:elevated
approvals:
exec:
mode: on-miss
write:
sensitive:
mode: alwaysPlugins 何时使用
插件类型
| 类型 | 用途 | 示例 |
|---|---|---|
| 渠道插件 | 扩展消息渠道 | Mattermost、LINE、Nostr |
| 能力插件 | 扩展工具能力 | 语音处理、图像生成 |
| 集成插件 | 对接外部系统 | Jira、GitHub、Slack |
插件安装
bash
# 列出可用插件
openclaw plugins list --remote
# 安装插件
openclaw plugins install openclaw-plugin-mattermost
# 配置插件
openclaw config set plugins.mattermost.enabled true
# 验证插件
openclaw plugins test mattermost插件开发
yaml
# plugin.yaml
name: my-plugin
version: 1.0.0
description: Custom plugin for XYZ
# 工具定义
tools:
- name: xyz:action
description: Perform XYZ action
input_schema:
type: object
properties:
param:
type: string
handler: ./handlers/action.js官方插件文档:
- https://docs.openclaw.ai/plugins/community.md
- https://docs.openclaw.ai/plugins/manifest.md
- https://docs.openclaw.ai/plugins/agent-tools.md
工具使用示例
exec 工具
bash
# 执行命令
openclaw exec "ls -la"
# 带审批执行
openclaw exec "rm -rf /tmp/cache" --approve
# 后台执行
openclaw exec "npm run build" --backgroundbrowser 工具
bash
# 导航
openclaw browser navigate "https://example.com"
# 截图
openclaw browser screenshot --output screenshot.png
# 点击
openclaw browser click "#submit-button"
# 输入
openclaw browser type "#search-input" "OpenClaw"web 工具
bash
# 获取网页
openclaw web fetch "https://api.example.com/data"
# 搜索
openclaw web search "OpenClaw documentation"
# POST 请求
openclaw web post "https://api.example.com/submit" --data '{"key": "value"}'file 工具
bash
# 读取文件
openclaw file read "./config.yaml"
# 写入文件
openclaw file write "./output.txt" --content "Hello"
# 编辑文件
openclaw file edit "./config.yaml" --find "old" --replace "new"开发者与产品经理协作要点
开发者负责
- 配置工具权限和审批策略
- 维护工具列表和能力边界
- 提供错误分类和回滚方案
产品经理负责
- 定义"可自动执行"和"必须人工确认"的业务边界
- 维护高风险操作清单
- 制定审批流程和响应策略
协作模板
yaml
# 高风险操作清单
high_risk_operations:
- operation: exec:elevated
risk: high
approval_required: true
approvers: [admin]
- operation: write:sensitive
risk: high
approval_required: true
approvers: [admin, security]
- operation: browser:auth
risk: medium
approval_required: true
approvers: [admin]
- operation: file:delete
risk: medium
approval_required: false
audit: true