AS AgentScopeAPI 手册 / API Reference

BotLoopGuard

public final class BotLoopGuard
源码Source io/agentscope/extensions/channel/common/BotLoopGuard.java:38–160

Bot 循环守卫,把智能体接入外部消息渠道与企业平台。位于 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.

源码Source io/agentscope/extensions/channel/common/BotLoopGuard.java:47–49

BotLoopGuard

public BotLoopGuard(int maxEventsPerWindow, long windowMillis, long cooldownMillis)

初始化 BotLoopGuard 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
maxEventsPerWindowint最大事件每个 Window(类型 `int`)。The max events per window.
windowMillislongwindow 毫秒(类型 `long`)。The window millis.
cooldownMillislongcooldown 毫秒(类型 `long`)。The cooldown millis.
源码Source 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).

参数Parameters
名称Name类型Type说明Description
peerKeyString对端键(类型 `String`)。The peer key.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/extensions/channel/common/BotLoopGuard.java:65–90

isCoolingDown

public boolean isCoolingDown(String peerKey)

判断是否 isCoolingDown。

Returns true when peerKey is currently in cooldown.

参数Parameters
名称Name类型Type说明Description
peerKeyString对端键(类型 `String`)。The peer key.
返回Returns boolean
返回布尔值,表示判断结果。Returns a boolean result.
源码Source io/agentscope/extensions/channel/common/BotLoopGuard.java:105–113

trackedPeers

public int trackedPeers()

返回 trackedPeers 结果。

Returns the number of currently tracked peers; mostly for tests/observability.

返回Returns int
返回数值结果。Returns a numeric result.
源码Source io/agentscope/extensions/channel/common/BotLoopGuard.java:116–118

evictIdlePeers

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.

返回Returns int
返回数值结果。the number of peers removed
源码Source io/agentscope/extensions/channel/common/BotLoopGuard.java:129–131
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.