我转变下思维发现其实可以:同一个 Agent,平时能当独立 Telegram Bot 私聊;需要联动时,又能被主 Agent 当 subagent 调用。
第一步:给每个 Agent 一个独立 TG 入口
在~/.openclaw/openclaw.json 的 channels.telegram.accounts 里,给每个账号配 token。通过Telegram: Launch @BotFather
{
"channels": {
"telegram": {
"accounts": {
"default": {
"enabled": true,
"botToken": "主指挥官token",
"dmPolicy": "pairing"
},
"study": {
"enabled": true,
"botToken": "学习agent的token",
"dmPolicy": "pairing"
},
"finance": {
"enabled": true,
"botToken": "理财agent的token",
"dmPolicy": "pairing"
}
}
}
}
}
这一步就解决每个 bot 能单独聊天,还没到谁能调谁的环节。
第二步:把 TG 账号路由到对应 Agent
还是这个文件,改 bindings。
{
"bindings": [
{
"agentId": "commander",
"match": { "channel": "telegram", "accountId": "default" }
},
{
"agentId": "study",
"match": { "channel": "telegram", "accountId": "study" }
},
{
"agentId": "finance",
"match": { "channel": "telegram", "accountId": "finance" }
}
]
}
做到这步,就有多个独立 TG bot了,至少能单独聊了。
第三步:给主 Agent 开调度权限(关键)
依旧是~/.openclaw/openclaw.json,改 agents.list 里主 Agent 的 subagents.allowAgents。
{
"agents": {
"list": [
{
"id": "commander",
"name": "中央指挥官",
"subagents": {
"allowAgents": ["study", "finance", "research"]
}
},
{
"id": "study",
"name": "学习训练Agent"
},
{
"id": "finance",
"name": "理财Agent"
}
]
}
}
其实就是commander 能把 study/finance/research 当小弟调用,而 study 本身还是独立 TG bot,能单独聊。
第四步(可选):允许互为领导
要是真想 A 调 B、B 也调 A,也是在这加双向 allowAgents,但得同时调高嵌套深度,不然小弟没法再派活。
{
"agents": {
"defaults": {
"subagents": {
"maxSpawnDepth": 2,
"maxChildrenPerAgent": 5
}
}
}
}
我还没试过。
第五步:如果不想再收配对码
我之前发消息没反应 / 看不到配对码”,本质是 DM 策略的问题。
可以在账号下加 allowFrom 放行 user id(比如 12345678):
{
"channels": {
"telegram": {
"accounts": {
"study": {
"dmPolicy": "pairing",
"allowFrom": ["12345678"]
}
}
}
}
}
这样不用一个一个配对。
总结
想实现每个 Agent 有独立 TG,还能被主 Agent 调用,必须同时搞定三层:
- accounts:配 bot token(入口)
- bindings:把入口绑到对应 Agent(归属)
- subagents.allowAgents:指定谁能调谁(权限)
希望对大家有帮助,如果还有什么改进的欢迎佬友分享,这是我这几天的收获~
更新了一下我的架构
我现在配置是一个董事长,然后 4 个组长,每个组下面有两个人,总共是 13 个人,一个组是三个人,然后设了个组长群 然后每个组也有一个群,还有一个全体群。我的boss的总结如下(是AIGC已经截图,审核明察):
