𝗕𝗼𝘂𝗻𝗱𝗲𝗱 𝗥𝗲𝘁𝗿𝗶𝗲𝘀 𝗙𝗼𝗿 𝗔𝗴𝗲𝗻𝘁 𝗧𝗼𝗼𝗹 𝗖𝗮𝗹𝗹𝘀
The worst incident our agent caused was not a wrong answer. It was a loop.
A tool call failed. The agent retried. The retry failed again. The agent kept going. It burned tokens and hit our API hundreds of times in one minute.
The agent did what we told it to do. We told it to retry if a tool fails. We forgot to tell it when to stop.
Retries are good for temporary errors. The problem is that agents cannot tell a temporary error from a permanent one. Without limits, an agent retries a broken call until something kills it.
Traditional code uses retry limits. Agent tool calls moved this decision into the model reasoning. This made the loop invisible and unbounded.
We fixed this by adding two budgets outside the model:
• Per-call cap: A specific tool gets a set number of attempts. If it fails, the agent must try a different path. • Per-session budget: The entire task has a limit on total tool calls. If the agent hits this limit, it stops and asks for help.
The limit itself is not the solution. What happens after the limit is what matters.
If you just stop, the agent gets stuck. Instead, we give the agent a clear message. We tell it the call failed and it must not retry. This turns a loop into a decision. Usually, the agent then picks a new approach.
Since we added this, tool-misuse loops almost disappeared. When they do happen, they escalate cleanly instead of creating huge API bills.
Finding the right limit is hard. A tight limit kills long tasks. A loose limit allows expensive loops. We set our limits based on 95th percentile task lengths.
Do you have a better way to set these budgets? Let me know in the comments.
Optional learning community: https://t.me/GyaanSetuAi