By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
| Kind | Example | What the agent should do |
|---|---|---|
| Call error | Unknown tool, bad argument | Read the error, correct the call, retry once |
| Tool error | Rate limited, timeout, upstream 500 | Back off and retry, or choose another tool |
| Bad result | Empty list, irrelevant documents | Change the query, not the tool |
The distinction matters because the correct response is different each time. An agent that retries a bad-argument call three times wastes money confirming it is wrong.
def call_tool(name, args, attempts=2):
for attempt in range(attempts):
try:
return run_tool(name, args)
except Retryable as exc: # 429, 5xx, timeout
if attempt == attempts - 1:
raise
time.sleep(0.5 * (2 ** attempt))
except NotRetryable as exc: # 400, 403, bad args
raise ToolError(str(exc)) # back to the model as feedbackThe single most expensive failure mode in agent systems is a loop: the agent calls the same tool with the same arguments, gets the same unhelpful result, and tries again. Guard it in the executor, not in the prompt:
Key takeaways
Separate call errors, tool errors and bad results — each needs a different response.
Retry only transport failures, with backoff; return other errors as feedback.
Cap steps, identical calls, tokens and cost in the executor.
Partial answers with a reason beat infinite loops.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.