Loop Detection in Long-Running Agents

Agents repeat. Loops eat budget and produce nothing. The cheap detector that catches 90% of loops and the expensive one that catches the rest.

Cheap detection: state hashing

Hashing the agent’s recent state catches almost every loop in practice and costs nothing per step. It is the first defence to ship.

Expensive detection: semantic similarity

Hashing misses loops where the agent paraphrases the same action with slightly different arguments. Semantic similarity catches these at a per-step embedding cost.

What to do when a loop is detected

Detection without action is decoration. Three responses cover the operational path; resist any logic that tries to recover the loop in flight.

Loop guards in budget terms

Loops are budget exhaustion under another name. Treating them that way unifies the enforcement story.

Eval cases for loop behaviour

The eval suite covers loop behaviour the same way it covers any other failure mode. Without explicit cases, regressions land silently.