OpenClaw多Agent飞书机器人路由配置实战
摘要:本文详细记录了OpenClaw多Agent系统中飞书机器人消息路由问题的诊断与解决过程。从所有消息错误路由到总指挥,到通过配置bindings实现正确分发,提供了完整的实战经验和避坑指南。
问题背景
最近在部署OpenClaw多Agent系统时,遇到了一个棘手的问题:我们配置了3个飞书机器人,分别对应3个不同的AI专家Agent(总指挥、编程大师、投资顾问)。但所有用户发送给这些机器人的消息,都被错误地路由到了总指挥Agent。
问题现象:
用户向编程大师机器人发送技术问题 → 总指挥回复 用户向投资顾问机器人发送财经咨询 → 总指挥回复
这完全打乱了我们的多Agent协作架构!
问题诊断过程
第一阶段:基础检查
检查OpenClaw配置文件~/.openclaw/openclaw.json✅
agent配置
{"agents": {"list": [{"id": "commander","name": "指挥官","workspace": "/home/user/.openclaw/workspace-commander","agentDir": "/home/user/.openclaw/agents/commander/agent","subagents": {"allowAgents": ["coder","investor"]}},{"id": "coder","name": "编程大师","workspace": "/home/user/.openclaw/workspace-coder","agentDir": "/home/user/.openclaw/agents/coder/agent","model": "moonshot/kimi-k2.5"},{"id": "investor","name": "投资顾问","workspace": "/home/user/.openclaw/workspace-investor","agentDir": "/home/user/.openclaw/agents/investor/agent"}]}}
渠道飞书机器人配置
{"channels": {"feishu": {"enabled": true,"connectionMode": "websocket","domain": "feishu","requireMention": true,"accounts": {"commander_bot": {"appId": "cli_xxx","appSecret": "pxxx"},"coder_bot": {"appId": "cli_xxx","appSecret": "cqxx"},"investor_bot": {"appId": "cli_xxx","appSecret": "gkxx"}}}}}
检查Gateway日志✅
openclaw logs --follow0:43:07+00:00 info gateway/channels/feishu {"subsystem":"gateway/channels/feishu"} feishu[commander_bot]: Feishu[commander_bot] DM from ou_ec78524c64adc02cbbabf9ad8ed64956: 你现在有哪些技能?10:43:07+00:00 info gateway/channels/feishu {"subsystem":"gateway/channels/feishu"} feishu[commander_bot]: dispatching to agent (session=agent:commander:feishu:direct:ou_ec78524c64adc02cbbabf9ad8ed64956)
第二阶段:深入学习官方文档
通过阅读OpenClaw官方文档《Multi-Agent Routing》,发现了关键信息:
核心要点:
多Agent路由必须配置bindings accountId是路由的关键标识 路由规则按特异性匹配 没有bindings时,所有消息路由到默认或第一个Agent
根本原因
缺少bindings配置!我们的配置虽然正确设置了agents.list和channels.feishu.accounts,但缺少了关键的bindings配置。OpenClaw Gateway收到飞书消息后,不知道应该将哪个accountId的消息路由到哪个agentId。
解决方案
添加bindings配置
{"bindings": [{"agentId": "commander","match": {"channel": "feishu","accountId": "commander_bot"}},{"agentId": "coder","match": {"channel": "feishu","accountId": "coder_bot"}},{"agentId": "investor","match": {"channel": "feishu","accountId": "investor_bot"}}]}
实施步骤
手动编辑配置文件
备份原配置:
bash cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.backup编辑配置文件,在根级别添加bindings数组
验证:
openclaw config validate 或者 openclaw doctor重启Gateway
openclaw gateway restart验证结果
配置更新后,进行了全面测试:
✅ 回复来自编程大师Agent
我是 CodeMaster 💻,你的编程专家向投资顾问机器人发送:"你是?"
✅ 回复来自投资顾问Agent
我是投资顾问,专注于为我的用户提供专业的投资分析和财经建议所有消息路由恢复正常!
技术要点总结
1. OpenClaw多Agent路由架构
2. bindings配置的核心作用
3. 路由匹配规则
4. 常见配置错误
避坑指南
1. 配置检查清单
2. 调试技巧
结语
OpenClaw的多Agent架构非常强大,但正确的配置是关键。bindings配置是多Agent路由的核心,缺少它会导致所有消息被错误路由。通过这次实战,我们不仅解决了具体问题,更深入理解了OpenClaw的路由机制。
关键收获:
阅读官方文档是解决问题的捷径 bindings是多Agent路由的必备配置 系统化的诊断方法比盲目尝试更有效
夜雨聆风