Lv.1 0 XP

Agentic Loop Anti-Patterns — The Mistakes That Break Production

⚡ Exam Critical 10 min +40 XP
💡
THE ANALOGY

A fire alarm that sometimes doesn't go off, sometimes goes off randomly, and sometimes you can't tell if it's real or a drill. An agentic loop with bad termination logic is exactly this — unreliable in ways that are hard to detect and catastrophic when they fail.

⚠️ EXAM TRAP — The Wrong Answer People Choose

Thinking that an iteration cap prevents infinite loops safely. It does prevent infinite loops, but it masks the real error. A loop that hits its cap returned partial results silently — which is often worse than failing loudly.

KEY POINTS
1 Natural language completion detection is always wrong — 'done', 'finished', 'complete' can appear in any context, not just as signals that the task is done.
2 Iteration caps are safety valves, not primary termination logic — hitting the cap should raise an exception, not return partial results.
3 Checking content type instead of stop_reason breaks when Claude returns mixed content (text + tool_use in the same response).
4 Not persisting messages correctly between iterations corrupts the conversation history and causes Claude to repeat work or contradict itself.
5 Missing max_tokens handling is a silent failure mode — the response was cut short but stop_reason is 'max_tokens' not 'end_turn'.