Picture it. You hand an agent a job you'd rather not do yourself: get the failing test suite green. You go to bed. In the morning the job is still going. It has tried the same fix in a few slightly different shapes, undone some of them, and paid for every round.
Nothing crashed. Nothing told it when to stop. That's the whole problem, and no amount of prompt polish fixes it. An agent job needs a stop rule: how many attempts, how much spend, what counts as blocked, and what it hands back to you when it quits.
Failure turns into repetition
The vendors tell you to set limits. Anthropic's guide to building agents notes that it's common to include stopping conditions, such as a maximum number of iterations, to keep control of an agent. It also warns that their autonomy means higher costs and the potential for compounding errors. OpenAI's practical guide names failure thresholds as a reason to bring a human in: set limits on retries or actions, and escalate when the agent goes past them.
I go one step further: an agent task isn't ready to run until it says when to give up. Without that, failure tends to turn into repetition.
1. Attempts: count them, and pick the number yourself
Google's SRE book, in a chapter on cascading failures in services rather than AI, says to limit retries per request and never retry indefinitely. Treat that as an analogy, but a close one: an agent stuck on a bug is a retry loop with better manners.
Pick the number yourself. In the example below it's two tries per approach, and a reshaped version of a fix counts as the same approach. Add a total as well, a cap on approaches in all, or the agent can drift from shape to shape all night, which is exactly the morning above. Agent tools can cap turns too; set that cap yourself rather than assume one is there.
2. Budget: a tripwire, not a wall
The same SRE chapter suggests a server-wide retry budget: once it's exceeded, don't retry, fail the request. I'd borrow the idea as a spend figure per job: when it's gone, the job ends. Some tools let you set it directly. Set the figure below what you are willing to lose. In the Claude Agent SDK, for one, spend is checked after a response arrives, so it can pass the cap.
The chapter has a second warning worth borrowing: retries at several levels of a system amplify each other. If your agent retries a step and the tool underneath retries too, you're paying for both.
3. Blocked: name the walls before it hits them
Some failures will never succeed on another try. The SRE book says not to retry permanent errors or malformed requests for exactly that reason. In agent terms: a missing credential, a file that isn't there, a spec that contradicts itself. Another attempt is just a more expensive way to learn the same thing.
Then there are the steps where trying again is the danger. Amazon's article on retries points out that a timeout doesn't mean the side effects didn't happen, and that calls which change things generally aren't safe to retry unless they're idempotent. OpenAI's guide says irreversible or high-stakes actions should trigger human oversight until you trust the agent more. Its examples include cancelling orders and making payments. So I'd mark these as blocked, not merely difficult:
- Missing access: a key, a permission, a file it can't read. Stop and say which.
- A decision I haven't delegated: two valid fixes with different trade-offs. Stop and show both.
- Anything irreversible: a payment, a deletion, a push to something live. Stop before, never after.
4. The handback: what it tells you when it quits
Anthropic's guide says agents can pause for human feedback at checkpoints or when they hit blockers. That's the behaviour you want. In the Claude Agent SDK, a run that hits a turn or budget limit comes back with which limit fired, cost and turn count, and no final result text. Useful numbers, but not a written account of what is blocked. The cap only stops the run; the task has to ask for the report.
Martin Fowler, describing the circuit breaker pattern for services, says every change in the breaker's state should be logged and that you'll usually want an alert when it trips. An agent quitting is the breaker tripping. So the report belongs in the task, written as plainly as the job itself:
Two plain facts about that block. It is instructions: the agent reads it, but nothing in a prompt enforces it. And the agent may not be able to track its own spend, so the money limit rests on the tool's cap. The written rule leans on what the agent can count: approaches tried, blockers hit. The intent is that one of those ends the job first, with a report. If the cap fires first, there may be no report at all, only the hard stop and its numbers.
The changed field matters most to me. If the agent touched something before it quit, I want to know before I start it again, not after.
Next time an agent job loops, resist the urge to rewrite the prompt first. Ask a smaller question: did it know when to give up, and did it know what to tell me? Write the four parts: attempts, budget, blocked, handback. Then tune the prompt.
Building with AI?Let's talk about your appBook a free intro call


