Skip to main content

Inline circuit breaker for LLM agents to prevent stuck loops, budget overruns, and output bloat.

Project description

⚡ AgentBreaker

A real-time circuit breaker for AI agent loops.

AgentBreaker monitors token spend, iteration count, and cost velocity across multi-step LLM orchestration — and hard-stops runaway agents before they burn through budget or get stuck in infinite loops.

Most teams only set max_tokens on a single LLM call. AgentBreaker works at the orchestration layer — across multiple LLM calls, tool invocations, and sub-agent spawns. Observability tools tell you an agent went wrong after the fact. AgentBreaker stops it while it's happening.


The Problem

AI agents that loop, retry, or spawn sub-tasks can silently burn through API budgets in minutes. A max_tokens cap on one call doesn't catch an agent that makes 50 calls in a row. Teams find out when the bill arrives.

What AgentBreaker Does

  • Tracks cost, token usage, iteration count, and elapsed time live, per agent run
  • Evaluates every LLM call against a configurable rule engine
  • Hard-stops the agent the instant a rule fires — not after the fact
  • Surfaces exactly which rule fired and why, with full run history and cost trajectory

Features

  • Composable rule engine — not hardcoded thresholds. Pick which rules apply per run:
    • Total Cost Limit
    • Max Iterations
    • Max Run Time
    • Spend Velocity (catches fast burns)
    • Stuck Loop Detector (same tool called repeatedly)
    • Cost Anomaly Spike (single call costs way more than average)
    • Long Run Warning (soft warning, doesn't stop execution)
  • Live dashboard — real-time cost trajectory chart, run history, trip alerts with estimated savings
  • REST API — start runs, poll status, fetch aggregate metrics
  • Fully containerizeddocker compose up and you have a working demo

Tech Stack

Layer Tech
LLM Provider Groq (Llama 3.3 70B)
Agent Framework LangChain
Backend FastAPI + SQLAlchemy + SQLite
Frontend React + Recharts
Infra Docker + Docker Compose
CI GitHub Actions

Architecture

agentbreaker/

backend/ agent.py # Demo "runaway" research agent circuit_breaker.py # Core breaker — tracks state, evaluates rules rules.py # Rule engine + built-in rule library database.py # SQLAlchemy models, SQLite setup main.py # FastAPI app — endpoints + background run execution frontend/ src/App.js # Dashboard — run form, history, live detail view docker-compose.yml


Quick Start (Docker — recommended)

  1. Clone the repo:
   git clone https://github.com/YOUR_USERNAME/agentbreaker.git
   cd agentbreaker
  1. Get a free Groq API key at groq.com (no credit card required).

  2. Create a .env file in the project root:

   echo "GROQ_API_KEY=your_key_here" > .env
  1. Run it:
   docker compose up --build
  1. Open http://localhost:3000

Local Development (without Docker)

Backend:

cd backend
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
uvicorn main:app --reload --port 8000

Frontend (separate terminal):

cd frontend
npm install
npm start

API Reference

Method Endpoint Description
POST /runs Start a new agent run
GET /runs List all runs
GET /runs/{run_id} Get a single run's live status
GET /rules List all available rules
GET /metrics Aggregate stats across all runs
DELETE /runs Clear all run history

Roadmap

  • Phase 1 — Core breaker logic, demo agent, FastAPI backend, React dashboard
  • Phase 2 — Composable rule engine, per-run rule configuration
  • Phase 3 — Semantic loop detection, goal drift detection, anomaly baselines
  • Phase 4 — LangChain callback handler for zero-friction integration, PyPI package

License

MIT

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

agentbreaker_sdk-2.1.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

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

agentbreaker_sdk-2.1.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file agentbreaker_sdk-2.1.0.tar.gz.

File metadata

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

File hashes

Hashes for agentbreaker_sdk-2.1.0.tar.gz
Algorithm Hash digest
SHA256 3e9695453ad6af6c0ebde5b059bbe5594a9ba96fd94531907d36635084f50d88
MD5 d20288cf338fed98b2908135f85de3e5
BLAKE2b-256 8120e259c3a3bde9d4413de80de6ecb5c36b17ca434d4673814e64492b788a8e

See more details on using hashes here.

File details

Details for the file agentbreaker_sdk-2.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agentbreaker_sdk-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22195511cb4b93bb78bd30208bfdfbd3b112aa4ef1a4b4994cf2297483e15cc6
MD5 3a89a7a39dffc777707035579405691b
BLAKE2b-256 1d7c26e6b8ea85643eb04e3df36711a951d8f6dba86475cbf9566a684302d5a0

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