OpenClaw 支持在同一个 Gateway 中运行多个相互隔离的 Agent,配合多个频道账号(如两个 WhatsApp 号),通过 Binding 规则将入站消息精准路由到对应 Agent。
什么是「一个 Agent」?
每个 Agent 是一个完整独立的「大脑」,拥有:
- 独立 Workspace(文件、AGENTS.md/SOUL.md/USER.md、本地配置、人格规则)
- 独立状态目录(
agentDir):认证配置、模型注册表、Agent 专属配置 - 独立 Session 存储(历史记录 + 路由状态),位于
~/.openclaw/agents/<agentId>/sessions
认证配置文件是每个 Agent 独立的,读取路径为:
~/.openclaw/agents/<agentId>/agent/auth-profiles.json
⚠️ 永远不要跨 Agent 复用同一个
agentDir,会导致认证/Session 冲突。
快速路径参考
| 内容 | 路径 |
|---|---|
| 全局配置 | ~/.openclaw/openclaw.json |
| 状态目录 | ~/.openclaw |
| Workspace | ~/.openclaw/workspace(或 workspace-<agentId>) |
| Agent 目录 | ~/.openclaw/agents/<agentId>/agent |
| Session 存储 | ~/.openclaw/agents/<agentId>/sessions |
添加新 Agent
使用 Agent 向导快速新建隔离 Agent:
bash
openclaw agents add work
openclaw agents list --bindings # 验证结果多 Agent = 多人 + 多人格
每个 agentId 成为一个完全隔离的人格:
- 不同手机号/账号(每个频道的
accountId) - 不同人格设定(每个 Workspace 的
AGENTS.md和SOUL.md) - 独立的认证和 Session(除非显式配置,否则互不干扰)
这让多人共用一台 Gateway 服务器成为可能,同时保持各自的 AI「大脑」和数据完全隔离。
路由规则:最精确匹配优先
Binding 是确定性的,按以下优先级匹配(从高到低):
peer精确匹配(DM/群组/频道 ID)parentPeer匹配(线程继承)guildId + roles(Discord 角色路由)guildId(Discord 服务器)teamId(Slack 工作区)accountId精确匹配- 频道级匹配(
accountId: "*") - 回退到默认 Agent
实战配置示例
Telegram:多 Bot 对应多 Agent
json
{
"agents": {
"list": [
{ "id": "main", "workspace": "~/.openclaw/workspace-main" },
{ "id": "alerts", "workspace": "~/.openclaw/workspace-alerts" }
]
},
"bindings": [
{ "agentId": "main", "match": { "channel": "telegram", "accountId": "default" } },
{ "agentId": "alerts", "match": { "channel": "telegram", "accountId": "alerts" } }
],
"channels": {
"telegram": {
"accounts": {
"default": { "botToken": "123456:ABC...", "dmPolicy": "pairing" },
"alerts": { "botToken": "987654:XYZ...", "dmPolicy": "allowlist", "allowFrom": ["tg:123456789"] }
}
}
}
}Discord:多 Bot 对应多 Agent
json
{
"agents": {
"list": [
{ "id": "main", "workspace": "~/.openclaw/workspace-main" },
{ "id": "coding", "workspace": "~/.openclaw/workspace-coding" }
]
},
"bindings": [
{ "agentId": "main", "match": { "channel": "discord", "accountId": "default" } },
{ "agentId": "coding", "match": { "channel": "discord", "accountId": "coding" } }
]
}WhatsApp:不同号码路由到不同 Agent
bash
# 先登录两个账号
openclaw channels login --channel whatsapp --account personal
openclaw channels login --channel whatsapp --account bizjson
{
"agents": {
"list": [
{ "id": "home", "default": true, "workspace": "~/.openclaw/workspace-home" },
{ "id": "work", "workspace": "~/.openclaw/workspace-work" }
]
},
"bindings": [
{ "agentId": "home", "match": { "channel": "whatsapp", "accountId": "personal" } },
{ "agentId": "work", "match": { "channel": "whatsapp", "accountId": "biz" } }
]
}按频道分工:WhatsApp 日常 + Telegram 深度工作
不同频道使用不同模型,实现功能分层:
json
{
"agents": {
"list": [
{ "id": "chat", "name": "Everyday", "workspace": "~/.openclaw/workspace-chat", "model": "anthropic/claude-sonnet-4-5" },
{ "id": "opus", "name": "Deep Work", "workspace": "~/.openclaw/workspace-opus", "model": "anthropic/claude-opus-4-6" }
]
},
"bindings": [
{ "agentId": "chat", "match": { "channel": "whatsapp" } },
{ "agentId": "opus", "match": { "channel": "telegram" } }
]
}家庭群组专属 Agent(含 Docker 沙箱隔离)
json
{
"agents": {
"list": [{
"id": "family",
"name": "Family",
"workspace": "~/.openclaw/workspace-family",
"groupChat": { "mentionPatterns": ["@family", "@familybot"] },
"sandbox": { "mode": "all", "scope": "agent" },
"tools": {
"allow": ["exec", "read", "sessions_list", "sessions_history", "sessions_send", "sessions_spawn", "session_status"],
"deny": ["write", "edit", "apply_patch", "browser", "canvas", "nodes", "cron"]
}
}]
},
"bindings": [{
"agentId": "family",
"match": { "channel": "whatsapp", "peer": { "kind": "group", "id": "120363999999999999@g.us" } }
}]
}每个 Agent 的沙箱与工具独立配置
从 v2026.1.6 开始,每个 Agent 可以有独立的沙箱和工具限制:
json
{
"agents": {
"list": [
{
"id": "personal",
"workspace": "~/.openclaw/workspace-personal",
"sandbox": { "mode": "off" }
},
{
"id": "family",
"workspace": "~/.openclaw/workspace-family",
"sandbox": { "mode": "all", "scope": "agent" },
"tools": {
"allow": ["read"],
"deny": ["exec", "write", "edit", "apply_patch"]
}
}
]
}
}核心概念速查
| 概念 | 说明 |
|---|---|
agentId | 一个「大脑」(Workspace + 独立认证 + 独立 Session 存储) |
accountId | 一个频道账号实例(如 WhatsApp 的 personal 和 biz) |
binding | 将入站消息路由到 agentId 的规则(按 channel + accountId + peer) |
| 直接对话 | 折叠到 agent:<agentId>:<mainKey>(每个 Agent 的「main session」) |
原文:Multi-Agent Routing - OpenClaw | 来源:OpenClaw 官方文档