广播组
将 WhatsApp 消息广播到多个代理
实验性
广播组使多个代理能够同时处理和响应同一消息。这允许您创建专门的代理团队,在单个 WhatsApp 群组或 DM 中协同工作——所有这些都使用一个电话号码。
当前范围:仅限 WhatsApp(web 通道)。
广播组在通道允许列表和群组激活规则之后进行评估。在 WhatsApp 群组中,这意味着广播在 OpenClaw 通常会回复时发生(例如:在提及时,取决于您的群组设置)。
用例
1. 专门的代理团队
部署具有原子化、专注职责的多个代理:
Group: "Development Team" Agents: - CodeReviewer (reviews code snippets) - DocumentationBot (generates docs) - SecurityAuditor (checks for vulnerabilities) - TestGenerator (suggests test cases)
每个代理处理相同的消息并提供其专业视角。
2. 多语言支持
Group: "International Support" Agents: - Agent_EN (responds in English) - Agent_DE (responds in German) - Agent_ES (responds in Spanish)
3. 质量保证工作流程
Group: "Customer Support" Agents: - SupportAgent (provides answer) - QAAgent (reviews quality, only responds if issues found)
4. 任务自动化
Group: "Project Management" Agents: - TaskTracker (updates task database) - TimeLogger (logs time spent) - ReportGenerator (creates summaries)
配置
在顶层添加一个 ''broadcast'' 部分(在 ''bindings'' 旁边)。键是 WhatsApp 对等 ID:
- 群组聊天:群组 JID(例如 ''[email protected]'')
- DM:E.164 电话号码(例如 ''+15551234567'')
{
"broadcast": {
"[email protected]": ["alfred", "baerbel", "assistant3"]
}
}结果:当 OpenClaw 在此聊天中回复时,它将运行所有三个代理。
处理策略
控制代理如何处理消息:
并行(默认):所有代理同时处理:
{
"broadcast": {
"strategy": "parallel",
"[email protected]": ["alfred", "baerbel"]
}
}顺序:代理按顺序处理(一个等待前一个完成):
{
"broadcast": {
"strategy": "sequential",
"[email protected]": ["alfred", "baerbel"]
}
}完整示例
{
"agents": {
"list": [
{
"id": "code-reviewer",
"name": "Code Reviewer",
"workspace": "/path/to/code-reviewer",
"sandbox": { "mode": "all" }
},
{
"id": "security-auditor",
"name": "Security Auditor",
"workspace": "/path/to/security-auditor",
"sandbox": { "mode": "all" }
},
{
"id": "docs-generator",
"name": "Documentation Generator",
"workspace": "/path/to/docs-generator",
"sandbox": { "mode": "all" }
}
]
},
"broadcast": {
"strategy": "parallel",
"[email protected]": ["code-reviewer", "security-auditor", "docs-generator"],
"[email protected]": ["support-en", "support-de"],
"+15555550123": ["assistant", "logger"]
}
}工作原理
消息流程
1. 传入消息 到达 WhatsApp 群组
2. ''广播检查'':系统检查对等 ID 是否在 ''broadcast'' 中
3. 如果在广播列表中:
- 所有列出的代理处理消息
- 每个代理都有自己的会话密钥和隔离的上下文
- 代理并行(默认)或顺序处理
4. 如果不在广播列表中:
- 应用正常路由(第一个匹配的绑定)
注意:广播组不会绕过通道允许列表或群组激活规则(提及/命令/等)。它们只会在消息符合处理条件时更改哪些代理运行。
会话隔离
广播组中的每个代理保持完全独立的:
- ''会话密钥''(''agent:alfred:whatsapp:group:120363...'' vs ''agent:baerbel:whatsapp:group:120363...'')
- 对话历史(代理看不到其他代理的消息)
- 工作区(如果配置了独立的沙箱)
- 工具访问(不同的允许/拒绝列表)
- 内存/上下文(独立的 IDENTITY.md、SOUL.md 等)
- 群组上下文缓冲区(用于上下文的最近群组消息)按对等方共享,因此所有广播代理在触发时看到相同的上下文
这允许每个代理具有:
- 不同的个性
- 不同的工具访问(例如:只读与读写)
最佳实践
1. 保持代理专注
为每个代理设计单一、明确的职责。
2. 使用描述性名称
明确每个代理的作用。
3. 配置不同的工具访问
只给代理它们需要的工具。
4. 监控性能
对于许多代理,考虑使用 ''"strategy": "parallel"'',限制群组大小,并使用更快的模型。
5. 优雅地处理失败
代理独立失败。一个代理的错误不会阻止其他代理。
故障排除
代理不响应
检查:
1. 代理 ID 存在于 ''agents.list'' 中
2. 对等 ID 格式正确(例如 ''[email protected]'')
3. 代理不在拒绝列表中
调试:
tail -f ~/.openclaw/logs/gateway.log | grep broadcast
只有一个代理响应
原因:对等 ID 可能在 ''bindings'' 中但不在 ''broadcast'' 中。
修复:添加到广播配置或从绑定中删除。