Agent Spend: Runaway Loops and Guardrails
A chat answer costs about what you expect. An agent decides how many steps to take, so its cost per task is set by its behavior, and a bad run can spend many times the typical amount before anyone looks. A manager bounds that with four layers of limits, derived from the cost of a normal task, plus an alert and a tested way to stop a run. The limits are cheap to set compared with the cost of a loop nobody bounded.
After this chapter you can
- Explain why agent cost per task has a long tail set by behavior and not by price alone.
- Set turn, run, day and organization limits from the measured median cost and 95th-percentile turns of real runs.
- Name loop signals, such as repeated identical calls and retry storms, that should halt a run before any cap does.
- Run the stop, preserve, reconcile and fix sequence on a runaway run, and drill the stop path with a timed test.
- State the most one run and one day of your least supervised agent could cost.
An agent differs from a chat answer in one way that matters to a budget: it chooses how many steps to take. A run that costs little on a normal day can cost many times that on a day when the agent cannot find what it needs, retries a failing tool, or keeps asking itself to try again; that is the failure these limits are for. Your director’s question will arrive as a bill, and your answer should be a number you set in advance: the most one run can spend.
Level 1 treated an agent’s authority as a design decision, bounded by how far a mistake can reach. This chapter applies the same thinking to money. It covers where agent cost comes from, four layers of limits, how to set the numbers from a normal task, what to do when a run goes wrong, and one public case about limits arriving from the outside.
Why agent cost compounds
Three mechanisms make agent spend harder to predict than chat spend. First, each step sends the growing history again. The Claude Code documentation, as of October 2026, says the full conversation goes with every request, and that each tool use sends another request carrying its results; prompt caching lowers the rate at which that history is re-read, but a one-line question late in a long conversation still draws on the whole thing1. Second, work can run without you. The same page lists scheduled tasks that fire while a conversation sits idle, and goal check-ins that are capped at three while idle in that product, as sources of cost that grow without anyone typing. Third, more agents mean more context windows. The page says agent teams use approximately 7 times the tokens of standard sessions when teammates run in plan mode, as the vendor puts it for that feature1. Anthropic’s earlier engineering post on its own research system said agents typically used about 4 times the tokens of chat and multi-agent systems about 15 times; that points the same way but is one system’s result, not a general rate2.
None of this says agents are a bad deal. It says the cost of one task is a distribution with a long tail, and a budget needs a limit on the tail.
Four layers of limits
A single cap is brittle. A monthly budget alert reaches you after the damage, and a per-run cap does not stop a thousand cheap runs. Use four layers, each catching what the one below lets through.
The step layer limits how many model calls one run can make and watches for repetition. The run layer puts a spend ceiling and a time ceiling on one task. The day layer caps what one key or job can spend in a day and warns before it gets there. The organization layer is the provider’s own limit on a workspace or account, which you set but do not operate. Layers one and two stop a single loop. Layer three stops many loops, and layer four stops a mistake in the first three.
Tools already offer pieces of this, and their details differ in ways worth reading before you rely on them.
The sources for this table are the Claude Code command-line reference3, the OpenAI Agents SDK documentation4, the LangGraph error reference5 and Anthropic’s costs page1. Two cautions come from the documentation itself. A cap that compares a client’s own estimate against a limit can be passed, because the figure is an estimate and not an invoice. And the usage endpoint Anthropic documents typically shows data within about 5 minutes, with a cost report in daily buckets only6. So, as I read those documents, billing data is the second line, not the first. The first line is inside the run: a limit the agent cannot talk its way past.
Set the numbers from a normal task
Limits copied from a blog post are wrong for your task. Measure first. Run the agent on real tasks, record the cost and the number of turns per task, and compute the median cost, the 95th-percentile turns and the expected number of tasks per day. Then derive limits from those, as starting values to be tuned:
- Turn limit: roughly twice the 95th-percentile turns. Lower, and you stop good runs; higher, and a loop gets room.
- Per-run budget: roughly 5 times the median cost per task. Review every run that hits it.
- Time limit: about 3 times the median wall-clock time, so a stuck call cannot hold a run open.
- Day cap: about 1.5 times expected daily cost, set on the key or job itself.
- Alert: 80 percent of the day cap, sent to a person who can act.
The multipliers are illustrative starting values and not rules. What matters is the structure: each limit has a measured reason, and each capped run is reviewed. A cap that fires often is telling you either that the task is harder than you measured or that the agent has a bug. Raising the cap without reading the run only moves the ceiling.
Attended and unattended agents deserve different settings. When an engineer watches a coding agent work, the person is the loop detector, and a wide cap is acceptable because a human can press stop. When the agent runs from a scheduler, a pipeline or a background job, nobody is watching, so the limits must be tighter and the alert must reach someone who is awake. Ask of every agent in your register which of the two it is. The unattended ones get all four layers before they run; the attended ones can start with the run and day layers. The reach of an agent’s permissions matters here as well, because a looping agent that can only read files wastes money, while one that can create cloud resources or open tickets can also leave a mess to clean up, and a budget cap does not undo that.
Recognize a loop before the cap does
Caps work as a backstop. A loop detector catches the pattern earlier and cheaper. It looks at the run’s own history for signals that the agent is repeating itself.
Here is what the controls can look like when written as configuration. This is a sketch of the idea, and each framework names the settings differently.
agent: nightly-flaky-test-triage
limits:
max_turns: 25
max_budget_per_run: 4.50 # US dollars, estimate-based, leave headroom
max_wall_clock_minutes: 20
repeated_identical_call: 3
key_daily_cap: 54.00 # on the key itself, not only in the agent
alert_at_fraction_of_daily_cap: 0.8
stop_owner: [named person, backup]
Retry logic deserves its own look, because it is where loops often start in ordinary software: a call fails, the code retries, the model re-plans and calls again. Every retry path needs a count and a back-off, and the agent should return an error to a person when the count is spent.
When a run goes wrong
You will eventually see a capped run or an alert. The response is a short, rehearsed sequence, and the first step is to stop the spend, not to find the cause.
Test the stop path. The Claude Code command line, for example, can stop a background session by identifier3, but that helps only if the person on call knows the command and has the rights. Once a quarter, have the named person stop a harmless test run and revoke a test key, and time it. Write down who can do this when you are away.
Case: weekly limits for round-the-clock use
Limits can also arrive from the provider. In July 2025, trade press reported that Anthropic would introduce weekly rate limits for Claude subscribers from 28 August 2025. As reported by VentureBeat, the company cited advanced usage such as running Claude around the clock in the background, along with account sharing and resale, and said the limits would affect about 5 percent of users. The same report records that many developers reacted negatively, saying the move punished many for the actions of a few, while some were more understanding of a platform at capacity9.
Read the case narrowly. It concerns subscription usage and capacity, not a company’s invoice, and the report is trade press rather than Anthropic’s own post. What a manager can take from it is a point about control. Unattended, always-on agent use eventually meets a limit, and if you have set none, the one that arrives may be someone else’s, on someone else’s schedule, and it can stop work that mattered. The report does not say that any particular team lost work this way. Your own limits are chosen for your task; the provider’s are chosen for its capacity.
A team-sized worked example
The costs below are invented to show the arithmetic, and the multipliers are illustrative starting values. Picture a seven-engineer team that runs a nightly agent in CI to triage failing tests. Each night it handles 40 failing test groups, one run per group. The team measures two weeks of real runs.
One night, run 17 meets a flaky lookup service, retries, re-plans and calls again. At its 25th turn it hits the turn limit and stops, having spent 4.10 US dollars, below the 4.50 budget, so the turn limit bound first. The other 39 runs cost 0.90 each, 35.10 in total, and the night comes to 39.20 US dollars (35.10 plus 4.10), under the 43.20 alert line. No alert fires. The morning report lists run 17 as capped, the engineer on call reads its log, and the finding is that the agent retried a failing call without a count. The team adds the retry limit and the repeated-call check from the loop table.
Look at what the layers did. Without limits, nothing in the design bounded run 17. With them, the worst night possible is the daily cap of 54.00 US dollars, provided the cap is enforced on the key itself and not from a client-side estimate, since all 40 runs hitting the 4.50 budget would total 180.00, and the cap binds first. The monthly ceiling of 1,620 US dollars is 540 above the expected 1,080 (1,620 minus 1,080), and it is a number the manager can state to finance in advance.
Check yourself
- A monthly budget alert is enough to keep an agent’s spend under control.
- Limits for an agent should be derived from measured cost and turns of a normal task.
- A spend cap enforced from a client’s own estimate may be passed.
- Raising a limit each time it fires is a safe fix.
- A stop control that nobody has tried is a control you can rely on.
- Unattended agents may eventually meet limits set by the provider if you set none.
Reflection
What this means for engineering managers
Your Monday action, owned by you as the manager with the on-call lead as the named stop owner: choose your least supervised agent or scheduled job, and write down the most a single run and a single day could cost under its current settings. If you cannot, that is the first limit to set. Then bring these to your next review.
- A turn limit, a per-run budget and a day cap, each tied to a measured baseline.
- An alert at 80 percent of the day cap, sent to a named person.
- A written stop path that someone has tested this quarter.
- A review of every capped run, before any limit is raised.
What comes next
Controls keep agent spend bounded; seats are the other half of the bill, and they renew on the vendor’s calendar. The next chapter, Seat Licenses, Utilization and Renewal Decisions, covers reviewing who uses each license and deciding whether to keep, move, downgrade or drop it.
Laws referenced
Not legal advice. Laws change; verify before relying on this, and consult counsel for decisions.
EU AI Act · EU
Regulation (EU) 2024/1689, as amended by Regulation (EU) 2026/1744
Risk-based rules. Prohibited practices include social scoring, untargeted scraping of facial images, and emotion recognition in workplaces and schools (with narrow exceptions). High-risk systems (Annex III: biometrics, safety components of critical infrastructure such as energy, water and traffic, employment and worker management, credit, education, essential services, law enforcement, migration, justice) need risk management, data governance, documentation, logging, human oversight, human oversight that keeps people able to understand the system, notice automation bias (over-reliance on its output), override it or stop it (Art. 14(4)), appropriate accuracy, robustness and cybersecurity (Art. 15), automatic logging of events (Art. 12), a provider quality-management system (Art. 17) and conformity assessment. An Annex III system is not high-risk if it poses no significant risk of harm, for example a narrow procedural or preparatory task that does not replace human assessment; systems that profile people are always high-risk, and a provider relying on this exception must document it and register (Art. 6(3)). Deployers of high-risk AI must use it as instructed, assign competent human oversight, monitor its operation, keep logs for at least six months and report serious incidents (Art. 26); employers must inform workers' representatives (Art. 26(7)). Public bodies, private providers of public services, and deployers of credit-scoring or life and health insurance pricing systems must carry out a fundamental-rights impact assessment before first use (Art. 27). Providers must run post-market monitoring (Art. 72). A deployer that puts its name on a high-risk system, substantially modifies it, or changes its purpose so that it becomes high-risk takes on the provider's obligations (Art. 25(1)). A substantial modification (Art. 3(23)) of a high-risk system needs a new conformity assessment, unless the change was pre-determined and documented at the first assessment, as with planned continuous learning (Art. 43(4)). Providers of general-purpose AI models (from 2 Aug 2025) must keep technical documentation, have a policy to comply with EU copyright law including text-and-data-mining opt-outs, and publish a sufficiently detailed summary of training content (Art. 53). Research, testing and development before a system is placed on the market or put into service is outside the Act, except testing in real-world conditions (Art. 2(8)). Since the 2026 Omnibus, the Art. 4 AI-literacy duty is an obligation of effort (take measures to support literacy), not of result. Fines reach EUR 35 million or 7% of global turnover for prohibited practices.
- 2024-08-01 — Entered into force
- 2025-02-02 — Prohibited practices (Art. 5) and the AI-literacy duty (Art. 4) apply
- 2026-07-27 — Omnibus softens Art. 4: providers and deployers must take measures to support AI literacy; no specific level must be guaranteed
- 2025-08-02 — General-purpose AI model obligations apply; governance and penalties regime in place
- 2026-08-02 — Transparency duties (Art. 50) apply: disclose AI interaction, label synthetic and deepfake content (marking for generative systems already on the market: 2 Dec 2026)
- 2027-12-02 — High-risk obligations for Annex III systems (e.g. hiring, credit, education, essential services) - moved from 2 Aug 2026 by the 2026 Omnibus
- 2028-08-02 — High-risk obligations for AI in products regulated under Annex I
Last verified 2026-10-06 · official text
EU Digital Omnibus on AI · EU
Regulation (EU) 2026/1744
First amendment to the AI Act. Defers high-risk obligations (Annex III to 2 Dec 2027, Annex I to 2 Aug 2028), adds two prohibited categories, softens the Art. 4 AI-literacy duty to "take measures to support", and simplifies some compliance duties. Art. 50 transparency duties still apply from 2 Aug 2026, with one transition (new Art. 111(4)): providers of generative AI systems placed on the market before 2 Aug 2026 must meet the Art. 50(2) marking duty by 2 Dec 2026.
- 2026-07-24 — Published in the Official Journal
- 2026-07-27 — Entered into force
- 2026-12-02 — Grace period ends for safeguards against two new prohibited uses (non-consensual intimate imagery, child sexual abuse material)
- 2026-12-02 — Art. 50(2) marking duty applies to generative AI systems placed on the market before 2 Aug 2026 (Art. 111(4))
Last verified 2026-10-10 · official text
References
- Anthropic. Manage costs effectively (Claude Code documentation). Claude Code documentation. 2026.
- Anthropic. How we built our multi-agent research system. Anthropic Engineering blog. 2025.
- Anthropic. CLI reference (Claude Code documentation). Claude Code documentation. 2026.
- OpenAI. Running agents (OpenAI Agents SDK). OpenAI Agents SDK documentation. 2026.
- LangChain. GRAPH_RECURSION_LIMIT. LangGraph documentation. 2026.
- Anthropic. Usage and Cost API. Claude Platform documentation. 2026.
- European Parliament and Council of the European Union. Regulation (EU) 2024/1689 laying down harmonised rules on artificial intelligence (Artificial Intelligence Act). Official Journal of the European Union. 2024.
- European Union. Regulation (EU) 2026/1744 (Digital Omnibus on AI) amending Regulation (EU) 2024/1689. Official Journal of the European Union. 2026.
- VentureBeat. Anthropic throttles Claude rate limits, devs call foul. VentureBeat. 2025.
Further reading
- Anthropic. CLI reference (Claude Code documentation). Claude Code documentation. 2026.
- Anthropic. Manage costs effectively (Claude Code documentation). Claude Code documentation. 2026.
- OpenAI. Running agents (OpenAI Agents SDK). OpenAI Agents SDK documentation. 2026.
- LangChain. GRAPH_RECURSION_LIMIT. LangGraph documentation. 2026.
- VentureBeat. Anthropic throttles Claude rate limits, devs call foul. VentureBeat. 2025.
Sources last verified 2026-10-13.