OpenClaw 多 Agent 与飞书机器人配置实践
在 OpenClaw 架构中,建议遵循'一个 Agent 对应一个飞书机器人'的原则,这样能避免消息路由混乱,也便于权限管理。
一、创建新的 Agent
首先我们需要创建一个独立的 Agent 实例。通过命令行工具执行以下操作:
# 创建新 Agent,命名为 new-agent
openclaw agents add new-agent
# 确认创建结果
openclaw agents list
二、配置飞书渠道信息
每个 Agent 需要绑定独立的飞书应用凭证(App ID 和 App Secret)。请在终端中运行配置命令,替换为你实际获取的值:
# 设置飞书渠道配置
openclaw config set agents.new-agent.channels.feishu.appId "你的 new-agent 飞书 App ID"
openclaw config set agents.new-agent.channels.feishu.appSecret "你的 new-agent 飞书 App Secret"
# 重启网关服务使配置生效
openclaw gateway restart
配置完成后,系统会生成或更新 openclaw.json 配置文件。你可以手动检查文件内容,重点关注 channels 下的 accounts 部分,确保结构如下所示:
"channels": {
"feishu": {
"enabled": true,
"domain": "feishu",
"groupPolicy": "allowlist",
"accounts": {
"main": {
"appId": "cli_1",
"appSecret": "appSecret1",
"botName": "主助手",
"groupAllowFrom": ["ou_id1"]
},
"new-agent": {
"appId": "cli_2",
"appSecret": "appSecret2",
"botName": "工作助手",
"groupAllowFrom": ["ou_id2"]
}
},
"dmPolicy": "pairing"
}
}
三、绑定 Agent 与飞书账号
接下来需要将创建的 Agent 与具体的飞书账户进行绑定。这一步决定了哪个 Agent 处理哪类消息。
# 将 agent 绑定到指定飞书账号
openclaw agents bind --agent <agentId> --bind feishu:<accountId>
# 示例:绑定 main 和新创建的 agent
openclaw agents bind --agent main --bind feishu:main
openclaw agents bind --agent new-agent --bind feishu:new-agent
绑定成功后,JSON 配置文件中的 bindings 字段应显示为:
"bindings": [
{
"agentId": "main",
"match": {
"channel": "feishu",
"accountId": "main"
}
},
{
"agentId": "work",
"match": {
"channel": "feishu",
"accountId": "new-agent"
}
}
]
注意这里的 accountId 必须与前面配置的 accounts 名称保持一致。
四、常见问题排查
在实际部署过程中,可能会遇到以下几种情况:
- 发送消息无法回复:通常是因为长连接未建立或网络策略限制,请检查防火墙及网关状态。
- 飞书配置错误:务必核对 APP ID 和密钥是否填写正确,大小写敏感。
- 401 Token 错误:这通常意味着 Token 过期或配置未同步,尝试重新配置并重启服务。
- 应用复用问题:不要试图用一个飞书应用绑定多个 Agent,这会导致消息分发冲突。坚持'一应用一 Agent'的规范最稳妥。
完成上述步骤后,再次执行 openclaw gateway restart 即可正式使用多 Agent 模式。
