agent's LLM token spend blew the budget, no per-run cap on its own reasoning loops
Puts a per-run token budget and iteration ceiling on agent reasoning loops so the agent cannot spend unboundedly on itself. Use when an agent's own inference cost spiked because loops had no cap. Not for single-shot model calls with fixed prompts.
TL;DR
An agent with no per-run token budget is a blank check. Set a hard token ceiling per run, a max iteration count for reasoning loops, and an early-exit rule when the loop stops making progress. Alert when a run hits 80% of its budget so a human sees it before the bill does.
agent's llm token spend blew the budget, no per-run cap on its own reasoning loopsUse this when
- Agent inference spend spiked with no corresponding increase in completed work.
- Reasoning loops (plan, act, observe, repeat) have no iteration limit.
- The agent's own cost is untracked while it optimizes everyone else's.
Not for this skill when
- Spend is dominated by a fixed workload (batch inference with known prompt sizes). Cap the batch, not the loop.
- You already have per-run budgets and the spike came from volume, not runaway loops.
Steps
- Measure the damage: break down inference spend by agent run or task for the spike period. Verify: identify the runs with extreme token counts.
- Set a per-run token ceiling in the agent harness (a number, not a suggestion). Verify: a test run exceeding it actually stops.
- Add a max-iteration cap on the reasoning loop (for example, 25 steps) with an early exit when two consecutive steps produce no progress.
- Emit token usage per run to your metrics so the next spike is visible in a dashboard, not a surprise invoice.
- Alert at 80% of the per-run budget; page the owner at 100%.
- Review the capped runs monthly: legitimate work that keeps hitting the ceiling needs a bigger budget, not a workaround.
Variant phrasings
agent reasoning loop infinite token spend
The runaway framing.
cap llm agent cost per run
The preventive question.
agent inference bill spike no limit
Symptom-level search.
Compatibility: Any agent harness with tool-calling loops; model provider billing consoles for the spend breakdown.
Why it happens
Loop termination is the agent's hardest problem and cost control is nobody's problem, so neither gets built. The loop keeps going because each step looks reasonable in isolation, and the meter runs on every step. Unbounded loops plus pay-per-unit pricing is the entire failure.
Edge cases / pitfalls
- A hard cap can kill legitimate long runs. Log capped runs prominently so real work gets re-budgeted instead of silently truncated.
- Token counting must include tool-call payloads, not just model output; large tool results are often the real spend.
- Do not let the agent raise its own budget. The ceiling is set by the operator, full stop.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_EKhaaVoAO5qIP1DX-vfunA