Founders

How to Write a Stop Message an Agent Can Act On at the Cap

Antonio Evans10 min read

An agent chain of completed steps ends at a stop sign, and an arrow labelled handoff leads to a person reading a folder labelled work so far with a sticky note reading needs: API key.
Key points

Key points

  1. 1A useful cap does not just stop the agent, it converts the remaining state into a handoff a person can act on without reading the transcript.
  2. 2The boundary protocol has three phases: finish the in-flight step within a bounded extra allowance, persist partial work to a named artifact, and emit one blocking ask.
  3. 3Budget stops must be decided before the next model call, not discovered afterwards in a dashboard, or the agent will spend past the line.
  4. 4The stop message should be a small fixed schema with a size limit, because context accumulation is what makes agent runs expensive and handoffs unreadable.

Why the cap itself is not the hard part

Most teams can set a number: 40 steps, 20 minutes, 15 dollars. The number is the easy half. The hard half is what the loop does in the two seconds after the number is reached.

There is a well-documented reason to care. Spend that arrives through an agent loop is not linear in the way a single API call is, because most chat and completion APIs are stateless and bill for the whole conversation on every call. A naive N-step loop re-sends prior context each turn, so billed input tokens grow quadratically, and a 20-step loop can consume over ten times what a per-step estimate suggests per this analysis of agent loop token costs. One write-up of multi-turn tool use puts the same point more bluntly: a ten-step run with a 9,000-token starting context reached roughly 472,000 tokens across all calls, about 43 times the single-call baseline in this token economy breakdown.

That math has a direct design consequence. Because the cost of a step rises as the run goes on, the last few steps before a cap are the most expensive ones you will ever buy. An agent that spends them on an unbounded retry, or on a polite essay explaining that it has run out of budget, wastes the most expensive tokens in the session. The stop path has to be cheap, short and deterministic.

The second consequence is that a cap enforced only at the provider account level almost never fires in time. Account-level caps are set at monthly ceilings and typically trip days after the damage; dashboards and Slack alerts are records, not controls, and an agent inside a tool-calling loop does not consult either before calling the endpoint again as argued in this budget enforcement write-up. A run-scoped decision, made before execution, is what actually stops the next call per the reserve, execute, commit pattern described here.

So the stop message is not a courtesy notification bolted onto the end of a run. It is the output of the only code path in the system that is guaranteed to execute at the boundary.

The three-phase boundary protocol

Treat the cap as a boundary event with three phases, executed in order, each with its own allowance.

Phase 1: finish the step in flight. An agent partway through writing a file, applying a migration or sending a request is in a dangerous state. Cutting power mid-step is how you get half-written artifacts and orphaned side effects. Give the boundary a small overshoot allowance, expressed in the same unit as the cap, and spend it only to reach a safe point. A step-limit cap might grant one extra model call. A budget cap might grant a fixed reserve held back from the main loop precisely for this purpose.

Phase 2: persist partial work. When the agent reaches a safe point, it writes what it has to a named location: a file path, a branch, a draft record, a comment on the ticket. Phase 2 is where most implementations fail, because the model is asked to "summarize progress" in prose and the summary never reaches durable storage. The unit economics literature is clear that retrieval, orchestration, evaluation and labor all sit outside the token line and all cost real money per this allocation guide. A partial artifact that a human can pick up is the only part of the run that survives the cap with value intact.

Phase 3: tell a person what it needs. The final message names the one blocking input. Not five. One, plus a list of what is already done and where the partial work lives.

The ordering matters because each phase depends on the previous one. You cannot write a truthful handoff about partial work if the work was never persisted, and you cannot persist cleanly if you are interrupted mid-write.

PhaseBudget unitWhat it may spendOutputFailure if skipped
Finish stepOne extra call, or a reserved slice of budgetOnly enough to reach a safe point (close file, finish write, stop tool call)Consistent artifact on diskCorrupt or half-written outputs
Hand backA fixed small token ceiling, for example the handoff schema onlyOne write to the handoff location, no tool explorationPath plus status of each artifactWork exists only in a transcript nobody will read
Tell a personThe remainder of the handoff ceilingNothing beyond composing the messageOne blocking ask, one ownerHuman restarts from scratch

A practical rule of thumb: reserve the boundary allowance before the loop starts, not after. If the cap is 100 units, run the main loop to 95 and hold 5 for the boundary. An agent that discovers it has zero left cannot finish a write or compose a handoff, so it does the worst thing available: it emits a long apology, which is itself a paid generation.

Design the stop message as a schema, not a paragraph

The stop message should be machine-checkable, because a human reviewer under time pressure will read the first line and then look for a file. Keep the schema small and fixed. Four fields do most of the work: what finished, what is partial with its exact path, what the agent was trying to do next, and the single input a person must supply.

{
  "status": "capped",
  "cap": {"type": "budget", "limit": 15.00, "spent": 14.92, "unit": "usd"},
  "finished": ["migrations/004_add_index.sql applied to staging"],
  "partial": [{"path": "reports/q3-draft.md", "state": "sections 1-4 complete, 5-7 missing"}],
  "next_intended_step": "fetch Q3 revenue from warehouse view finance.q3_rev",
  "blocking_input": "warehouse access for the reporting service account",
  "owner": "data-platform-oncall"
}

Three properties make this usable.

It is actionable without the transcript. A reviewer reads the blocking input, grants or denies it, and re-runs with a larger cap. They never need to scroll through 40 tool calls to reconstruct intent. The handoff-protocol literature makes the same point about agent-to-agent work: pass conclusions and unresolved items, not raw exploration logs, because the receiver cannot parse your noise efficiently per this handoff pattern reference.

It states the cap honestly. Recording the type, the limit and the spend at the moment of stopping turns the message into an audit record. That matters for the same reason signed receipts matter in budget enforcement systems, where a refusal over budget is itself an event worth proving as described in this cost control overview.

It separates finished from partial. Ambiguity here is expensive, because the next person will either redo completed work or trust incomplete work. A structured handoff format with explicit fields for what was done, what was found, what needs attention and what is unresolved is more reliable than prose notes, since field extraction is deterministic per this handoff protocol guide.

One caveat worth designing around: structured fields imply certainty. An agent that fills a partial array with tidy JSON can hide that its conclusions were tentative. Where the work is genuinely uncertain, put the hedge inside the field value rather than dropping it for the sake of a clean schema.

Choosing the cap type changes the stop message

Step, time and budget caps fail differently, and the stop message should reflect that. A step cap is predictable but blind to cost. A time cap protects latency for interactive users but can fire mid-tool-call. A budget cap protects margin but is the hardest to enforce because it needs a pre-execution decision.

Cap typeBest fitTypical overshoot allowanceMost common bad stop messageWhat to require instead
Step limitRepetitive tool loops with predictable step costOne extra model call to close the step"I have reached my step limit" with no artifact pathName the last completed step and the current step number
Time limitInteractive sessions and CI jobs with a deadlineEnough wall clock for the pending write to completeGeneric timeout text with no stateConfirm the pending write landed, then hand off
Budget limitLong autonomous runs where cost is the real riskA reserve held back before the loop startsA long apology that costs money to generateState limit, spent amount and the exact next paid action

If you run more than one cap, decide precedence up front. A common and defensible order is: budget first, because it is the only one that can stop the next call; then time, because users and pipelines have deadlines; then steps, which mostly catch loops the other two would eventually catch anyway.

Budget caps also need a scope decision. A single monthly ceiling will not stop a runaway loop inside one agent, or a single tenant consuming a shared pool per this token budget guide. Set per-run limits for the loop, per-user or per-tenant limits for fairness, and per-feature limits so a single expensive workflow cannot eat the allowance for everything else. That layering is also what lets you attribute spend to the team that caused it rather than to the platform that happened to host it per this FinOps treatment of AI unit economics.

A worked example makes the arithmetic concrete. Suppose a summarization task averages 23 calls at about 2.63 dollars when it behaves using the cost profile in this budget control article, and you set a 5 dollar run cap. A well-behaved run finishes with 2.37 dollars of headroom. A looping run hits the cap and stops. The difference between a good and bad stop path is whether that 5 dollar run returns four section summaries on disk plus one blocked question, or returns a paragraph saying it ran out of money.

Getting the allowance right without guessing

The boundary allowance should be derived from measured behaviour, not intuition. Instrument first, enforce second, optimize third, and log input tokens, output tokens, model, feature, user or tenant, environment, request status, retry count and estimated cost per request per this guide to setting token budgets.

Three measurements set the numbers.

The distribution of steps per successful task gives you the step cap: take a high percentile of successful runs, not the mean, so ordinary variation does not trip the boundary. Retry behaviour is the reason to aim high, because retries are a large and under-budgeted cost driver; in one simulation, a five times retry multiplier pushed cost per successful task from 5.73 dollars to 28.65 dollars per this retry cost analysis. A cap that fires on ordinary retries will be tuned away by the first engineer who gets paged.

The cost of a single step at the tail of a run gives you the phase 1 allowance. Because context grows with each turn, a late step can cost several times an early one. Measured per-call consumption in a documented five-step run grew from 888 tokens to 18,900 per this agent cost analysis. Size the overshoot for the step you will actually be on, not the average.

The size of your handoff schema gives you the phase 2 and 3 allowance. Keep it to a few hundred tokens and it will never be the reason a run overshoots.

Two levers reduce the allowance you need. Prompt caching cuts the cost of repeated context, with published savings on cacheable content of up to 90 percent per this token efficiency survey. And explicit terminal states in tool responses stop the model retrying an ambiguous outcome; one team cut per-task tool calls from 14 to 2 by adding clear success and failure signals per the same multi-turn cost analysis. Fewer ambiguous outcomes means fewer runs that reach the cap at all, and the ones that do are genuinely out of road.

Stop messages for agents that act, not just read

Everything above assumes the agent is producing text and files. When the agent can send email, change infrastructure or call paid third-party APIs, the boundary carries a different risk: side effects that cannot be undone by cutting the budget afterwards per this enforcement discussion.

For these agents, add two fields to the schema: side_effects_committed and side_effects_uncertain. The second field is the important one. It lists actions the agent started but could not confirm, such as a request sent without a response or a job submitted without a status check. A person then knows exactly what to verify before re-running, which is the difference between a recovery that takes minutes and one that takes an incident review.

Autonomy level should also be encoded at the boundary rather than decided ad hoc. Governance frameworks that distinguish fully supervised, checkpointed, monitored and post-hoc reviewed work give you a vocabulary for this, and the checkpointed level, where routine cases proceed and exceptions escalate to a human, maps naturally onto the cap as set out in this handoff and autonomy guide. At the cap, the agent is always in the escalate branch.

Treat the boundary as a trust boundary too. Limit what context and credentials cross it, and revalidate before the next run acts on inherited state, because a compromised or malfunctioning upstream step can otherwise steer later actions through context it should never have passed along per this handoff governance guidance.

There is an older, useful analogy. When a contract is terminated for convenience, the supplier does not stop dead and vanish: it stops incurring new obligations, protects the work already done, and submits a settlement proposal describing what was completed and what remains under the termination rules in the Federal Acquisition Regulation. Your agent's stop message is that settlement proposal. Short, factual, and sufficient for someone else to close the file.

If the boundary work is where your team keeps getting stuck, a free 30-minute discovery call is a reasonable place to sketch the protocol against your actual stack: book a Quanta consulting call.

FAQ

FAQ

What exactly should the agent say when the cap fires?

It should emit a short structured message naming what finished, what is partial with its exact path, what it intended to do next, and the single input a person must supply. Keep it small enough that a reviewer can act in under a minute without reading the transcript.

Should the agent be allowed to exceed the cap to finish its current step?

Yes, if the overshoot is bounded and reserved in advance, and if it is spent only to reach a safe point such as closing a file or completing a write. Size that reserve from the measured cost of a late step, not an average step, because context growth makes late steps the most expensive ones.

Why not just let the provider's monthly spending cap handle it?

Because account-level caps are set at monthly ceilings and usually fire long after the run has done its damage, while dashboards and alerts only record what already happened. A decision made before each call, scoped to the run, is the only thing that reliably stops the next request per this enforcement analysis.

How do I decide between a step cap, a time cap and a budget cap?

Pick based on what you are actually protecting. Steps suit predictable tool loops, time suits interactive sessions and CI deadlines, and budget suits long autonomous runs where cost is the risk. If you need several, set precedence explicitly, with budget usually first because it is the one that can block the next paid call.

How do I test the stop path before it matters?

Run the agent against a deliberately tiny cap in staging, with a task you know cannot finish, and check that the handoff artifact exists on disk, that the message validates against the schema, and that a second person can resume from it without asking the original operator anything. If any of the three fails, the cap is not doing its job.

Sources

Sources

  1. AI Agent Loop Token Costs: How to Constrain Context
  2. The Token Economy of Multi-Turn Tool Use
  3. AI Agent Budget Enforcement: Dashboards Are Not Control
  4. AI Agent Budget Control: Enforce Hard Spend Limits - Cycles
  5. AI Unit Economics: Allocating Token Spend to the Teams ...
  6. Agent Handoff Protocols: Passing Work Between Agents
  7. AI Agent Cost Control | Request-Path Budget Enforcement
  8. Set Token Budgets for an AI Product
  9. How AI Agent Loops Multiply Costs, The Retry Rate Analysis
  10. Stop Burning API Budget With 5 Patterns for LLM Token ...
  11. AI Agent Handoff Protocols: 4 Levels of Autonomy
  12. How should teams govern AI agent handoffs across ...
  13. Part 49 - Termination of Contracts
About the author

About the author

Antonio Evans
Antonio Evans

Antonio Evans is the founder of Quanta Intelligence and a fractional CTO who builds HIPAA-ready AI systems for health and life-science companies. Before that he was technical co-founder of FriendsEAT for twenty years, CEO of Socialdraft, and a data engineer at IBM. Antonio lives with his dog Santino in Lisbon, Portugal.

All articles