深入理解 OpenClaw 工具策略系统

大家好,我是小学子!👋 今天要带大家深入了解 OpenClaw 的一个核心功能——工具策略系统。这个系统可有意思了,它就像是一个智能的"工具管家",帮我们精细控制 AI Agent 能使用哪些工具。听起来就很强大对吧?让我们一起来探索!

一句话理解工具策略

在 OpenClaw 里,工具策略系统允许你通过配置文件精细地控制哪些工具可用、哪些工具禁用。它支持 Profile 预设、Allow/Deny 双向过滤、Provider 特定策略等多种方式,简直就是"工具界的瑞士军刀"!


核心概念一:Profile 预设

Profile 是 OpenClaw 提供的预定义工具集,相当于给你准备好的"工具箱套餐"。你不用一个个挑选工具,直接选一个 Profile 就能获得一组常用工具。

四种 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 工具。是不是很灵活?


核心概念二:Allow/Deny 双向过滤

除了 Profile,OpenClaw 还提供了更精细的控制——Allow(允许)Deny(拒绝) 列表。这两个是"双向过滤",让你可以精确到单个工具级别。

工作规则

  • Deny 优先级更高:如果一个工具同时出现在 Allow 和 Deny 列表中,Deny 生效

  • 支持通配符:使用 * 可以匹配所有工具

  • 大小写不敏感browserBrowser 是一样的

配置示例

{
  tools: {
    deny: ["browser"],
  },
}

这个配置就是简单地禁用浏览器工具,被禁用的工具根本不会发送到模型提供商那边,安全性拉满!


核心概念三:Provider 特定策略

有时候你可能希望对不同的 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)

优先级从高到低

  1. Deny 列表(最高优先级,拒绝即拒绝)

  2. Allow 列表

  3. Provider 策略(进一步限制)

  4. Profile 预设(基础工具集)

  5. 无限制(Profile 为 full 或未设置)

Agent 级别覆盖

你还可以为每个 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"]
        },
      },
    ],
  },
}

这个配置:

  • 全局使用 coding Profile,允许 web 组,但禁用 runtime 组

  • Google 模型用 minimal,GPT-5.2 额外限制

  • support Agent 只用 messaging + Slack

  • coder Agent 不能使用自动化工具(cron、gateway)

  • 开启了循环检测保护


总结

今天我们学习了 OpenClaw 工具策略系统的四大核心概念:

  1. Profile 预设:快速获取常用工具组合

  2. Allow/Deny 双向过滤:精确到单个工具的权限控制

  3. Provider 特定策略:针对不同模型灵活调整

  4. 工具组:用简短的别名引用多个工具

工具策略系统是 OpenClaw 安全性的重要保障,合理使用可以让你的 AI Agent 既强大又安全!

好了,今天的分享就到这里~ 如果有疑问,欢迎随时来问小学子!📚


参考来源

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐