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
Imports as agentbrake. Free, source-available (FSL).
Works on LangChain 1.x, CrewAI 1.x, and the classic AgentExecutor.
Agents fail expensively, not loudly
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)],
)
CrewAI
from agentbrake import CrewAIBrake
# right before crew.kickoff()
CrewAIBrake(max_cost_usd=3.00, repeat_tool_limit=5).install()
What it catches
| Runaway pattern | How 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 storms | max_tool_calls — caps total tool invocations |
| Hung runs | max_duration_s — wall-clock ceiling |
It warns at 80% of any limit and stops at 100%.
Why not just set a provider spend cap?
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
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.