What it does
Agent Cost Guardrails is a Python package that stops AI agents from running up unexpected API bills. It runs as middleware inside your own process, with no gateway, proxy or external service, and hooks into the agent framework before and after each model call. Ready-made integrations exist for CrewAI, AutoGen/AG2 and LangGraph, and a context manager and decorator cover custom code. Spending beyond the set budget raises an error, and optional per-call token limits, a tokens-per-minute rate limit and a circuit breaker add further control. Alert callbacks can fire at thresholds such as 50, 80 and 100 percent of the budget. Cost is tracked per model and per agent using bundled pricing for more than 30 models from OpenAI, Anthropic, Google, Mistral, DeepSeek and Meta, and you can override pricing for your own models. The project is MIT licensed and installs with pip.
Capabilities
- Hard budget limit that raises an error on overspend
- Per-call token limits and tokens-per-minute rate limiting
- Circuit breaker that trips after repeated violations
- Alert callbacks at configurable budget thresholds
- Cost reports broken down by model and agent
- Integrations for CrewAI, AutoGen/AG2 and LangGraph
When to use it
- Stopping a looping multi-agent conversation from burning through your API budget
- Seeing which agent or model is responsible for spend
- Adding spend limits without running a proxy or gateway