I burned $153 in 30 minutes with an agent loop — here's the pattern that stopped it
The incident Short story — my agent retried a failing loop using multiple models: My agent: GPT-4o + Stable Diffusion + TradingView Charts + Kling. 100s iterations. $153 in under 30 minutes. My enf...
The incident Short story — my agent retried a failing loop using multiple models: My agent: GPT-4o + Stable Diffusion + TradingView Charts + Kling. 100s iterations. $153 in under 30 minutes. My enforcement layer did not work Rate limiters — control velocity, not total cost. Provider caps — per-provider, not cross-provider. Observability — tells me after. I need before. The pattern that worked for me: reserve-run-commit My budget control in 3 steps: Reserve estimated cost before the call (instrumented code) Execute action (LLM, toolcall) On success — commit actual cost, release unused portion On failure — release the full reservation The critical piece for retries: each reservation has an idempotency key. If the agent retries the exact same action, the second reservation is a no-op. Budget only gets locked once per logical action, not once per attempt. The critical piece for concurrent agents: the reservation is atomic. Two agents can't both check the balance, both see enough, and both