OpenClaw 工具插件使用:让你的 AI 助手无所不能

OpenClaw 的强大之处在于它提供第一类工具,让 AI Agent 可以执行各种实际操作。本文将详细介绍 OpenClaw 的工具系统,包括核心工具、工具策略和如何使用工具。

什么是第一类工具?

OpenClaw 的工具是第一类对象,这意味着:

  • 类型安全:所有工具都有明确定义的输入/输出类型
  • 无 Shell:不需要通过 Shell 执行,更安全可靠
  • Agent 原生:AI Agent 直接调用工具,无需中间层
  • 替代旧技能:替代了旧的 openclaw-* 技能系统

核心工具列表

1. 浏览器工具(browser)

通过浏览器控制 Canvas,渲染实时可视化内容:

  • 功能:浏览器自动化、屏幕截图、页面交互
  • 用途:网页测试、数据抓取、自动化操作

2. 文件系统工具(group:fs)

读取、写入、编辑文件:

  • read:读取文件内容
  • write:写入文件内容
  • edit:编辑文件
  • apply_patch:应用结构化补丁(多文件编辑)

3. Web 工具(group:web)

网络搜索和内容获取:

  • web_search:使用 Perplexity、Brave、Gemini、Grok、Kimi 搜索
  • web_fetch:获取 URL 内容并提取可读文本

4. 代码执行工具(exec / process)

在沙箱中运行代码:

  • exec:执行 Shell 命令
  • process:管理后台进程

5. 会话管理工具(group:sessions)

管理多个对话会话:

  • sessions_list:列出所有会话
  • sessions_history:获取会话历史
  • sessions_send:发送消息到会话
  • sessions_spawn:创建新会话
  • session_status:获取会话状态

6. 内存工具(group:memory)

搜索和获取历史数据:

  • memory_search:搜索历史对话和知识库
  • memory_get:获取特定记忆

7. UI 工具(group:ui)

浏览器和 Canvas 控制:

  • browser:浏览器控制
  • canvas:Canvas 渲染

8. 自动化工具(group:automation)

自动化任务:

  • cron:定时任务
  • gateway:网关控制

9. 节点工具(group:nodes)

节点管理和控制。

10. 消息工具(message)

发送消息到任何连接的渠道。

工具分组

OpenClaw 提供工具分组,方便批量管理:

分组 包含工具 说明
group:runtime exec, bash, process 代码执行
group:fs read, write, edit, apply_patch 文件系统
group:sessions sessions_* 会话管理
group:memory memory_search, memory_get 内存检索
group:web web_search, web_fetch 网络操作
group:ui browser, canvas UI 控制
group:automation cron, gateway 自动化
group:messaging message 消息发送
group:nodes nodes 节点管理
group:openclaw 所有内置工具 核心工具集

工具策略(Tools Policy)

你可以通过配置文件控制哪些工具可以被 Agent 使用:

全局允许/拒绝

openclaw.json 中配置:

{
  "tools": {
    "deny": ["browser"],
    "allow": ["group:fs", "web_search"]
  }
}

注意:deny 优先级高于 allow

工具 Profile

OpenClaw 提供预定义的工具 Profile:

Profile 包含工具 适用场景
minimal session_status 最小权限,仅状态查询
coding group:fs, group:runtime, group:sessions, group:memory, image 编程助手
messaging group:messaging, sessions_* 消息处理
full 所有工具 完整权限(默认)

示例配置

消息专用 Profile

{
  "tools": {
    "profile": "messaging",
    "allow": ["slack", "discord"]
  }
}

编程 Profile,禁止执行

{
  "tools": {
    "profile": "coding",
    "deny": ["group:runtime"]
  }
}

全局编程 Profile,消息专用 Agent

{
  "tools": {
    "profile": "coding"
  },
  "agents": {
    "list": [
      {
        "id": "support",
        "tools": {
          "profile": "messaging",
          "allow": ["slack"]
        }
      }
    ]
  }
}

按提供商限制工具

你可以为不同的模型提供商设置不同的工具策略:

{
  "tools": {
    "profile": "coding",
    "byProvider": {
      "google-antigravity": {
        "profile": "minimal"
      },
      "openai/gpt-5.2": {
        "allow": ["group:fs", "sessions_list"]
      }
    }
  }
}

高级功能

循环检测

OpenClaw 可以检测并阻止工具调用的无限循环:

{
  "tools": {
    "loopDetection": {
      "enabled": true,
      "warningThreshold": 10,
      "criticalThreshold": 20,
      "globalCircuitBreakerThreshold": 30,
      "historySize": 30,
      "detectors": {
        "genericRepeat": true,
        "knownPollNoProgress": true,
        "pingPong": true
      }
    }
  }
}

插件工具

插件可以注册额外的工具:

  • Lobster:类型化工作流运行时,支持可恢复审批
  • LLM Task:JSON-only LLM 步骤,结构化工作流输出
  • Diffs:只读差异查看器,PNG/PDF 文件渲染

工具使用示例

Web 搜索

配置 Web 搜索提供商:

$ openclaw configure --section web

搜索示例:

@openclaw 搜索最新的 AI 技术趋势

文件操作

读取文件:

@openclaw 读取 README.md 文件

编辑文件:

@openclaw 把 config.json 中的 timeout 改为 300

代码执行

运行脚本:

@openclaw 运行 backup.sh 脚本

安全注意事项

  • 最小权限:默认使用最小权限 Profile
  • 拒绝优先deny 优先级高于 allow
  • 沙箱:代码执行在沙箱中进行
  • 审批机制:敏感操作需要审批

总结

OpenClaw 的工具系统是其强大功能的核心。通过精心配置工具策略,你可以让 AI Agent 执行各种任务,同时保持安全性。在下一篇文章中,我们将学习如何自定义技能和工作流。

相关资源

发表回复

后才能评论