用飞书机器人管多 Agent,听起来挺复杂,配起来其实不费劲。写篇文章记录一下,方便以后翻,也给有需要的同学一个参考。
一、为什么需要多 Agent
- 分开上下文,不同任务互不干扰
- 不同的 Agent 可以绑定不同的模型,跑不同任务,或多 Agent 协同分工
- 主 Agent 当调度器,按需唤起子 Agent 干活
二、方案设计
飞书只申请了一个机器人,通过 OpenClaw 多 Agent 机制实现分工:
- 主 Agent(main):绑定私聊,负责接收指令、调度资源
- 子 Agent(observer):绑定特定群聊,在群聊内直接指挥,或由 main 调度
三、实现流程
1. 前提
飞书机器人已配置完成,飞书私聊正常收发消息。
2. 创建主 Agent
私聊飞书机器人,发送:
*创建agent main,所有配置继承全局,然后绑定此私聊
用 /new 开新会话,/status 验证:
Session:
agent:main:feishu:direct:ou_********
agent:main:feishu:direct:ou_********
配置文件关键部分:
{
agents: {
list: [
{ id: "main", default: true
},
],
},
bindings: [
{
agentId: "main",
match: { channel: "feishu",
peer: { kind: "direct",
id: "ou_私聊用户的open_id"
}
},
},
],
}
3. 创建群聊
在飞书创建群聊,将机器人加入,修改群名(如观察员)。PC端在群聊设置中可直接复制群聊 ID(格式 oc_xxx)。
若无法从客户端复制,运行 openclaw logs --follow,在群中 @机器人,从日志查找 chat_id。
4. 创建子 Agent
回到飞书机器人私聊:
*创建子agent observer,可由agent main调度,绑定群聊:(群聊ID),关闭需要@才能收到消息
群聊中发 /new 开新会话,/status 查看 Agent 及模型是否正确。
配置文件关键部分:
{
agents: {
list: [
{ id: "main", default: true
},
{ id: "observer"
}, // 新增子 Agent
],
},
bindings: [
// 私聊 → main
{ agentId: "main", match: { channel: "feishu",
peer: { kind: "direct",
id: "ou_私聊open_id"
}
}
},
// 群聊 → observer
{ agentId: "observer",
match: { channel: "feishu",
peer: { kind: "group",
id: "oc_群聊ID"
}
}
},
], }
kind 字段:"direct" = 私聊,"group" = 群聊。
两种干活方式:
- 私聊中让 main 调度 observer
- 直接在 observer 群聊中发消息
踩坑记录:第一次回复时 OpenClaw 仅能绑定话题,需要让它查文档找到绑定群聊的方法。
5. 指定子 Agent 使用不同模型(可选)
提前在 agents.defaults.models 配置好模型后,私聊中直接说:
将 **** 设置为 agent observer 默认模型
配置文件关键部分:
{
agents: {
defaults: {
models: {
"minimax/MiniMax-M2.7":{ alias: "minimax"
},
"anthropic/claude-sonnet-4-6": { alias: "sonnet"
}, },
},
list: [
{ id: "main", default: true
},
{
id: "observer",
model: { primary:"anthropic/claude-sonnet-4-6", fallbacks: []
},
},
],
},
}
模型继承说明:群聊直接指挥 observer → 使用 observer 默认模型;main 通过 sessions_spawn 调度 observer → 模型继承 main 当前会话模型。如需强制使用子 Agent 默认模型,调度时明确指定。
6. 更多子 Agent(扩展)
按同样方法:创建新群聊 → 配置文件中添加新 Agent → 在 bindings 中绑定即可:
{
agents: { list: [
{ id: "main",
default: true
},
{ id: "observer"
},
{ id: "coder"
}, // 新增
] },
bindings: [
{ agentId: "main",
match: { channel: "feishu",
peer: { kind: "direct",
id: "ou_私聊ID"
}
}
},
{ agentId: "observer",
match: { channel: "feishu",
peer: { kind: "group",
id: "oc_群聊ID1"
}
}
},
{ agentId: "coder",
match: { channel: "feishu",
peer: { kind: "group",
id: "oc_群聊ID2"
}
}
}, ], }
四、总结
核心三步:
- 私聊建主 Agent(main),负责总控
- 群聊建子 Agent(observer),负责执行
- 在 bindings 中绑定对应的 agentId 和 peer.id
最小配置示例:
{
agents: { list: [
{ id: "main", default: true
},
{ id: "observer"
},
] },
bindings: [
{ agentId: "main",
match: { channel: "feishu",
peer: { kind: "direct",
id: "ou_私聊ID"
}
}
},
{ agentId: "observer",
match: { channel: "feishu",
peer: { kind: "group",
id: "oc_群聊ID"
}
}
},
],
channels: {
feishu: {
groupPolicy: "allowlist",
groupAllowFrom: ["oc_群聊ID"],
},
},
}
夜雨聆风