AgentBrake
Free · Private by design

Stop runaway AI agents before they burn your budget.

AgentBrake is the emergency brake for LangChain & CrewAI. One line of code stops infinite loops, cost blowouts and endless reasoning, in real time, before the next expensive call goes out.

Star on GitHub

imports as agentbrake· LangChain 1.x & 0.x · CrewAI 1.x

AgentBrake halting a runaway agent at a $2 cost ceiling as the running cost climbs

A runaway agent racking up cost, stopped the moment it crosses your ceiling, before the bill grows.

Agents fail expensively, not loudly

In November 2025, four LangChain agents entered an infinite loop. They ran for 11 days. The bill was $47,000. Nobody noticed until it was over.

This is not rare. An agent calls the same tool 14,000 times with identical arguments. A planner expands one task into dozens of subagent calls. A reasoning loop never terminates and runs all night. Observability tools record it, they don't stop it. The gap between “the alert fired” and “the run stopped” is exactly where the money goes.

One line to wire it in

AgentBrake watches every step in real time and raises a clean exception that halts the agent before the next expensive call.

LangChain 1.xLangGraph
from agentbrake import LangChainBrakeMiddleware
from langchain.agents import create_agent

agent = create_agent(
    model, tools=tools,
    middleware=[
        LangChainBrakeMiddleware(
            max_cost_usd=2.00,
            repeat_tool_limit=5,
        )
    ],
)
CrewAI 1.xbefore kickoff
from agentbrake import CrewAIBrake

# right before crew.kickoff()
CrewAIBrake(
    max_cost_usd=3.00,
    repeat_tool_limit=5,
).install()

What it catches

Five runaway patterns, one brake. It warns at 80% of any limit and stops at 100%.

Identical-tool loops

Same call, same args, over and over. Trips after N identical calls in a row.

repeat_tool_limit

Cost blowouts

The $47k overnight run. A hard ceiling, enforced live as tokens are spent.

max_cost_usd

Endless reasoning

A loop that never hits its stopping condition. Caps total reasoning steps.

max_steps

Tool-call storms

Runaway tool fan-out. Caps total tool invocations per run.

max_tool_calls

Hung runs

A run that just keeps going all night. A wall-clock ceiling per run.

max_duration_s

Provider spend caps are monthly and account-wide, they fire after the damage. AgentBrake is per-run and in-process: it stops this agent now.

A sprinkler, not a smoke alarm.

In-process by design. Private and fast.

AgentBrake runs inside your process as a library. No proxy, no gateway. Your prompts and data never leave your environment, and the brake adds microseconds, not a network round-trip.

Privacy by design

Your prompts, completions and tokens stay in your process. Nothing is sent to a third party, so there is nothing to leak.

~3 microseconds per step

Measured overhead per agent step, with no network call in the hot path. Over 300,000 steps per second on a single core.

No proxy in the path

Proxy and gateway tools add a round-trip and see your traffic. AgentBrake is just a local library, so latency stays yours.

Frequently asked questions

What is AgentBrake?

AgentBrake is an open-source Python package that stops runaway LangChain and CrewAI agents in real time. You set limits, cost ceiling, identical-tool-loop detection, max steps, tool calls, and duration, and it halts the run before the next expensive call goes out.

How is it different from observability tools?

Observability tools like Langfuse, Helicone, and LangSmith record what an agent did. AgentBrake intercepts and stops it. It runs in-process and per-run, so it halts this agent now, not after the bill arrives.

Does it work with LangChain 1.x and CrewAI 1.x?

Yes. On LangChain 1.x (create_agent / LangGraph) it uses middleware that runs inside the agent graph, because callbacks can only observe a LangGraph run, not stop it. On CrewAI 1.x it patches the provider call path and raises a BaseException the framework's retry loop cannot swallow.

How much code does it take?

One line. You add the middleware (LangChain) or call .install() (CrewAI). No refactor, no proxy, no account. It's free to use and source-available (FSL).

Stop your next runaway agent

One line of code. Free and in-process. Works on LangChain 1.x, CrewAI 1.x, and the classic AgentExecutor.

Star on GitHub