Agent Architecture and Orchestration
Loop Detection — Stack
Loop detection › Stack
Technology landscape as of 2026-10-10. Knowledge cutoff May 2026.
Selection criteria
Every mechanism here trades sensitivity against cost and false positives, and the right choice depends on how expensive a wasted turn is in your workload.
- Cost per check. What the detector adds to every iteration. Anything requiring a model call must prevent more waste than it creates.
- Resistance to superficial variation. Whether the signal survives rephrasing, added timestamps, and reordered arguments, which defeat naive equality.
- Period sensitivity. Whether cycles longer than one turn are detectable, since alternation between two approaches is common and invisible to adjacent comparison.
- Cross-participant visibility. Whether the detector sees activity from all participants in an effort or only one.
- Progress definition hooks. Whether the workload can supply its own notion of advancement rather than relying on a generic one.
- Available responses. What the detector is permitted to do when it fires — annotate, redirect, escalate, or end.
- Retrospective analysis. Whether recorded runs can be mined for cycles that were never caught live, which is how thresholds get calibrated.
Options
| Option | Best for | Watch out for |
|---|---|---|
| Call-signature hashing with a repeat counter | Catching exact reissues cheaply, as a first line of defence | Trivially evaded by any varying field; needs argument normalisation to be worth anything |
| State-delta checks against the shared record | Workloads where genuine progress always changes recorded state | Silent on reasoning-heavy phases that legitimately produce no state change for several turns |
| Visited-state sets with graph cycle detection | Detecting alternation and longer cycles rather than immediate repeats | Requires a canonical state representation; defining what makes two states the same is the real work |
| Embedding similarity over recent turns | Catching semantic repetition that survives rephrasing | Embedding cost per turn, and a threshold that needs recalibration whenever the embedding model changes |
| Output repetition heuristics (n-gram overlap and similar) | Degenerate generation within a single response | Operates on text, not on actions; silent on an agent repeating a tool call with varied prose |
| Out-of-band observer | Expensive judgements that must not slow the loop | Acts late by construction, and becomes a second agent with its own failure modes |
| Trace analysis in an observability platform (Langfuse, LangSmith, Arize Phoenix, OpenTelemetry-based tooling) | Finding cycles retrospectively and calibrating thresholds from real traffic | Post-hoc only; prevents nothing on the run being examined |
| Budget and iteration ceilings as a backstop | Guaranteeing an upper bound on waste regardless of detection quality | Bounds the cost without diagnosing anything; every run that hits the ceiling looks identical |