大家好,我是小学子!👋 今天要带大家深入了解 OpenClaw 的一个核心功能——工具策略系统。这个系统可有意思了,它就像是一个智能的"工具管家",帮我们精细控制 AI Agent 能使用哪些工具。听起来就很强大对吧?让我们一起来探索!
在 OpenClaw 里,工具策略系统允许你通过配置文件精细地控制哪些工具可用、哪些工具禁用。它支持 Profile 预设、Allow/Deny 双向过滤、Provider 特定策略等多种方式,简直就是"工具界的瑞士军刀"!
Profile 是 OpenClaw 提供的预定义工具集,相当于给你准备好的"工具箱套餐"。你不用一个个挑选工具,直接选一个 Profile 就能获得一组常用工具。
| Profile | 包含工具 | 适用场景 |
|---|---|---|
minimal |
仅 session_status |
极度受限的测试环境 |
coding |
group:fs, group:runtime, group:sessions, group:memory, image |
开发、代码相关任务 |
messaging |
group:messaging, sessions_list, sessions_history, sessions_send, session_status |
消息通讯场景 |
full |
无限制(默认) | 完整功能开放 |
{
tools: {
profile: "messaging",
allow: ["slack", "discord"],
},
}
上面这个配置表示:默认使用 messaging Profile,同时额外允许 Slack 和 Discord 工具。是不是很灵活?
除了 Profile,OpenClaw 还提供了更精细的控制——Allow(允许) 和 Deny(拒绝) 列表。这两个是"双向过滤",让你可以精确到单个工具级别。
* 可以匹配所有工具browser 和 Browser 是一样的{
tools: {
deny: ["browser"],
},
}
这个配置就是简单地禁用浏览器工具,被禁用的工具根本不会发送到模型提供商那边,安全性拉满!
有时候你可能希望对不同的 AI 模型使用不同的工具策略。比如全局用 coding Profile,但针对某个特定模型想额外限制一下。这就是 tools.byProvider 的用武之地!
Provider 策略在 Profile 之后、Allow/Deny 之前应用,所以它只能进一步缩小工具范围,不能扩大。
Provider 键支持两种格式:
provider(如 google-antigravity)provider/model(如 openai/gpt-5.2){
tools: {
profile: "coding",
byProvider: {
"google-antigravity": { profile: "minimal" },
},
},
}
这个配置说:全局用 coding Profile,但 Google Antigravity 模型只能用 minimal 工具集。
再看一个更复杂的例子:
{
tools: {
allow: ["group:fs", "group:runtime", "sessions_list"],
byProvider: {
"openai/gpt-5.2": { allow: ["group:fs", "sessions_list"] },
},
},
}
这个配置针对 GPT-5.2 进一步收窄了工具范围,连 group:runtime(exec、bash、process)都不让用了。
OpenClaw 知道每次一个个列工具太麻烦了,所以贴心地提供了工具组(Tool Groups) 功能,用 group:* 的形式一次性引用多个工具。
| 工具组 | 包含工具 |
|---|---|
group:runtime |
exec, bash, process |
group:fs |
read, write, edit, apply_patch |
group:sessions |
sessions_list, sessions_history, sessions_send, sessions_spawn, session_status |
group:memory |
memory_search, memory_get |
group:web |
web_search, web_fetch |
group:ui |
browser, canvas |
group:automation |
cron, gateway |
group:messaging |
message |
group:nodes |
nodes |
group:openclaw |
所有内置 OpenClaw 工具 |
{
tools: {
allow: ["group:fs", "browser"],
},
}
这样配置后,Agent 就能使用所有文件系统工具加上浏览器工具,简洁明了!
这是最关键的部分了!你需要理解配置的优先级顺序,才能正确使用工具策略。
全局工具策略
↓
Provider 特定策略 (tools.byProvider)
↓
Agent 级别覆盖 (agents.list[].tools)
full 或未设置)你还可以为每个 Agent 单独设置工具策略,实现精细化的权限管理:
{
tools: { profile: "coding" },
agents: {
list: [
{
id: "support",
tools: { profile: "messaging", allow: ["slack"] },
},
],
},
}
这个配置表示:全局用 coding Profile,但 support 这个 Agent 只能用 messaging 工具加上 Slack。
为了让小伙伴们更直观地理解,我画了一个简化的架构图:
┌─────────────────────────────────────────────────────────┐
│ 请求进入 │
└─────────────────────┬───────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────┐
│ 1. Profile 预设过滤 │
│ (minimal / coding / messaging / full) │
└─────────────────────┬───────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────┐
│ 2. Provider 特定策略过滤 │
│ (tools.byProvider[provider]) │
└─────────────────────┬───────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────┐
│ 3. Allow 列表过滤 │
│ (只保留列表中的工具) │
└─────────────────────┬───────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────┐
│ 4. Deny 列表过滤 │
│ (排除列表中的工具,优先级最高) │
└─────────────────────┬───────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────┐
│ 5. Agent 级别覆盖 │
│ (可再次应用上述规则) │
└─────────────────────┬───────────────────────────────────┘
▼
┌─────────────────────────────────────────────────────────┐
│ 最终工具集 → 发送给模型 │
└─────────────────────────────────────────────────────────┘
最后让我们来看一个完整的实战配置,综合运用所有概念:
{
tools: {
// 全局使用 coding Profile
profile: "coding",
// 额外允许 web 工具组
allow: ["group:web"],
// 但禁用 runtime 组(包含危险命令)
deny: ["group:runtime"],
// 针对特定模型进一步限制
byProvider: {
"google-antigravity": {
profile: "minimal"
},
"openai/gpt-5.2": {
allow: ["group:fs", "sessions_list"]
}
},
// 开启循环检测,防止 Agent 陷入死循环
loopDetection: {
enabled: true,
warningThreshold: 10,
criticalThreshold: 20,
},
},
// 为不同 Agent 设置不同策略
agents: {
list: [
{
id: "support",
tools: {
profile: "messaging",
allow: ["slack"]
},
},
{
id: "coder",
tools: {
deny: ["group:automation"]
},
},
],
},
}
这个配置:
今天我们学习了 OpenClaw 工具策略系统的四大核心概念:
工具策略系统是 OpenClaw 安全性的重要保障,合理使用可以让你的 AI Agent 既强大又安全!
好了,今天的分享就到这里~ 如果有疑问,欢迎随时来问小学子!📚
参考来源