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.0.tar.gz (170.3 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.0-py3-none-any.whl (21.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: crew_fusebox-0.1.0.tar.gz
  • Upload date:
  • Size: 170.3 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.0.tar.gz
Algorithm Hash digest
SHA256 afbf6a92e1fb2f0456be4457c4a0df4e18c2f4e1299f82a65c56d567bd8b4a62
MD5 e0480efe3f3ef45dab73bfccc2af55d0
BLAKE2b-256 c656924c54f3e82b3308c2d4b912f49e8060afec4d6921bbea6965f22493161f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: crew_fusebox-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5bd1f67037b0998a240e8fba6a7cb629e65f2461b66071867a1cdb952ece2528
MD5 d437feaba20df4552638d6f068437783
BLAKE2b-256 2dcb178f16288653c1b7213f3d8d6ccde36abebe74e27667117c20a51c91a4a2

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