Free, source available · LangChain & CrewAI

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.

$pip install agentbrake-sdk
Star on GitHub

Imports as agentbrake. Free, source-available (FSL). Works on LangChain 1.x, CrewAI 1.x, and the classic AgentExecutor.

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 hits its stopping condition and runs all night. Observability tools record it. They don't stop it — and the gap between "the alert fired" and "the run stopped" is exactly where the money goes.

How it works

AgentBrake watches every step in real time. When a run crosses a limit you set, it raises a clean exception that halts the agent before the next expensive call goes out.

LangChain

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)],
)

LangChain guide →

CrewAI

from agentbrake import CrewAIBrake

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

CrewAI guide →

What it catches

Runaway patternHow AgentBrake stops it
Identical-tool loops
same call, same args, over and over
repeat_tool_limit — trips after N identical calls in a row
Cost blowouts
the $47k overnight run
max_cost_usd — a hard ceiling, enforced live as tokens are spent
Endless reasoning
no stopping condition
max_steps — caps total reasoning steps
Tool-call stormsmax_tool_calls — caps total tool invocations
Hung runsmax_duration_s — wall-clock ceiling

It warns at 80% of any limit and stops at 100%.

Why not just set a provider spend cap?

Provider caps are monthly and account-wide — they fire after the damage, across everything. AgentBrake is per-run and in-process: it stops this agent now, before the next call. It's the difference between a smoke alarm and a sprinkler.

Stop your next runaway agent

One line of code. Open source. Works on LangChain 1.x, CrewAI 1.x, and the classic AgentExecutor.

$pip install agentbrake-sdk
Star on GitHub

Frequently asked questions

What is AgentBrake?
AgentBrake is a free, source-available 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, before the next call — 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 uses a BaseException so the framework's retry loop can't swallow the brake.
Is AgentBrake free?
Yes, it is free to use and source-available under the FSL (non-compete; converts to MIT after two years). Install it with pip install agentbrake-sdk.
How much code does it take?
One line. You add the middleware (LangChain) or call .install() (CrewAI). No refactor, no proxy, no account.