Loop Detection
Deterministic sliding-window detection of repeating agent action patterns.
Agents get stuck. They re-run the same search, re-call the same tool, or alternate between two steps forever. Traditional debuggers can't see these semantic loops. SteerPlane detects them deterministically — no LLM judge, no probabilistic scoring.
How it works
The loop detector maintains a bounded history of recent action names (default window W = 8) and
runs a sliding-window pattern match in O(W²) time — sub-millisecond at any realistic window size.
from steerplane import LoopDetector
detector = LoopDetector(window_size=8, min_repetitions=2)
for action in agent_actions:
result = detector.record_action(action)
if result.loop_detected:
raise RuntimeError(f"Loop: {result.pattern} ×{result.repetitions}")For each candidate pattern length, the detector counts consecutive repetitions anchored at the most recent actions and declares a loop once the repetition threshold is met.
What it catches
| Input (window) | Detected pattern |
|---|---|
[A, A, A, A] | [A] — single-action loop |
[A, B, A, B, A, B] | [A, B] — alternating loop |
[A, B, C, A, B, C] | [A, B, C] — multi-step loop |
[X, A, B, A, B, A, B] | [A, B] — offset / phase-shifted loop |
[A, B, C, D, E, F] | none — no loop |
A confirmed loop always terminates the run immediately — loops are never legitimate, so this is independent of the kill/alert enforcement mode.
Two independent layers
- In-process — the SDK detects loops on action names as your agent runs.
- Network layer — the gateway detects loops on SHA-256 prompt hashes, catching repetition even when the SDK is bypassed.
Together they provide defense-in-depth.