Before giving it another tool, give it a way to recognize that nothing is changing.
You leave an agent working on a small task, come back, and find a beautifully busy transcript. It checked something, reconsidered something, tried another approach, and somehow arrived at the same error again.
Meanwhile, you still need the task finished.
I love the promise of delegating the tedious parts of engineering. But the part that makes me trust a system is what happens when the easy path disappears. Can it explain what blocked it, or does it just keep spending your afternoon?
Honestly, an agent that knows when to stop can be more useful than one that always finds something else to do.
Let’s make that practical with a tiny debugging task, then turn it into a stopping policy you can use in a project or explain in an interview.
Watch what changes between attempts
Imagine a coding agent has been asked to investigate a failed build in a private repository. This is an illustrative example, and the repository service explicitly reports that the agent lacks read permission.
Its first request returns a 403. It rewrites the request and gets another 403. Then it delegates the investigation to a second agent using the same credentials, which gets the same response.
Three attempts have happened, but the missing permission is still missing.
This is the question I want next to the run log whenever an agent retries. What has changed that makes the next attempt worth making?
A temporary service outage may clear. A corrected argument may fix an invalid request. Newly granted access may unblock a repository read. Rewording the task does not, by itself, change any of those conditions.
Don’t turn that into a blanket rule that every 403 means the same thing. Read the tool’s error details and contract. In our example, the cause is already known, so repeatedly sending the same request is a poor next move.
The useful response is to preserve the evidence and ask for read access, or ask the user to provide the relevant build log. The agent has reached a dependency it cannot resolve with its current tools.
If you want a concrete place to practice this, use this agent harness design exercise and sketch just the stopping policy first. Decide what the system should do after a temporary failure, a missing permission, and an uncertain write. That small slice is enough to make the design interesting.
Decide what finished means before the loop starts
Keep trying until it works sounds encouraging, but it leaves an enormous amount undefined.
For our debugging task, an acceptable outcome might be a diagnosis supported by the build log and a reproducible failing check. If the scope also includes a patch, completion needs evidence that the relevant check passes, plus a clear account of what changed.
An upbeat final paragraph cannot substitute for that evidence. Neither can a test run that never actually started.
Write the completion condition beside the task, then make the surrounding application check whatever can be checked reliably. For this example, that means recording whether the log was retrieved, which failure was observed, and whether the claimed verification ran.
Some judgments will still need a reviewer. The important part is keeping verified completion separate from an agent’s belief that it has finished.
Anthropic’s Building effective agents makes the underlying point clearly. Agents need feedback from the environment, and their execution can include stopping conditions and human checkpoints. The article is older guidance, rather than a description of every current SDK, but that design principle remains useful here.
Give different failures different exits
I prefer a small set of explicit outcomes over a single success or failure flag, because the person receiving the result needs to know what to do next.
For this project, the outcomes can be completed, retryable, blocked, uncertain, and budget exhausted. The labels are a design proposal, so change them to fit your application.
A retryable failure means another attempt has a plausible reason to work and repeating the operation is safe. A blocked run needs an input or permission. An uncertain run means an action may have happened, but the system does not yet know its outcome.
That last distinction deserves a little extra attention.
Suppose an agent creates a support ticket and the request times out. Repeating the action might create a second ticket, because a timeout does not prove the first request failed before saving.
Before retrying, the harness needs a way to reconcile the outcome, perhaps through an operation identifier or the tool’s documented idempotency support. If the tool offers neither, uncertainty may require a human decision instead of another write.
For a temporary failure on a safe read, a bounded retry with backoff may be sensible. For missing authorization, asking for the missing access is sensible. For an uncertain write, finding out what already happened comes first.
Those are different engineering decisions, even if all three initially look like an error message.
Put the budget outside the agent’s enthusiasm
Even a reasonable retry policy needs a limit. Otherwise, each local decision can look defensible while the overall run becomes expensive and unhelpful.
For a small sandbox exercise, try an illustrative ceiling of eight tool calls and two minutes. Pick a spend limit appropriate to your model and tools as well. These are practice settings, not universal recommendations or evidence of the best configuration.
Enforce the limits in the application that dispatches work. A prompt asking the model to be economical is useful guidance, but it is not a hard boundary.
Check the remaining budget before launching another operation, give calls deadlines, and account for work already in flight. If several workers run concurrently, reserve their capacity against the same run budget so each worker cannot spend the entire allowance independently.
A second agent does not magically make the first agent’s missing permission disappear. It also should not reset the clock or create a fresh spending allowance.
There is another important wrinkle here. Canceling a run does not necessarily undo an external action that already started. Preserve operation identifiers and any unresolved outcomes when the budget runs out, so the next person can reconcile them safely.
Budget exhaustion should produce an honest partial result. Please don’t let it quietly become a success message because the loop ended.
Make a stopped run useful to the next person
Nobody wants a handoff that just says the task failed. That transfers the entire investigation back to the user.
A better handoff explains what is known and asks for the smallest useful next decision. For our repository example, it can fit on one short card.
Include the task, the decisive tool result, the blocker, any changes already made, and the next action that could actually unblock progress. Keep secrets and unnecessary private content out of the trace.
Notice how different this feels from a long transcript of repeated attempts. The user can grant access or share a log and resume from a known point, instead of rereading the entire conversation to discover the problem.
Before resuming, check that the relevant state still matches the saved checkpoint. A repository, ticket or permission may have changed while the run was paused.
Test the exit before adding another tool
You can try this without building a whole agent platform. Start with a simulated tool and deliberately give the agent a few awkward outcomes.
- Return a temporary error once, then a valid result. Check that the safe retry stays within its budget and the final claim matches the returned evidence.
- Return an explicit missing-permission error. Check that the run asks for the missing dependency instead of cycling through equivalent calls.
- Simulate a write that succeeds but loses its response. Check that the next step reconciles the operation rather than blindly creating a duplicate.
- Exhaust the budget before completion. Check that the handoff names unfinished work and any action whose outcome remains unknown.
Repeat the scenarios, because one successful run is not enough to establish reliable behavior. Record task completion alongside unnecessary retries, duplicate side effects, cost, and whether the handoff gave a person enough information to continue.
Avoid treating fewer calls as the only goal. An agent that stops immediately can be cheap and completely useless. What matters is whether each additional attempt has a defensible purpose, and whether the system recognizes when that purpose has disappeared.
That is the habit I want to carry into my own designs. Before adding another model, tool or worker, make the current loop explain why its next step is worth taking.
Your agent does not need to look busy for you to trust it. It needs to make progress, recognize a real blocker, and leave you somewhere better than where it started.
~ Emily





Top comments (0)