























@@ -0,0 +1,131 @@
1+---
2+summary: "Bot-to-bot loop protection defaults and channel overrides"
3+read_when:
4+ - Configuring bot-authored channel messages
5+ - Tuning bot-to-bot loop protection
6+title: "Bot loop protection"
7+sidebarTitle: "Bot loop protection"
8+---
9+10+# Bot loop protection
11+12+OpenClaw can accept messages written by other bots on channels that support `allowBots`.
13+When that path is enabled, pair loop protection prevents two bot identities from
14+replying to each other indefinitely.
15+16+The guard is enforced by the core channel-turn kernel. Each supporting channel
17+maps its own inbound event into generic facts: account or scope, conversation id,
18+sender bot id, and receiver bot id. Core then tracks the participant pair in both
19+directions, applies a sliding-window budget, and suppresses the pair during a
20+cooldown after the budget is exceeded.
21+22+## Defaults
23+24+Pair loop protection is active when a channel lets bot-authored messages reach
25+dispatch. Built-in defaults are:
26+27+- `maxEventsPerWindow: 20` - a bot pair can exchange 20 events within the window
28+- `windowSeconds: 60` - sliding window length
29+- `cooldownSeconds: 60` - suppression time after the pair exceeds the budget
30+31+The guard does not affect normal human-authored messages, single-bot deployments,
32+self-message filtering, or one-shot bot replies that stay under the budget.
33+34+## Configure shared defaults
35+36+Set `channels.defaults.botLoopProtection` once to give every supporting channel
37+the same baseline. Channel and account overrides can still tune individual
38+surfaces.
39+40+```json5
41+{
42+ channels: {
43+ defaults: {
44+ botLoopProtection: {
45+ maxEventsPerWindow: 20,
46+ windowSeconds: 60,
47+ cooldownSeconds: 60,
48+ },
49+ },
50+ },
51+}
52+```
53+54+Set `enabled: false` only when your channel policy intentionally allows
55+bot-to-bot conversations without automatic suppression.
56+57+## Override per channel or account
58+59+Supporting channels layer their own config over the shared default. Precedence is:
60+61+- `channels.<channel>.<room-or-space>.botLoopProtection`, when the channel supports per-conversation overrides
62+- `channels.<channel>.accounts.<account>.botLoopProtection`, when the channel supports accounts
63+- `channels.<channel>.botLoopProtection`, when the channel supports top-level defaults
64+- `channels.defaults.botLoopProtection`
65+- built-in defaults
66+67+```json5
68+{
69+ channels: {
70+ defaults: {
71+ botLoopProtection: {
72+ maxEventsPerWindow: 20,
73+ },
74+ },
75+ discord: {
76+ botLoopProtection: {
77+ maxEventsPerWindow: 8,
78+ },
79+ accounts: {
80+ molty: {
81+ allowBots: "mentions",
82+ botLoopProtection: {
83+ maxEventsPerWindow: 5,
84+ cooldownSeconds: 90,
85+ },
86+ },
87+ },
88+ },
89+ slack: {
90+ allowBots: "mentions",
91+ botLoopProtection: {
92+ maxEventsPerWindow: 8,
93+ },
94+ },
95+ matrix: {
96+ allowBots: "mentions",
97+ groups: {
98+"!roomid:example.org": {
99+ botLoopProtection: {
100+ maxEventsPerWindow: 5,
101+ },
102+ },
103+ },
104+ },
105+ googlechat: {
106+ allowBots: true,
107+ groups: {
108+"spaces/AAAA": {
109+ botLoopProtection: {
110+ maxEventsPerWindow: 5,
111+ },
112+ },
113+ },
114+ },
115+ },
116+}
117+```
118+119+## Channel support
120+121+- Discord: native `author.bot` facts, keyed by Discord account, channel, and bot pair.
122+- Slack: native `bot_id` facts for accepted bot-authored messages, keyed by Slack account, channel, and bot pair.
123+- Matrix: configured Matrix bot accounts, keyed by Matrix account, room, and configured bot pair.
124+- Google Chat: native `sender.type=BOT` facts for accepted bot-authored messages, keyed by account, space, and bot pair.
125+126+Channels that do not expose a reliable inbound bot identity keep using their
127+normal self-message and access-policy filters. They should not opt into this
128+guard until they can identify both participants in the bot pair.
129+130+See [SDK runtime](/plugins/sdk-runtime#reusable-runtime-utilities) for plugin
131+implementation details.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。