How can you stop an AI agent from repeating the broken API call ten times?
Last month, an agent we built to sync customer tickets ran into a loop when a third‑party webhook timed out. The error message seemed generic, so the agent thought it was a glitch. The agent then spent forty dollars worth of tokens in twelve minutes.
Many builders give agents tools, but few set strict limits on how an agent behaves when a tool fails. When an agent has no exit rules, the agent treats every error like a puzzle it must keep brute‑forcing until it succeeds.
We solved this by adding a simple two‑strike rule in the system prompt and tool wrapper. If the same tool returns the error code twice in one session, the wrapper blocks any further calls to that endpoint and forces the agent to summarize the failure for a human.
Within a week, our token waste fell by sixty percent and support tickets stopped flooding with duplicate partial entries. Setting clear failure boundaries matters as much as writing good instructions for success. How do you handle retry limits. Fallback logic in your agent workflows?
p/meridian-16
p/google-cloud-platform
p/producthunt
p/reso
p/kodlo
p/zush
p/neoagent
p/runevr
p/beamfy
p/expert-chase-deleted-1107920
p/netclicker
p/faraday-4
p/gatrends
p/kanbanq
p/truedraft-cad
p/findergit
p/thebold
p/murror
p/orbit-app-blocker
p/cleared-quit-nicotine
Replies
What helped us most was making the wrapper sort the error before deciding anything, because "busy" and "refused" need opposite answers.
Our song pipeline calls a music model that fails in both ways. When it says the quota is exhausted, the client retries after 10, 25 and 45 seconds, and if it is still busy the song goes back to a queue with growing waits, from 3 minutes up to 30, about two and a half hours in total. A scheduled job picks up at most 3 due songs every 2 minutes, so a burst can't turn into a stampede. Only the ninth busy answer fails the song, and the user's credits stay on hold meanwhile.
When the model refuses the prompt, repeating the same call is pointless. A cheap model judges the refusal first: anything genuinely prohibited is never retried, everything else gets exactly one more try, rephrased or on a second music engine.
So my rule is a retry budget per kind of error rather than per endpoint. Errors about time earn patience, errors about content get one more try at most.