CHAPTER 02 · The Agent Loop Pattern · 8 / 8
Common failure modes to design against
- Runaway iteration → the hard cap.
- Stuck loops (same call repeated) → repetition detection.
- Missing tool results → guarantee one result per call.
- Malformed tool arguments → parse defensively, default to empty, return a useful error the model can recover from.
- Tool exceptions → catch them and feed the error back as a tool result, so the model can adapt rather than the whole turn crashing.
The theme: the loop is where the model's unreliability meets your code, so the loop is where you must be most defensive.