Pre-call guardrails that stop a runaway AI agent before the bill arrives
MaverikSh · reddit · 2026-11-01
The author shares guardrail designs for stopping runaway agents before the provider bills you, since post-hoc cost tools are too late when a loop can burn hundreds of dollars in minutes:
- Per-run budgets: tag every call in a run with one run ID and enforce the budget across all of them.
- Loop detection: kill a session after N identical tool calls in a row or an error streak (their product: 3 identical calls).
- Velocity limits in dollars, not requests: catches floods that request-count limits miss when calls get long.
- Reserve before calling: atomically reserve expected cost before forwarding, then settle; otherwise 20 parallel calls all pass a budget check meant for one.
- Read/write-aware degrading: when budget runs out, hard-stop write-like calls, route read-only calls to a cheaper model.
- A kill switch: one button blocking everything.
Trade-off: all this sits in the request path—one base URL change plus some latency. If you only need after-the-fact reports, a read-only billing integration is simpler. The author asks whether anyone enforces budgets inside the agent framework rather than at a gateway.
More from coding & agent
- traits.sh turns agent code-review feedback into reusable traits, enforcing Redacted for secrets — samgoodwin89 · 2026-11-01
- Google's rakyll: agent quality hinges on locked-down, reproducible environments — IaC principles still apply — rakyll · 2026-11-01
- Browser-Based Video Mapping Built with Claude Code, Open for Agent Remixing — ismaelfaro · 2026-11-01
- Dev runs Codex-driven Blender 3D modeling agent through 8 iterations, hits prompt limits — ZeYanjie · 2026-11-01
- Craft team open-sources Craft Anything for understanding how any software works — ismaelgokufox · 2026-11-01
- "Tell AI to build Netflix": viral exchange reignites debate on AI coding limits — burny_tech · 2026-11-01