Skip to main content

An economic circuit-breaker for CrewAI multi-agent systems. Stop your AI agents from bankrupting you.

Project description

crew-fusebox

CI

Stop your AI agents from bankrupting you.

An ultra-lightweight, open-source economic circuit-breaker for CrewAI multi-agent systems. Wrap your kickoff() with one decorator to get real-time dollar-spend tracking across the whole crew and an opt-in hard budget ceiling that deterministically stops a runaway loop before it produces an invoice-shock bill.

Why not just max_iter / max_rpm?

CrewAI already caps an agent's iteration count (max_iter) and request rate (max_rpm). crew-fusebox does not duplicate those. It stops loops by real-time dollar cost, aggregated across every agent in a crew, and blocks the next LLM call the moment a budget ceiling is breached — the economic dimension CrewAI's per-agent, count/rate-based knobs don't model.

Most CrewAI cost guards hook into step_callback/task_callback — they can only react after a step finishes. crew-fusebox hooks into before_llm_call — it blocks the next request before it's sent, mid-step if needed.

Install

pip install crew-fusebox

Requires Python 3.11–3.13 and crewai>=1.14.

Quickstart

from crew_fusebox import crew_circuit_breaker, CircuitBreakerException
from crewai import Crew

# Dry-run / audit mode (default): passively tracks spend and prints color-coded warnings,
# never interrupts the run.
@crew_circuit_breaker(max_budget_dollars=5.00)
def run_pipeline():
    return Crew(agents=[...], tasks=[...]).kickoff()

# Hard-kill mode: blocks the next LLM call and raises CircuitBreakerException once the
# dollar ceiling is breached.
@crew_circuit_breaker(max_budget_dollars=5.00, hard_kill=True)
def run_guarded_pipeline():
    return Crew(agents=[...], tasks=[...]).kickoff()

try:
    run_guarded_pipeline()
except CircuitBreakerException as exc:
    print(f"Tripped after ${exc.spent_dollars:.4f} across {exc.call_count} calls")

How it works

  • Enforcement binds to CrewAI's before_llm_call hook, which runs before each LLM call and can block it — so a hard-kill stops spend before the next call is dispatched. (CrewAI's step_callback/task_callback fire after a step and only report; they can't prevent the next call.)
  • Cost is computed from real token usage via LiteLLM's maintained pricing data (token_counter + cost_per_token), so there is no hand-maintained price table to go stale.
  • Safe by default: ships in dry-run mode; only blocks when you opt in with hard_kill=True.
  • Fail-open: any internal error in the breaker warns on stderr and lets your agent proceed — it never crashes a healthy host application.

Enforcement semantics (read this)

Hard-kill blocks the next LLM call after the budget is breached — not the call that breaches it. This is intentional:

  • Cost is booked in after_llm_call from the actual response, so the breaker only knows a call put you over budget after that call returns. The following before_llm_call is then blocked and CircuitBreakerException is raised.
  • The pre-call decision is deliberately a sub-millisecond compare (no tokenizing on the hot path), and true cost can't be known before a call anyway (output tokens don't exist yet).

Practical consequence: you may overshoot the budget by roughly one call. For the target use case — a runaway loop against a budget many times a single call's cost (e.g. a $5 ceiling with ~$0.01 calls) — this is negligible. It only matters if one call is a large fraction of the whole budget, so set the ceiling with a small buffer above a single expected call's cost.

Configuration

Argument Default Meaning
max_budget_dollars None Dollar ceiling for the run. None = passive tracking only.
hard_kill False Block + raise on breach. False = warn only (dry-run).
warn_thresholds (0.5, 0.8, 1.0) Budget fractions at which to emit escalating warnings.

Status

Phase 1 MVP. License: MIT. See plan.md and the design docs in sdk/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crew_fusebox-0.1.2.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crew_fusebox-0.1.2-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

Details for the file crew_fusebox-0.1.2.tar.gz.

File metadata

  • Download URL: crew_fusebox-0.1.2.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for crew_fusebox-0.1.2.tar.gz
Algorithm Hash digest
SHA256 521037898e3a7aca68652ebbe145830f218efa22da6a79bddc9ee45be88160b4
MD5 dcd54cbe3f84f8d3c03b215b81ec1f17
BLAKE2b-256 cc23f7baea8ac128108d6dd741103c840cc3be26e72ea9bb08d6aaffc1f3ea1c

See more details on using hashes here.

File details

Details for the file crew_fusebox-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: crew_fusebox-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 21.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for crew_fusebox-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9cbf15c98427cce6401ccdfef1833a60f2751627a795f2e373b93b76c8b97a83
MD5 df6f03654b67fb35af223b9fd7031b92
BLAKE2b-256 1a49050dfc0c4a53578edde6a86f7adca3efeafc7670370cde07ccf368fe7a32

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page