Dashboard
0%
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 →

Q18IntermediateScenario

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 traceLikely causeFix
Tool returns empty list / "no results"Model thinks retrying will helpReturn 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-correctReturn actionable errors
Result is truncated without saying soModel keeps searching for the "rest"Say "truncated; showing 10 of 300" and add pagination
Result is correct but model ignores itInstructions unclear about what "done" means, or result buried in noiseClarify success criteria; slim down output
Two tools overlapModel alternates between themMerge 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_iterations or adding "DON'T LOOP" to the prompt. That treats the symptom, not the cause.

Slow is fine. Stopping is the only problem.