Infinite Loop
The Anti-Pattern
Agent enters an unbounded execution cycle — retrying failed actions, oscillating between states, or generating plans it never completes.
Why It Happens
Missing termination conditions, no max-iteration limits, or error handling that restarts the same failing step. The agent lacks the ability to recognize it’s stuck. It will keep trying the exact same approach, burning tokens and time, because from its perspective each attempt is a fresh start. Without explicit loop detection, the agent can’t distinguish ‘I should try again’ from ‘I’ve tried this 50 times and it won’t work.’
How to Fix It
Implement max iteration limits at every loop boundary in your agent. Add loop detection that recognizes repeated identical actions. Escalate to human-in-the-loop when the agent detects it’s stuck. Use exponential backoff for retries and add explicit ‘am I making progress?’ checks between iterations. Every agentic loop needs three things: a counter, a progress check, and an escape hatch.
Diagram
Without limits: With limits:
┌──────────┐ ┌──────────┐
│ Action │──▶ Fail ──┐ │ Action │──▶ Fail ──┐
└──────────┘ │ └──────────┘ │
▲ │ ▲ │
└─────────────────┘ │ ┌────────┐ │
(forever) └────│ n < 3? │◀──┘
└────────┘
│ n ≥ 3
▼
[Escalate to
human]Symptoms
- Agent gets stuck in retry loops calling the same tool with the same arguments
- Token spend spikes unexpectedly during a task
- Tasks that should take minutes run for hours without completing
- Same error appears repeatedly in agent logs with no variation in approach
False Positives
- Legitimate retries with exponential backoff and varying approaches
- Iterative refinement loops that are demonstrably converging toward a solution
- Exploration that appears repetitive but is systematically covering new ground
Warning Signs & Consequences
Warning Signs
- Repeated identical tool calls visible in logs
- Escalating latency with no corresponding progress
- Tasks running 10x or more beyond expected duration
- Token consumption graphs showing sustained flat-line activity
Consequences
- Runaway API costs from uncapped iterations
- Stuck tasks blocking downstream pipeline stages
- Resource exhaustion from zombie processes
- Poor user experience — task appears to hang indefinitely
Remediation Steps
- 1Add max iteration limits to every loop and retry mechanism
- 2Implement loop detection that flags repeated identical actions
- 3Add progress checks: ‘Is the state different from N iterations ago?’
- 4Build escalation paths: after N failures, alert a human or try a different strategy
- 5Use exponential backoff for retries so transient failures don’t become infinite loops
Real-World Example
Web Scraping Retry Storm
A web scraping agent hits a 403 Forbidden error on a target site. Without loop detection, it retries the exact same request 200 times — same URL, same headers, same auth — burning $50 in API costs over 2 hours before hitting a global timeout. A 3-retry limit with approach variation (try different headers, try a different URL pattern) would have either succeeded or escalated in under a minute.