Skip to main content

Module loop_detector

Module loop_detector 

Source
Expand description

Loop detection for agent outputs — prevents repetitive/stuck agents. Loop detection for ARES agents.

Detects when an agent is producing repetitive outputs and intervenes to break the loop. Uses a sliding window of recent outputs with similarity hashing, optional fuzzy matching, and iteration limits.

Structs§

LoopConfig
Configuration for loop detection and iteration limits.
LoopDetection
Pure detection result from detect_loop.
LoopDetector
Tracks agent outputs and detects repetitive loops.
LoopState
Runtime state for loop detection and iteration tracking.

Enums§

LoopAction
Actions to take when a loop is detected.
LoopMatchKind
How a repetitive output was matched.
LoopStatus
Result of checking an output for loops.

Functions§

count_fuzzy_repetitions
Count signatures in signatures that fuzzy-match current.
count_repetitions
Count how many entries in hashes equal hash.
detect_loop
Detect a repetitive output against recent window state (does not mutate state).
loop_signature
Canonical normalized signature (whitespace-stripped, lowercased, capped).
should_halt
Whether the agent should halt due to iteration limits or consecutive failures.
should_halt_on_max_iterations
Returns true when LoopConfig::halt_on_max is set and iteration limits are reached.
similarity_hash
Hash normalized output content for exact duplicate detection.

Type Aliases§

LoopDetectorConfig
Backward-compatible alias for LoopConfig.