agent-budget
Sends event notifications to Discord via webhook for guardrail triggers, kill switch, projection breaches, loop detection, and budget alerts.
Sends event notifications to PagerDuty via webhook for guardrail triggers, kill switch, projection breaches, loop detection, and budget alerts.
Sends event notifications to Slack via webhook for guardrail triggers, kill switch, projection breaches, loop detection, and budget alerts.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@agent-budgetcreate a monthly budget of $500 for API costs"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Agent Budget
Cost guardrails, spend optimization, and budget management for autonomous AI agents
Features · Install · Quick Start · MCP Setup · Python API · Changelog
Stop runaway LLM costs before they happen. Agent Budget is an MCP server + CLI that gives autonomous AI agents real-time cost guardrails, progressive spend throttling, anomaly detection, model cost optimization, and full budget management — all local, no account required.
┌───────────┐ stdio ┌───────────────┐ JSON ┌──────────────┐
│ Agent │ ─────────────▶ │ agent-budget │ ────────────▶ │ Guardrail │
│ (Claude, │ ◀───────────── │ MCP server │ ◀──────────── │ Engine │
│ Cursor…) │ tool result └───────────────┘ decision └──────────────┘
└───────────┘ │
▼
ALLOW / WARN / THROTTLE / BLOCKWhy Agent Budget?
Problem | Without Agent Budget | With Agent Budget |
Runaway costs | Agent loops burn $$ until you notice | Kill switch + loop detection blocks instantly |
Cliff-edge blocking | Agent goes full-speed → hard stop | Progressive throttling degrades gracefully |
No spend visibility | You find out at end of month | Real-time dashboards + burn forecasts |
Overpaying for models | Using GPT-4 for everything | Model optimizer recommends cheaper alternatives |
No anomaly detection | Slow leaks go unnoticed | Statistical anomaly detection flags outliers |
How it compares
Feature | Agent Budget | Floe-Labs/floe-guard | @three-ws/billing-mcp |
Cost guardrails (pre-flight) | ✅ | ✅ | ❌ |
Progressive throttling (tiers) | ✅ | ❌ | ❌ |
Kill switch | ✅ | ✅ | ❌ |
Spend projection / burn forecast | ✅ | ❌ | ❌ |
Loop detection | ✅ | ❌ | ❌ |
Anomaly detection | ✅ | ❌ | ❌ |
Model cost optimizer | ✅ | ❌ | ❌ |
Budget management | ✅ | ❌ | ✅ |
Reserve & settle (hold funds) | ✅ | ❌ | ❌ |
Webhooks (Slack/Discord/PagerDuty) | ✅ | ❌ | ❌ |
MCP server | ✅ | ✅ (CLI) | ✅ |
REST API | ✅ | ❌ | ❌ |
Tests | 677 | — | — |
Related MCP server: cloudscope-mcp
Features
🚨 Cost Guardrails & Kill Switch (v0.5.0)
Real-time pre-flight checks —
check_guardrails()before LLM calls: ALLOW / WARN / BLOCK decisionsMulti-scope guardrails — Set limits per global, agent, model, budget, or task scope
Multiple limit types — Daily, hourly, per-call, and monthly spend caps
Emergency kill switch — Instantly block ALL LLM calls with auto-expire and override tokens
Cost alert events — Track breaches separately; acknowledge & clear
Cooldown periods — Block subsequent calls for N minutes after a breach
Priority ordering — Higher-priority guardrails checked first; most restrictive wins
📉 Progressive Cost Throttling (v0.8.0)
Tiered spend control — Graduated thresholds (60%, 75%, 90%) instead of binary cutoff
Cost-per-call limits — Recommends max spend per call at each tier
Model downgrade suggestions — "Switch to gpt-4o-mini" at 75% spend
Custom tiers — Define your own threshold percentages and limits
Advisory → Hard cap — 60% = advisory, 90% = blocks expensive calls
💰 Reserve & Settle Protocol (v0.9.0)
Concurrency-safe holds — Reserve funds before an operation, settle or release after
Double-spend prevention — Atomic reserve/settle ensures funds can't be spent twice
TTL-based expiry — Reserves auto-expire and release funds if not settled
Partial settlement — Settle for less than reserved; release the remainder
🔮 Spend Projection & Loop Detection (v0.6.0)
Burn forecast —
project_spend()predicts ETA-to-limit based on spend velocityMulti-period projections — Daily, hourly, and monthly with confidence scoring
Guardrail breach prediction — Know if a guardrail will trigger before period ends
Loop detection — Detect runaway agents making repeated similar LLM calls
Jaccard similarity — Groups repeated operations by call signature
Auto-block — Automatically block looping agents for N minutes
🔍 Spend Anomaly Detection (v0.10.0)
Statistical outlier detection — Flag costs that deviate from historical patterns
Z-score based — Configurable sensitivity thresholds
Per-agent / per-model baselines — Learn normal spend patterns
Real-time alerts — Fire webhook events when anomalies detected
🧮 Model Cost Optimizer (v0.11.0)
Compare models — Cost-compare your current model against all alternatives
Smart recommendations — Cheapest viable alternative with rationale + tier analysis
Savings projection — Monthly savings estimate for model switches
Capability tiers — High / medium / economy classification with fuzzy matching
Cheapest-for-tier — Find the cheapest model at or above a capability level
30+ models — Built-in pricing for OpenAI, Anthropic, Google, Meta, Mistral, Cohere
🔔 Guardrail Webhooks (v0.7.0)
Webhook notifications — Fire on guardrail triggers, kill switch, projection breaches
Event filtering — Subscribe to specific events (warn/block/kill/threshold/loop)
HMAC-SHA256 signing — Optional secret for request signature verification
Retry with backoff — Automatic retries on 5xx errors with exponential backoff
Slack/Discord/PagerDuty ready — Standard JSON POST payloads work out-of-the-box
📊 Budget Management (v0.1.0–v0.4.0)
Budget tracking — Create budgets with limits, periods, categories, rollover
Expense tracking — Log expenses with categories, tags, vendor info, receipts
Recurring expenses — Schedule payments (daily/weekly/monthly/quarterly/yearly)
Savings goals — Track progress toward targets with auto-completion
Spending rules — Block, warn, or require approval for expenses
Income tracking — Multiple sources, recurring income templates
Cash flow analysis — Income vs expenses, savings rate, burn rate, runway
Financial dashboard — Health score (0-100), budget status, sustainability
Multi-currency — 15+ currencies
Data export — JSON, CSV, Markdown
Installation
pip install agent-budgetOr with uv:
uv pip install agent-budgetQuick Start
CLI
# Create a monthly budget
agent-budget budget create "API Costs" --limit 500 --period monthly --category api
# Log an expense
agent-budget expense add 25.50 --category api --description "OpenAI GPT-4 call" --vendor "OpenAI"
# Check budget status
agent-budget budget status
# Create a cost guardrail (block at $50/day globally)
agent-budget guardrail create "Daily Cap" global --daily-limit 50.0
# Check before an LLM call
agent-budget guardrail check --cost 0.05 --agent worker-bot --model gpt-4o
# Emergency stop
agent-budget kill-switch trigger "Budget blown — investigating"
# Optimize: find cheaper model
agent-budget optimize recommend --model gpt-4o --input-tokens 1000 --output-tokens 500MCP Server Setup
Claude Desktop
~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"agent-budget": {
"command": "uvx",
"args": ["agent-budget", "serve"]
}
}
}Cursor
~/.cursor/mcp.json:
{
"mcpServers": {
"agent-budget": {
"command": "uvx",
"args": ["agent-budget", "serve"]
}
}
}Continue
~/.continue/config.yaml:
mcpServers:
- name: agent-budget
command: uvx
args: ["agent-budget", "serve"]Any MCP host
command: uvx, args: ["agent-budget", "serve"]
Programmatic
from agent_budget.mcp_server import mcp
mcp.run()MCP Tools
Cost Guardrail Tools
Tool | Description |
| Pre-flight check before an LLM call — returns ALLOW/WARN/THROTTLE/BLOCK |
| Create a spending limit (global/agent/model/budget/task scope) |
| List all guardrails |
| Delete a guardrail |
| Emergency stop — blocks ALL LLM calls |
| Reset (requires override token if set) |
| Check if kill switch is active |
| Enable tiered spend control on a guardrail |
| List cost alert events |
Spend Projection & Loop Detection
Tool | Description |
| Burn forecast — predicts ETA-to-limit |
| Loop detection — checks for repeated similar calls |
| Configure loop detection parameters |
| List loop detection configs |
| Delete a loop detection config |
Model Cost Optimizer (v0.11.0)
Tool | Description |
| Compare current model against all alternatives |
| Get cheapest viable alternative with rationale |
| Monthly savings projection for a model switch |
| Cost estimate for a model + token profile |
| Find cheapest model at/above a capability tier |
| Browse models by cost |
Reserve & Settle (v0.9.0)
Tool | Description |
| Reserve funds before an operation |
| Settle a reservation (full or partial) |
| Release an unsettled reservation |
| List active reservations |
Budget & Expense Tools
Tool | Description |
| Budget CRUD |
| Carry unspent budget forward |
| Budget vs. actual analysis |
| Expense CRUD |
| Savings goals |
| Spending rules |
| Recurring expenses |
| Analysis |
| Export to JSON/CSV/Markdown |
How Guardrails Work
Agent wants to call GPT-4o
│
▼
check_cost_guardrail(cost=$0.05, agent_id="worker-1", model_id="gpt-4o")
│
▼
Guardrail engine checks in priority order:
1. Kill switch active? ──────────────────────▶ BLOCK (all calls)
2. Per-call limit exceeded? ─────────────────▶ BLOCK
3. Progressive throttle tier active? ────────▶ THROTTLE (advisory or block)
4. Daily/hourly/monthly limit exceeded? ─────▶ BLOCK
5. Approaching a limit? ─────────────────────▶ WARN
6. All clear ────────────────────────────────▶ ALLOW
│
▼
Returns: GuardrailDecision {
action: ALLOW | WARN | THROTTLE | BLOCK,
reason: "...",
suggestions: [...],
throttle_tier: "60%" | "75%" | "90%" | null,
max_recommended_cost_usd: ...,
recommended_model: "gpt-4o-mini" | null,
}
│
▼
Agent proceeds, adjusts, or stopsProgressive Throttling Tiers
Instead of a cliff-edge (full speed → hard block), spend degrades gracefully:
Spend Level | Max Cost/Call | Action | Model Recommendation |
< 60% of limit | No restriction | ALLOW | — |
60% of limit | $0.50 | THROTTLE (advisory) | — |
75% of limit | $0.20 | THROTTLE (advisory) | Switch to gpt-4o-mini |
90% of limit | $0.05 | BLOCK if exceeded | Switch to gpt-4o-mini |
Python API
from agent_budget.service import BudgetService
from agent_budget.models import GuardrailScope, GuardrailAction
svc = BudgetService()
# Set up guardrails with progressive throttling
svc.create_guardrail(
name="Daily agent cap",
scope=GuardrailScope.AGENT,
scope_id="worker-bot",
daily_limit_usd=20.0,
warn_at_percent=75,
progressive_throttling=True, # Enable tiered control
)
# Before each LLM call — check guardrails
decision = svc.check_guardrails(
estimated_cost_usd=0.05,
agent_id="worker-bot",
model_id="gpt-4o",
)
if decision.action in (GuardrailAction.BLOCK, GuardrailAction.KILL):
print(f"Blocked: {decision.reason}")
elif decision.action == GuardrailAction.THROTTLE:
print(f"Throttled at {decision.throttle_tier}")
print(f"Max recommended cost: ${decision.max_recommended_cost_usd}")
if decision.recommended_model:
print(f"Consider switching to: {decision.recommended_model}")
elif decision.action == GuardrailAction.WARN:
print(f"Warning: {decision.reason}")
else:
make_llm_call() # Proceed
# Model optimization — find cheaper alternatives
from agent_budget.optimizer import ModelOptimizer
opt = ModelOptimizer()
recommendation = opt.recommend(
current_model="gpt-4o",
input_tokens=1000,
output_tokens=500,
monthly_calls=10000,
)
if recommendation:
print(f"Switch to {recommendation.recommended_model}")
print(f"Save {recommendation.savings_percent:.0f}% per call")
print(f"Monthly savings: ${recommendation.projected_monthly_savings:.2f}")
print(f"Rationale: {recommendation.rationale}")
# Reserve & settle — prevent double-spending in concurrent agents
reservation = svc.create_reservation(
agent_id="worker-bot",
amount_usd=5.00,
scope=GuardrailScope.AGENT,
scope_id="worker-bot",
ttl_seconds=300, # Auto-release after 5 min
)
# ... do the operation ...
svc.settle_reservation(reservation.id, actual_amount_usd=4.23)
# Remaining $0.77 is released back
# Burn forecast
proj = svc.project_spend(
scope=GuardrailScope.AGENT,
scope_id="worker-bot",
period="daily",
)
if proj.will_breach_guardrail:
print(f"⚠️ Will breach in {proj.eta_minutes_to_limit:.0f} min")
print(f"Recommendation: {proj.recommendation}")
# Emergency kill switch
svc.trigger_kill_switch(reason="Security incident", override_token="admin-only")
# All check_guardrails() now return action=KILL
svc.reset_kill_switch(override_token="admin-only")Data Storage
All data is stored in JSON files under ~/.agent-budget/ (or the directory specified by the AGENT_BUDGET_DIR environment variable). No external database required.
Supported Currencies
USD, EUR, GBP, JPY, CAD, AUD, CHF, CNY, INR, BRL, KRW, MXN, SGD, SEK, NZD
Testing
# Run all 677 tests
uv venv .venv
VIRTUAL_ENV=$(pwd)/.venv uv pip install -e ".[dev]"
.venv/bin/python -m pytest -qArchitecture
src/agent_budget/
├── models.py # Pydantic models (Budget, Expense, Guardrail, ThrottleTier, ...)
├── store.py # JSON file persistence
├── service.py # Business logic (BudgetService)
├── llm_costs.py # Model pricing catalog + cost calculation
├── optimizer.py # Model cost optimizer (compare, recommend, project)
├── mcp_server.py # MCP server with 40+ tools
├── api_server.py # REST API (FastAPI)
└── cli.py # CLI (click + rich)Changelog
v0.11.0 — Model Cost Optimizer 🧮
Model comparison, recommendation, savings projection
Capability tier classification (high/medium/economy)
6 new MCP tools, 5 new API endpoints
39 new tests (677 total)
v0.10.0 — Spend Anomaly Detection 🔍
Statistical outlier detection (z-score based)
Per-agent/model baselines
Anomaly webhook events
v0.9.0 — Reserve & Settle Protocol 💰
Concurrency-safe fund reservation
TTL-based expiry, partial settlement
Double-spend prevention
v0.8.0 — Progressive Cost Throttling 📉
Tiered spend control (60%/75%/90%)
Model downgrade suggestions
Custom tiers support
v0.7.0 — Guardrail Webhooks 🔔
Webhook notifications with HMAC signing
Event filtering, retry with backoff
Slack/Discord/PagerDuty ready
v0.6.0 — Spend Projection & Loop Detection 🔮
Burn forecast with ETA-to-limit
Runaway loop detection with auto-block
v0.5.0 — Cost Guardrails & Kill Switch 🚨
Real-time pre-flight checks
Multi-scope, multi-period guardrails
Emergency kill switch
v0.4.0 — Income & Financial Dashboard 📊
Income tracking, cash flow, burn rate
Financial health scoring, REST API
v0.2.0 — Savings & Rules 💰
Savings goals, budget rollover
Spending rules, expense receipts
v0.1.0 — Initial Release 🎉
Budget management, expense tracking
Multi-currency, data export
License
MIT
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/nyx-builds/agent-budget'
If you have feedback or need assistance with the MCP directory API, please join our Discord server