Agent loop cost simulator
A ReAct-style agent runs a loop: think, act, observe, repeat. Each pass appends
to a growing scratchpad that gets re-sent on the next call, so cost climbs with
every iteration. A task that usually finishes in three loops can quietly run to
twenty when the agent gets stuck. This simulator shows the typical cost, the
worst-case cost at your max_iterations cap, and helps you set a safe ceiling.
How it works
The simulator models cost as accumulating across iterations, where each iteration’s input grows as the scratchpad lengthens. To keep it transparent it uses a per-iteration token figure that already reflects the average growing context:
typical_cost = avg_iterations × tokens_per_iteration / 1M × price
worst_cost = max_iterations × tokens_per_iteration / 1M × price
The gap between the two is your exposure — the amount a single runaway task can cost beyond what you expect.
Tips and notes
- Always set max_iterations. An uncapped loop is an uncapped bill. Treat the cap as a non-negotiable safety control.
- Fail loud, fail cheap. Configure the agent to return a clear error when it hits the cap rather than silently retrying the whole task.
- Log iteration counts. If your average creeps toward the cap over time, your prompts or tools are getting harder to follow — investigate before the bill grows.