1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
51 small wins to finish your pathNext question →
Your agent keeps calling the same tool with the same arguments in a loop. How do you debug and fix it?
30-second answerSay your answer out loud first, then reveal.
Step 1 — Diagnose from traces
Look at what the tool returned. Common root causes:
| Symptom in trace | Likely cause | Fix |
|---|---|---|
| Tool returns empty list / "no results" | Model thinks retrying will help | Return guidance: "No orders found for this email. Ask the user to confirm the email." |
| Tool returns cryptic error (500, stack trace) | Model can't self-correct | Return actionable errors |
| Result is truncated without saying so | Model keeps searching for the "rest" | Say "truncated; showing 10 of 300" and add pagination |
| Result is correct but model ignores it | Instructions unclear about what "done" means, or result buried in noise | Clarify success criteria; slim down output |
| Two tools overlap | Model alternates between them | Merge or clarify descriptions |
Step 2 — Fix the root cause
Fix it in the tool design or prompt (see the table).
Step 3 — Add safety nets in code
- Detect repetition: hash
(tool_name, args); if it is seen N times (e.g. 3), don't execute. Inject a message: "You've already called X with these arguments and got Y. Try a different approach or report what you found." - Max iterations, and a budget per run.
- Escalate to a human or return a partial answer when stuck.
Step 4 — Prevent regressions
Add this case to your eval set and track a "repeated tool call rate" metric.
Common mistakes
- Only increasing
max_iterationsor adding "DON'T LOOP" to the prompt. That treats the symptom, not the cause.
Related
Slow is fine. Stopping is the only problem.