<!-- https://avertgate.com/docs/loop-breaker · Inspectors -->

# Loop breaker

Infinite loops caused by hallucination or attack create cost and damage (OWASP LLM04). The loop breaker looks at the session trajectory and stops them.

## Three loop kinds

| Kind | Definition | Default threshold |
| --- | --- | --- |
| Identical call | The same tool with the same arguments repeated | 3 |
| Consecutive same tool | The same tool called back-to-back | 5 |
| Oscillation | An A → B → A → B → A → B pattern | on |

## Configuration

<!-- policy.yaml -->
```yaml
loop_breaker:
  enabled: true
  max_identical_calls: 3
  max_consecutive_same_tool: 5
  detect_oscillations: true
  action: "BLOCK"          # or "ESCALATE"

tools:
  - name: "search"
    allow: true
    max_identical: 10      # per-tool override
```

Arguments are canonicalised and hashed, so the same call counts as identical even if key order changes.
