Dear Past Me: Three Agent Loop Mistakes That Cost a Day
Description and use
An LLM-powered review agent can waste a day due to unbounded tool calls, missing file handling, and partial JSON parsing. Implementing a loop budget, detailed missing-file responses, and strict JSON validation stops the cycle and saves time.
Problem
An LLM-powered review agent can waste a day due to unbounded tool calls, missing file handling, and partial JSON parsing.
Outcome
The agent loop now stops after a defined number of steps or tool calls, avoids retrying missing files, and only processes complete JSON tool calls, saving time and preventing infinite loops.
Workflow
- 1. Set a hard budget: cap maxSteps and maxToolCalls. 2. Track and abort on repeated identical tool calls. 3. Log each step as a structured event. 4. Return detailed missing file results with path, cwd, and retry hint. 5. Buffer tokens until stream signals done before parsing. 6. Validate tool call payloads against a schema and allowed set. 7. Reject or abort on schema violations or partial JSON.
Evidence
Set a hard budget before the first call.
Return the path, the cwd, and a stop hint.
- Record date: 2026-09-09T18:01:40.860Z