Agents 与路由
Agent loop 与 multi-agent。
Agents 与路由
这一课你将能做到
- 理解 OpenClaw 的 agent 循环(agent loop)与主动核心(proactive core)
- 配置多 agent 并设置路由规则
- 为「评审 bot + 值班 bot + 日报 bot」设计多 agent 架构
为什么要学
一个 bot 什么都会等于什么都不精。评审 bot 需要冷静严谨,值班 bot 需要紧急响应,日报 bot 需要活泼亲切——用一个 agent 硬撑三种人格,结果往往是人格分裂。OpenClaw 的多 agent 路由让不同渠道、不同场景、不同用户群走不同的 agent,各有人设、各有记忆、各有权限。
人话:多 agent 就是给团队招不同性格的「虚拟员工」,而不是逼一个员工八面玲珑。
先建立图像
消息进入 Gateway
│
▼
路由层(Routing)
├── 按渠道:Slack #code-review → 评审 agent
├── 按关键词:含「告警」「紧急」→ 值班 agent
├── 按用户:管理员 DM → 高权限 agent
└── 默认:其他 → 通用 agent
│
▼
Agent 循环(Agent Loop)
├── 接收消息 + 上下文
├── 调用模型推理
├── 可能调用工具(skills / MCP)
├── 生成回复
└── 写记忆、写日志
│
▼
主动核心(Proactive Core)
├── 定时任务触发(cron)
├── 事件触发(webhook / hook)
└── 心跳检查(heartbeat)
每个 agent 是独立的:独立 workspace、独立记忆、独立模型配置、独立权限。
跟着做
步骤 1:查看当前 agent 配置
openclaw config get agents
openclaw agents list
步骤 2:配置多 agent
编辑 ~/.openclaw/openclaw.json:
{
"agents": {
"defaults": {
"systemAgent": {
"agentId": "assistant",
"model": "claude-sonnet-4-20250514"
}
},
"entries": {
"reviewer": {
"workspace": "~/.openclaw/workspaces/reviewer",
"systemAgent": {
"model": "claude-sonnet-4-20250514"
},
"description": "代码评审 bot,严谨、直接、引用规范"
},
"oncall": {
"workspace": "~/.openclaw/workspaces/oncall",
"systemAgent": {
"model": "claude-sonnet-4-20250514"
},
"description": "值班问答 bot,紧急优先、步骤导向"
},
"standup": {
"workspace": "~/.openclaw/workspaces/standup",
"systemAgent": {
"model": "claude-3-haiku"
},
"description": "日报 bot,轻量、活泼、定时触发"
}
}
}
}
步骤 3:为每个 agent 准备 workspace
mkdir -p ~/.openclaw/workspaces/reviewer
mkdir -p ~/.openclaw/workspaces/oncall
mkdir -p ~/.openclaw/workspaces/standup
每个目录下放独立的 SOUL.md、AGENTS.md、USER.md(见第 3 课)。
步骤 4:配置路由规则
路由可以通过渠道配置绑定到特定 agent:
{
"channels": {
"slack": {
"accounts": {
"default": {
"agentId": "assistant"
}
},
"channels": {
"C01234567": {
"agentId": "reviewer"
}
}
}
}
}