BotLoopGuard
public final class BotLoopGuard
io/agentscope/extensions/channel/common/BotLoopGuard.java:38–160Bot 循环守卫,把智能体接入外部消息渠道与企业平台。位于 io.agentscope.extensions.channel.common 包。核心成员包括 allow、isCoolingDown、trackedPeers、evictIdlePeers、BotLoopGuard。
Per-peer sliding-window throttle for inbound channel events. Protects the bot from being looped into runaway interaction with another bot (or a stuck user/script).
Defaults follow OpenClaw: 20 events / 60s window. Once tripped the peer is
placed in a 60s cooldown during which #allow(String) returns false.
Tracked peers do not accumulate forever: a peer with no recorded event for longer than
windowMillis + cooldownMillis is evicted (by then its sliding window is empty and any
cooldown has expired, so the entry carries no information). Sweeping is opportunistic — no
background thread is started: the first #allow(String) call after each
windowMillis + cooldownMillis period sweeps idle peers, so a peer is reclaimed within
roughly one further period after going idle. #evictIdlePeers() offers the same sweep
explicitly. This class is thread-safe.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public BotLoopGuard() | 初始化 `BotLoopGuard` 实例。 Creates a new instance. |
public BotLoopGuard(int maxEventsPerWindow, long windowMillis, long cooldownMillis) | 初始化 `BotLoopGuard` 实例。 Creates a new instance. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public boolean allow(String peerKey) | 设置该参数。 Records an event for `peerKey` and returns `true` when the peer is within budget
(caller may proceed). |
public boolean isCoolingDown(String peerKey) | 判断是否 `isCoolingDown`。 Returns `true` when `peerKey` is currently in cooldown. |
public int trackedPeers() | 返回 `trackedPeers` 结果。 Returns the number of currently tracked peers; mostly for tests/observability. |
public int evictIdlePeers() | 返回 `evictIdlePeers` 结果。 Removes peers that have recorded no event for longer than `windowMillis +
cooldownMillis`; by then the sliding window is empty and any cooldown has expired, so an
evicted peer simply restarts with a fresh window on its next event. |
构造器详情Constructor Detail
BotLoopGuard
public BotLoopGuard()
初始化 BotLoopGuard 实例。
Creates a new instance.
io/agentscope/extensions/channel/common/BotLoopGuard.java:47–49BotLoopGuard
public BotLoopGuard(int maxEventsPerWindow, long windowMillis, long cooldownMillis)
初始化 BotLoopGuard 实例。
Creates a new instance.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
maxEventsPerWindow | int | 最大事件每个 Window(类型 `int`)。The max events per window. |
windowMillis | long | window 毫秒(类型 `long`)。The window millis. |
cooldownMillis | long | cooldown 毫秒(类型 `long`)。The cooldown millis. |
io/agentscope/extensions/channel/common/BotLoopGuard.java:51–58方法详情Method Detail
allow
public boolean allow(String peerKey)
设置该参数。
Records an event for peerKey and returns true when the peer is within budget (caller may proceed).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
peerKey | String | 对端键(类型 `String`)。The peer key. |
booleanio/agentscope/extensions/channel/common/BotLoopGuard.java:65–90isCoolingDown
public boolean isCoolingDown(String peerKey)
判断是否 isCoolingDown。
Returns true when peerKey is currently in cooldown.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
peerKey | String | 对端键(类型 `String`)。The peer key. |
booleanio/agentscope/extensions/channel/common/BotLoopGuard.java:105–113trackedPeers
public int trackedPeers()
返回 trackedPeers 结果。
Returns the number of currently tracked peers; mostly for tests/observability.
intio/agentscope/extensions/channel/common/BotLoopGuard.java:116–118evictIdlePeers
public int evictIdlePeers()
返回 evictIdlePeers 结果。
Removes peers that have recorded no event for longer than windowMillis + cooldownMillis; by then the sliding window is empty and any cooldown has expired, so an evicted peer simply restarts with a fresh window on its next event.
intio/agentscope/extensions/channel/common/BotLoopGuard.java:129–131