群聊
群聊行为:mention gating、群上下文注入、allowlists 与 routing
OpenClaw 的群聊模型是:默认不要在公共房间里"永远在线"。多数通道默认需要 @mention(或匹配 mention patterns)才会触发回复,并且群会话使用独立的 session key,避免污染私信主会话。
这能显著降低:
- 噪声(机器人抢话)
- prompt injection 攻击面(陌生人可把 bot 当作工具)
- 多人对话上下文混淆
Session 隔离
群聊使用独立的 session keys,例如:
- WhatsApp: ''agent:<agentId>:whatsapp:group:<jid>''
- Telegram: ''agent:<agentId>:telegram:group:<chatId>'' (topics append '':topic:<threadId>'')
- Discord: ''agent:<agentId>:discord:channel:<channelId>'' (threads append '':thread:<threadId>'')
- Slack: ''agent:<agentId>:slack:channel:<channelId>''
私信默认折叠到 agent 的 main session(见 ''/concepts/session'')。
Mention gating(触发门禁)
默认策略:只有在群里被提到时,OpenClaw 才会触发 agent run。
触发来源(按通道能力不同):
- 原生 mentions(Telegram/Discord/Slack/WhatsApp 部分场景)
- ''messages.groupChat.mentionPatterns''(全局)
- ''agents.list[].groupChat.mentionPatterns''(按 agent 覆盖)
当群里 mention gating 阻止了一条消息时,OpenClaw 会把它放入 pending history buffer(见下),以便下一次触发时把最近消息作为上下文注入。
你可以按群禁用 requireMention(让该群 always-on):
- Telegram: ''channels.telegram.groups.<chatId>.requireMention=false''
- WhatsApp: ''channels.whatsapp.groups.<jid>.requireMention=false''
- Discord: ''channels.discord.guilds.<guildId>.channels.<channel>.requireMention=false''
- Slack: ''channels.slack.channels.<channel>.requireMention=false''
安全提示:对任何"可能有陌生人"的房间,保持 ''requireMention=true''。
群 allowlists(哪些群会被处理)
不同通道的 allowlist 形态不同,但原则一致:当你开始显式配置 ''groups/guilds/channels'' 时,它通常会变成 allowlist。
- Telegram:
- 不写 ''channels.telegram.groups'':允许所有群(再由 mention gating 决定是否触发)。
- 写了 ''channels.telegram.groups'':只允许列出的群或 ''"*"''。
- WhatsApp:
- ''channels.whatsapp.groups'' 是 group allowlist(用 ''"*"'' 允许所有群)。
- Discord:
- ''channels.discord.guilds'' 是 guild allowlist;如果某个 guild 里定义了 ''channels'',则该 guild 只允许列出的频道。
- Slack:
- ''channels.slack.groupPolicy'' + ''channels.slack.channels'' 控制 channel allowlist。
谁可以在群里触发(groupAllowFrom / users allowlists)
很多通道有两层群访问控制:
- 允许哪些群/频道(上面的 allowlist)
- ''在允许的群里,允许哪些发送者触发''(''groupPolicy'' + ''groupAllowFrom'' 或 per-room ''users'')
例如 Telegram:
{
channels: {
telegram: {
groupPolicy: "allowlist",
groupAllowFrom: ["123456789"],
groups: {
"-1001234567890": { requireMention: true }
}
}
}
}当 ''groupPolicy="allowlist"'' 且没有 ''groupAllowFrom'' 时,默认会阻止(fail-closed)。
群历史上下文注入(pending-only)
当群里消息没有触发回复(没有 mention / 被 allowlist 阻止)时,OpenClaw 会把这些消息暂存为 pending,并在下一次触发时注入到 prompt:
[Chat messages since your last reply - for context] ... [/Chat messages since your last reply - for context] [Current message - respond to this] ... [/Current message - respond to this]
重要特性:
- pending-only:只注入"上次回复之后但未被处理"的消息。
- 不会重复注入已写入 transcript 的消息。
- 当前消息会进行 directive stripping;历史块保持原样。
上限:
- 全局:''messages.groupChat.historyLimit''
- 通道覆盖:''channels.telegram.historyLimit'' / ''channels.slack.historyLimit'' / ''channels.whatsapp.historyLimit'' 等
- 设为 ''0'' 禁用。
Activation(运行时改变群触发模式)
部分通道支持 ''/activation'' 命令(只影响当前会话):
- ''/activation mention'':需要 mention(默认)
- ''/activation always'':对所有消息回复
注意:
- 该命令通常只对授权发送者有效(owner/allowlist)。
多 agent 群路由(bindings)
群消息不会让模型"决定由谁来回复",而是通过 ''bindings'' 做确定性路由。
常用策略:
- "一群一 agent":在 ''bindings'' 中按 ''peer.kind="group"'' + ''peer.id'' 指向某个 agent。
- "按通道账号分配 agent":按 ''accountId'' 匹配。
- "广播 groups":同一条触发消息跑多个 agents(见 ''/broadcast-groups'')。
常见坑
- 你设置了 ''requireMention=false'' 但仍不回复:多半是 ''groupPolicy="allowlist"'' 且没有配置 ''groupAllowFrom'' / 群 allowlist。
- Discord:''requireMention'' 必须写在 ''channels.discord.guilds'' 或具体 channel 下面;顶层 ''channels.discord.requireMention'' 会被忽略。
- Telegram:关闭 BotFather privacy mode 后,需要把 bot 从群移除再重新加入,设置才会生效。