OpenClaw 飞书群绑定不生效?你可能踩了这个 accountId 的坑

3 阅读2分钟

背景

最近在用 OpenClaw 给飞书群配置专属 Agent,想实现"不同群用不同智能体"的效果。比如:

  • 投资讨论群 → 自动路由到 investment agent
  • 技术交流群 → 自动路由到 tech agent

按照文档的例子配置,结果……就是不生效。排查了一圈,发现是一个很容易忽略的细节。

遇到的问题

我想给某个飞书群绑定 investment agent,于是写了这样的配置:

"bindings": [
  {
    "agentId": "investment",
    "match": {
      "channel": "feishu",
      "peer": {
        "kind": "group",
        "id": "xxxxx"
      }
    }
  }
]

看起来没问题

  • agentId 指定了目标 agent
  • channel 是飞书
  • peer 指定了群 ID

但在群里发消息,仍然是main agent响应。

排查过程

第一反应是检查各种 ID 对不对:

  • ✅ 群 ID 没写错
  • ✅ channel 没写错
  • ✅ agentId 没写错

然后开始怀疑是不是 binding 机制本身有问题,去翻了官方文档,终于找到了这段话:

Important account-scope detail:

  • A binding that omits accountId matches the default account only.
  • Use accountId: "*" for a channel-wide fallback across all accounts.

根本原因

accountId 这个字段的行为和直觉不一样:

写法实际效果
省略 accountId只匹配默认账户,不是"所有账户"
accountId: "main"匹配指定账户
accountId: "*"匹配所有账户(通配符)

我的配置里省略了 accountId,以为会匹配所有飞书账户,结果它只匹配了"默认账户"——而我的飞书channel 配置的是 main 账户。

正确的配置

"bindings": [
  {
    "agentId": "investment",
    "match": {
      "channel": "feishu",
      "accountId": "main",
      "peer": {
        "kind": "group",
        "id": "xxxx"
      }
    }
  }
]

或者,如果你想这个群在所有飞书账户下都走这个 agent:

"bindings": [
  {
    "agentId": "investment",
    "match": {
      "channel": "feishu",
      "accountId": "*",
      "peer": {
        "kind": "group",
        "id": "xxxx"
      }
    }
  }
]

额外发现:Binding 升级机制

文档里还提到一个有趣的细节:

If you later add the same binding for the same agent with an explicit account id, OpenClaw upgrades the existing channel-only binding to account-scoped instead of duplicating it.

意思是:同一个 agent 的 binding 不会重复创建,而是会"升级"。

比如你先配了一个不带 accountId 的,后来又配了一个带 accountId: "main" 的,OpenClaw 会把前者升级为后者,而不是创建两条记录。

这个设计挺聪明,但如果你不知道,可能会困惑"为什么我的配置被改了"。


参考资料: OpenClaw 官方文档