共计 1595 个字符,预计需要花费 4 分钟才能阅读完成。
OpenClaw 多 Agent 配置模式完整指南
OpenClaw 支持在单个网关进程中运行多个完全隔离的智能体,每个智能体拥有独立的工作区、会话存储和身份配置。
什么是 Agent?
Agent(智能体) 是一个完全独立的 AI 大脑,拥有:
- 独立工作区 (workspace)- 包含 SOUL.md、AGENTS.md、USER.md 等身份文件
- 独立状态目录 (agentDir)- 存储认证信息、模型配置、会话历史
- 独立会话存储 – 每个 agent 的聊天记录互不干扰
核心概念
| 概念 | 说明 | 示例 |
|---|---|---|
| agentId | 智能体唯一标识 | main、coding、family |
| workspace | 工作区路径 | ~/.openclaw/workspace-coding |
| agentDir | 状态目录 | ~/.openclaw/agents/coding/agent |
| accountId | 渠道账号(如 WhatsApp 号码) | personal、biz |
| binding | 路由规则 – 将消息路由到指定 agent | 按渠道 / 账号 / 群组匹配 |
路由规则(优先级从高到低)
- peer 匹配 – 精确匹配 DM/ 群组 / 频道 ID
- parentPeer 匹配 – 线程继承
- guildId + roles – Discord 角色路由
- guildId – Discord 服务器
- teamId – Slack 团队
- accountId 匹配 – 渠道账号
- 渠道级匹配 – accountId: “*”
- fallback – 默认 agent(default: true 或列表第一个)
重要: 第一个匹配的规则获胜,精确匹配优先于宽泛匹配。
实用配置模式
模式 1:按渠道分离
不同渠道使用不同 agent:
- WhatsApp → 日常聊天 agent(快速模型)
- Telegram → 深度工作 agent(高级模型)
适用场景: WhatsApp 用于日常快速回复,Telegram 用于复杂任务。
模式 2:同渠道不同用户
同一 WhatsApp 号码,不同用户路由到不同 agent:
- 用户 A → alex agent
- 用户 B → mia agent
适用场景: 多人共享一个网关,但保持独立的 AI 人格和数据。
模式 3:特殊用户 / 群组路由
大部分用户用快速模型,特定用户用高级模型:
- VIP 用户 → pro agent(Claude Opus)
- 普通用户 → fast agent(Claude Sonnet)
模式 4:家庭群组专用 Agent
为特定 WhatsApp 群组配置专用 agent:
- 限制工具权限(只读 + 执行)
- 设置 @提及模式
- 绑定到特定群组 ID
模式 5:多 Discord 机器人
每个 agent 使用独立的 Discord 机器人账号:
- 主机器人 → main agent
- 编程机器人 → coding agent
快速开始
1. 创建新 Agent
openclaw agents add coding
这会创建:
- 工作区:~/.openclaw/workspace-coding
- 状态目录:~/.openclaw/agents/coding/agent
- 会话存储:~/.openclaw/agents/coding/sessions
2. 配置路由
编辑 ~/.openclaw/openclaw.json,添加 bindings。
3. 验证配置
openclaw agents list --bindings
openclaw gateway restart
安全隔离
沙箱配置
- 可信 agent – mode: “off”(无沙箱)
- 不可信 agent – mode: “all”(始终沙箱化)
工具权限
每个 agent 可以独立配置允许 / 拒绝的工具:
- allow – 只允许列出的工具
- deny – 拒绝列出的工具
最佳实践
- 精确匹配优先 – peer 绑定放在 channel 绑定前面
- 命名规范 – 使用有意义的 agentId(如 family、coding)
- 独立认证 – 不要共享 agentDir,每个 agent 独立认证
- 定期备份 – 备份 ~/.openclaw/agents/*/sessions
- 测试路由 – 使用 openclaw agents list –bindings 验证
最后更新:2026-03-06
正文完