SuperAPIAI Directory

agent-cost-guardrails

github.com · AI coding

Framework-native budget limits and circuit breakers for AI agent frameworks (CrewAI, AutoGen, LangGraph). Hard token caps, cost alerts, and spend tracking with hooks that integrate directly into agent execution loops. Open-source, available on PyPI and npm.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)

About this tool

agent-cost-guardrails is an open-source tool that provides budget limits and cost protection for AI agent frameworks, designed to prevent runaway API spending during agent operation. It achieves this through hard budget constraints, circuit breaker mechanisms, and per-agent cost tracking.

Purpose The tool's core purpose is to add "cost guardrails" to AI agent frameworks. When agents repeatedly call large model APIs during debugging, loops, or long conversations, costs can accumulate rapidly. agent-cost-guardrails intercepts these calls at the framework level, ensuring spending does not exceed a preset budget, and issues alerts or directly aborts execution when approaching or exceeding thresholds.

Key Capabilities

  • Hard budget limits: Raises BudgetExceededError when spending exceeds the set budget.
  • Per-call token limits and per-minute token rate limits.
  • Circuit breaker: Triggers after N consecutive violations, stopping subsequent calls.
  • Alert callbacks: Can be triggered at configurable thresholds such as 50%, 80%, and 100%.
  • Cost breakdown: Tracks spending separately by model and by agent.
  • Thread-safe: Suitable for multi-agent parallel execution scenarios.
  • Built-in pricing: Covers over 30 models (OpenAI, Anthropic, Google, Mistral, DeepSeek, Meta).
  • Custom price overrides: Prices can be specified for any model.
  • Zero infrastructure: No gateway, proxy, or external service required; it is pure Python middleware that hooks into the framework at the process level.

Usage This tool is installed as framework-specific extras. It is designed as pure Python middleware that hooks directly into the agent's execution loop, checking before each LLM call is executed.

Taking AutoGen as an example: AutoGen agents converse back and forth to solve problems. Without limits, a debugging loop of over 20 rounds might cost more than $20 before the conversation naturally ends. AutoGenGuardrails wraps a budget hook around each agent—each LLM call is checked before execution, and the conversation stops cleanly when the budget is exhausted. The integrations/autogen_example.py in the repository provides a runnable comparison example: an unprotected conversation costs $5.82, while setting a $1.00 budget stops at $0.82.

The tool also supports use in LangGraph / LangChain and provides a management interface via Context Manager.

Use Cases Suitable for developers building multi-agent applications with frameworks such as CrewAI, AutoGen, and LangGraph, especially teams that need to control API costs and avoid unexpectedly high bills caused by debugging or loop calls.

Limitations Official materials do not provide complete integration step details for the tool in each framework, specific code examples for the context manager, complete API documentation for alert callbacks, or detailed usage of the npm package; this content is not currently available. The tool uses the MIT license; see the LICENSE file in the repository for details.

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools