在 OpenClaw 中同时管理多个飞书机器人,核心在于解耦 Agent 与 Channel 的绑定关系。下面按实战流程梳理配置细节。
一、初始化 Agent
先创建独立的 Agent 实例,每个实例对应不同的业务场景(如新闻推送、开发助手等)。
1. 创建 Agent
使用 CLI 命令新建 Agent,系统会自动生成对应的 workspace 目录:
# 创建新的 Agent
openclaw agents add <agent 名称>
# 示例:创建 dailynews agent
openclaw agents add dailynews
2. 查看与确认
运行以下命令列出所有已创建的 Agent,确保 workspace 路径正确:
openclaw agents list
输出应类似:
Agents:
- main (default) Identity: 💼✨ 小美 Workspace: ~/.openclaw/workspace
- dailynews Workspace: ~/.openclaw/workspace-dailynews
3. 配置文件说明
每个 Agent 目录下都有关键配置文件,按需修改即可:
| 文件 | 说明 |
|---|---|
IDENTITY.md | Agent 身份信息(名字、性格、emoji) |
SOUL.md | Agent 核心价值观和行为准则 |
USER.md | 人类用户信息 |
AGENTS.md | Agent 的行为规范 |
HEARTBEAT.md | 主动模式任务清单 |
MEMORY.md | 长期记忆 |
全局 Agent 列表配置通常位于主配置文件中:
{
"agents": {
"list": [
{"id": "main", "default": true, "name": "小美", "workspace": "/home/username/.openclaw/workspace"},
{"id": "dailynews", "name": "dailynews", "workspace": "/home/username/.openclaw/workspace-dailynews"}
]
}
}
二、对接飞书开放平台
接下来处理 Channel 侧的配置,这是多账号并行的基础。
1. 应用创建与权限
登录 飞书开放平台,创建企业自建应用,注意获取以下信息:
- App ID(如
cli_xxx) - App Secret
权限方面必须勾选:
contact:contact.base:readonly- 读取通讯录im:message:send_as_bot- 发消息im:message:receive- 收消息
发布应用后,才能进行下一步配置。
2. 配置 openclaw.json
在 OpenClaw 配置文件中定义多个飞书账号,分别对应不同的 App ID 和 Secret:
{
"channels": {
"feishu": {
"enabled": true,
"defaultAccount": "main",
"domain": "feishu",
"accounts": {
"main": {"appId": "cli_第一个机器人的 appId", "appSecret": "第一个机器人的 secret"},
"dailynews": {"appId": "cli_第二个机器人的 appId", "appSecret": "第二个机器人的 secret"}
}
}
}
}
3. 验证 Channel
执行命令检查通道状态:
openclaw channels list
若看到 configured, enabled 字样,说明配置生效。
三、绑定 Agent 到 Channel
这一步决定哪个机器人接收哪类消息。支持命令行或配置文件两种方式。
1. 命令行绑定
直接通过命令建立映射关系:
# 绑定 agent 到指定飞书账号
openclaw agents bind --agent <agentId> --bind feishu:<accountId>
# 示例
openclaw agents bind --agent main --bind feishu:main
openclaw agents bind --agent dailynews --bind feishu:dailynews
2. 配置文件绑定
也可以在配置文件中直接写入 bindings 数组:
{
"bindings": [
{"agentId": "main", "match": {"channel": "feishu", "accountId": "main"}},
{"agentId": "dailynews", "match": {"channel": "feishu", "accountId": "dailynews"}}
]
}
3. 查看绑定结果
openclaw agents bindings
输出示例:
Routing bindings:
- dailynews <- feishu accountId=dailynews
- main <- feishu accountId=main
四、配置用户白名单
这里有个关键点:当前版本下,飞书多账号功能在完善中,一次只能配对(pairing)一个机器人。如果强行配对多个,会导致冲突。因此推荐使用白名单机制绕过 pairing 限制。
1. 创建白名单文件
编辑凭证文件,只允许特定用户使用该机器人:
vim ~/.openclaw/credentials/feishu-allowFrom.json
内容格式如下:
{"version":1,"allowFrom":["ou_用户的 open_id_1","ou_用户的 open_id_2"]}
2. 获取用户 OpenID
推荐通过飞书开放平台 API 工具获取:
- 打开 https://open.feishu.cn/document/server-docs/contact-v3/user/get
- 选择目标用户,点击'尝试'
- 返回结果中的
user_id或open_id即为所需值
或者直接在飞书中:打开用户主页 → 点击分享 → 复制链接,链接中包含用户 ID。
3. 注意事项
- 使用
allowFrom白名单后,无需执行openclaw pairing approve - 白名单更安全,仅允许特定用户使用该机器人
五、重启并验证
配置完成后,记得重启网关服务使配置生效:
openclaw gateway restart
随后用不同的飞书机器人发送消息,观察是否路由到了对应的 Agent。
六、常见问题
Q: 提示 'access not configured'
A: 检查
channels.feishu.accounts中是否配置了对应账号的 App ID 和 Secret。
Q: 提示权限错误
A: 需要在飞书开放平台授权,访问链接: https://open.feishu.cn/app/{appId}/auth?q=contact:contact.base:readonly
Q: 绑定后不生效
A: 执行
openclaw gateway restart重启 Gateway 服务。
七、完整配置示例
整合上述步骤,完整的 JSON 配置结构如下:
{
"agents": {
"list": [
{"id": "main", "default": true, "name": "小美", "workspace": "/home/username/.openclaw/workspace"},
{"id": "dailynews", "name": "dailynews", "workspace": "/home/username/.openclaw/workspace-dailynews"}
]
},
"channels": {
"feishu": {
"enabled": true,
"defaultAccount": "main",
"domain": "feishu",
"accounts": {
"main": {"appId": "cli_xxx1", "appSecret": "secret1"},
"dailynews": {"appId": "cli_xxx2", "appSecret": "secret2"}
}
}
},
"bindings": [
{"agentId": "main", "match": {"channel": "feishu", "accountId": "main"}},
{"agentId": "dailynews", "match": {"channel": "feishu", "accountId": "dailynews"}}
]
}
八、注意事项
- 多账号限制:OpenClaw 当前版本(2026.3.x)飞书多账号功能仍在完善中。
- 主要限制:一次只能配对(pairing)一个机器人。
- 解决思路:使用
allowFrom白名单机制,避免依赖 pairing 功能。

