LoopCraft
Sign In

2026-08-06

A practical guide to setting token budgets for agent loops

How to measure a loop's baseline cost, choose alert and hard-limit budgets, and wire the Cost Budget Guard into loops with retries and sub-loops.

Back to Blog

Reading time: 5 min

Agent loops are the fastest way to burn through an API bill: every extra iteration multiplies model calls, and retries quietly double the damage. The fix is not to guess a number — it is to measure, then guard. Step 1: establish a baseline. Run the loop on ten representative inputs and record the per-run token total from the trace view. Note the p50 and p95 values; the gap between them tells you how unstable the cost is. Step 2: set two numbers, not one. Use the p95 cost times 1.3 as your hard budget (the loop stops gracefully there and returns partial results), and 80% of that as your alert threshold, which warns you without interrupting work. Step 3: account for retries and sub-loops. A retry-with-backoff node can add up to five extra model calls per failure, and sub-loops inherit their own budgets. Keep the parent's hard limit larger than the sum of the child budgets, or the parent will stop mid-batch. Step 4: watch the breakdown. The per-node cost view shows exactly which step spends the most; in most loops it is the observation summarization step, not the reasoning step. Trim that step's context window before you raise the budget. A sensible default: hard budget at 1.3x p95, alert at 80% of the hard budget, review once a week. Full guide available at https://getloopcraft.com — sapsap@qq.com.