Types of Loops
| Loop Type | Pattern | Detection |
|---|---|---|
| Repeated Output | Same response 3+ times | Output hash matching |
| No State Change | Agent runs but nothing changes | State diff tracking |
| Action Cycle | A → B → C → A → B → C | Action sequence matching |
Basic Usage
With Workflow
Loop Detector API
For more control, use the LoopDetector directly:Handling Loop Errors
Loop Breaking Strategies
Detecting Subtle Loops
Sometimes loops aren’t exact repeats:Best Practices
Always enable for autonomous agents
Always enable for autonomous agents
Agents running without human oversight will get stuck. It’s a matter of when, not if.
Set appropriate thresholds
Set appropriate thresholds
Too low = false positives. Too high = loops run too long.
3 repeated outputs is a good default.
Monitor loop frequency
Monitor loop frequency
If loops are common, your prompts might need work.
Use state change detection
Use state change detection
Repeated outputs alone isn’t enough. An agent might output different text but make no progress.