大家好,我是祥子。
最近这一年,我在研究 AI 工程化,聚焦企业如何落地。实践过程中记录一些经验和感悟,今天分享的是:OpenClaw 工具分组机制。
工具分组(Tool Groups)是 OpenClaw 的权限管理机制,用于简化智能体的工具配置。
1. 为什么需要工具分组?
1.1 传统配置的痛点
早期的 OpenClaw 需要逐个列出工具名来配置权限:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 { id: "developer", tools: { allow: [ "read", "write", "edit", "apply_patch", "exec", "bash", "process", "browser", "web_search", "web_fetch" ], deny: [ "sessions_spawn", "sessions_yield", "subagents" ] }}
问题很明显:
配置冗长,容易遗漏或重复 看不出智能体的实际能力范围 新增工具时需要手动更新配置
1.2 工具分组的方案
OpenClaw 将相关功能的工具归类到预定义的组:
1 2 3 4 5 6 7 { id: "developer", tools: { allow: ["group:fs", "group:runtime", "group:web"], deny: ["group:sessions"] }}
一行替代多个工具名,语义也更清晰——group:fs 代表文件系统,group:runtime 代表运行时执行。新工具会自动归入对应组,不用手动更新配置。
2. 工作原理
2.1 语法
工具分组用 group: 前缀标识:
1 2 3 4 5 6 { tools: { allow: ["group:<组名>"], deny: ["<单个工具名>"] }}
2.2 权限优先级
deny 的优先级高于 allow:
1 2 3 4 5 6 { tools: { allow: ["group:runtime"], deny: ["exec"] }}
这个配置下,bash 和 process 可用,exec 被拒绝。
2.3 组合使用
工具组和单个工具可以混用:
1 2 3 4 5 6 7 8 9 10 11 12 { tools: { allow: [ "group:fs", "browser", "web_search" ], deny: [ "apply_patch" ] }}
3. 工具组列表
OpenClaw 提供了 10 个预定义工具组:
风险等级说明:
低风险:只读操作或受限操作 中风险:可能影响系统状态或跨智能体操作 高风险:可执行代码或完全权限,需谨慎授权
4. 各工具组详解
4.1 group:fs(文件系统)
包含工具
使用场景
适合产品经理(编写 PRD 文档)、开发工程师(读写代码)、测试工程师、文档管理员。
安全审计员只需要只读权限即可。
配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 // 产品经理:需要读写文档,但不能批量修改{ id: "pm", tools: { allow: ["group:fs"], deny: ["apply_patch"] }}// 开发工程师:完全文件权限{ id: "developer", tools: { allow: ["group:fs"] }}// 安全审计员:只读{ id: "security-auditor", tools: { allow: ["read"], deny: ["write", "edit", "apply_patch"] }}
4.2 group:runtime(运行时执行)
包含工具
使用场景
适合开发工程师(执行 git、npm、测试)、运维工程师(部署、监控)、自动化脚本。
不适合产品经理、安全审计员、跨部门协调器。
配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 // 开发工程师{ id: "developer", tools: { allow: ["group:fs", "group:runtime"] }}// 运维工程师{ id: "ops", tools: { allow: ["group:fs", "group:runtime", "group:automation"] }}// 安全审计员:禁止所有运行时工具{ id: "security-auditor", tools: { allow: ["group:fs"], deny: ["group:runtime"] }}
安全建议
这是高风险工具,生产环境务必谨慎授权:
使用沙箱隔离:
1 2 3 4 5 6 7 8 9 10 { id: "developer", sandbox: { mode: "all", scope: "agent" }, tools: { allow: ["group:runtime"] }}
限制命令白名单(需额外配置或自定义工具) 审计所有执行命令:
1 2 3 4 5 6 7 { logging: { audit: { events: ["exec", "bash"] } }}
4.3 group:sessions(会话管理)
包含工具
使用场景
适合跨部门协调器(管理多部门协作会话)、项目经理(创建和管理项目会话)、多智能体编排。
单一职责的智能体通常不需要会话管理。
配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 // 跨部门协调器{ id: "cross-coordinator", tools: { allow: [ "group:fs", "group:sessions", "message" ], deny: ["group:runtime"] }}// 项目管理智能体:只能查看,不能创建{ id: "pm", tools: { allow: [ "group:fs", "sessions_list", "sessions_history", "session_status" ], deny: [ "sessions_spawn", "sessions_yield" ] }}
跨智能体协作流程
1 2 3 4 1. sessions_spawn 创建新会话(如项目A协作会话)2. sessions_send 向其他部门智能体发送邀请3. subagents 管理参与协作的子智能体4. sessions_yield 让出控制权,等待其他智能体响应
4.4 group:memory(记忆管理)
包含工具
使用场景
适合所有需要长期记忆的智能体,或需要查询历史上下文的场景。
配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 // 默认配置:所有智能体都可以访问记忆{ agents: { defaults: { tools: { allow: ["group:memory"] } } }}// 临时智能体:不需要记忆{ id: "temporary-assistant", tools: { deny: ["group:memory"] }}
4.5 group:web(网络访问)
包含工具
使用场景
适合产品经理(市场调研、竞品分析)、开发工程师(查找技术文档)、研究员(收集资料)。
配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // 产品经理{ id: "pm", tools: { allow: ["group:fs", "group:web"] }}// 安全审计员:禁止访问外网{ id: "security-auditor", tools: { allow: ["group:fs"], deny: ["group:web"] }}
4.6 group:ui(用户界面)
包含工具
使用场景
适合前端开发(浏览器调试)、UI 设计师(Canvas 操作)、自动化测试。
配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // 前端开发{ id: "frontend-developer", tools: { allow: ["group:fs", "group:runtime", "group:ui"] }}// UI 设计师:只需要 Canvas{ id: "ui-designer", tools: { allow: ["group:fs", "canvas"], deny: ["browser"] }}
4.7 group:automation(自动化)
包含工具
使用场景
适合运维工程师(自动化部署、监控)、项目管理(定时报告)。
普通开发工程师和产品经理通常不需要。
配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // 运维工程师{ id: "ops", tools: { allow: ["group:fs", "group:runtime", "group:automation"] }}// 项目经理:只需要定时任务{ id: "pm", tools: { allow: ["group:fs", "cron"], deny: ["gateway"] }}
4.8 group:messaging(消息发送)
包含工具
使用场景
适合跨部门协调器(发送协作通知)、通知智能体(发送告警、报告)、客服智能体。
配置示例
1 2 3 4 5 6 { id: "cross-coordinator", tools: { allow: ["group:fs", "group:sessions", "group:messaging"] }}
4.9 group:nodes(节点管理)
包含工具
使用场景
适合移动端测试(控制设备)、远程协作(访问团队成员设备)。
4.10 group:openclaw(完全权限)
包含所有内置工具。
仅适合系统管理员、需要完全权限的超级智能体。
配置示例
1 2 3 4 5 6 { id: "admin", tools: { allow: ["group:openclaw"] }}
相当于 root 权限,谨慎使用。
5. 工具组组合策略
5.1 按角色配置
产品经理
需求:读写文档(PRD、会议纪要)、网络搜索(市场调研)、会话查看(了解项目进度)。
1 2 3 4 5 6 7 { id: "pm", tools: { allow: ["group:fs", "group:web", "sessions_list", "session_status"], deny: ["apply_patch", "group:runtime", "group:sessions"] }}
前端开发
需求:文件读写(代码)、执行命令(npm、git)、浏览器调试。
1 2 3 4 5 6 { id: "frontend-developer", tools: { allow: ["group:fs", "group:runtime", "group:ui"] }}
后端开发
需求:文件读写(代码)、执行命令(maven、git)。
1 2 3 4 5 6 7 { id: "backend-developer", tools: { allow: ["group:fs", "group:runtime"], deny: ["browser"] }}
运维工程师
需求:文件读写(配置文件)、执行命令(部署、监控)、自动化(定时任务)。
1 2 3 4 5 6 { id: "ops", tools: { allow: ["group:fs", "group:runtime", "group:automation"] }}
安全审计员
需求:只读文件(代码审计)、只读会话(了解项目状态)。
1 2 3 4 5 6 7 { id: "security-auditor", tools: { allow: ["read", "sessions_list", "session_status"], deny: ["group:runtime", "group:automation", "write", "edit"] }}
5.2 按风险等级配置
低风险配置
适合新智能体、临时智能体、外部协作。
1 2 3 4 5 6 { tools: { allow: ["group:fs", "group:web", "group:memory"], deny: ["group:runtime", "group:automation"] }}
中等风险配置
适合开发智能体、测试智能体。
1 2 3 4 5 6 { tools: { allow: ["group:fs", "group:runtime", "group:web"], deny: ["group:automation"] }}
高风险配置
适合运维智能体、管理员智能体。
1 2 3 4 5 { tools: { allow: ["group:openclaw"] }}
6. 安全最佳实践
6.1 最小权限原则
只授予完成任务所需的最小权限。
错误示例:
1 2 3 4 5 6 { id: "pm", tools: { allow: ["group:openclaw"] // 过度授权 }}
正确示例:
1 2 3 4 5 6 7 { id: "pm", tools: { allow: ["group:fs", "group:web"], deny: ["group:runtime"] }}
6.2 显式拒绝优先
明确拒绝危险工具,避免误操作。
1 2 3 4 5 6 7 { id: "developer", tools: { allow: ["group:runtime"], deny: ["exec"] // exec 最危险 }}
6.3 使用沙箱隔离
高风险工具必须在沙箱中运行。
1 2 3 4 5 6 7 8 9 10 { id: "developer", sandbox: { mode: "all", scope: "agent" }, tools: { allow: ["group:runtime"] }}
6.4 审计所有操作
记录所有工具调用,便于追溯。
1 2 3 4 5 6 7 8 9 { logging: { level: "info", audit: { enabled: true, events: ["exec", "bash", "sessions_spawn", "message"] } }}
7. 常见问题
Q1: 如何查看某个组包含哪些工具?
参考本文第 3 节完整工具组列表,或查阅官方文档。
Q2: 工具组和单个工具可以混用吗?
可以,OpenClaw 会自动展开组并合并。
1 2 3 4 5 { tools: { allow: ["group:fs", "browser", "web_search"] }}
Q3: 如果 allow 和 deny 冲突怎么办?
deny 优先级更高。
1 2 3 4 5 6 { tools: { allow: ["group:runtime"], deny: ["exec"] // exec 会被拒绝 }}
Q4: 如何知道智能体实际拥有了哪些工具?
使用命令查看:
1 openclaw config get agents.list[0].tools
或在 Control UI 的 Config 标签页查看展开后的工具列表。
Q5: 可以自定义工具组吗?
目前 OpenClaw 仅支持预定义工具组,不支持自定义。如有需求,可向官方提 Issue。
8. 总结
工具分组让配置更简洁(group:fs 替代 4 个工具名),语义更清晰(一眼看出权限范围),维护更方便(新工具自动归组)。
几个建议:
优先使用工具组,避免逐个列出工具名 遵循最小权限原则,按需授权 高风险工具( group:runtime)务必配合沙箱使用定期审计工具调用日志
推荐配置模板:
9. 参考资料
OpenClaw 官方文档:https://docs.openclaw.ai/tools 工具配置参考:https://docs.openclaw.ai/gateway/configuration-reference#tools 多智能体路由:https://docs.openclaw.ai/concepts/multi-agent 沙箱隔离:https://docs.openclaw.ai/gateway/sandboxing
感谢你的阅读。如果这篇文章对你有帮助,欢迎点赞支持、分享给朋友,或在评论区分享你的想法。
期待和你的交流!
夜雨聆风