crithstudio-hash/agent-circuit
When tools fail, your agent degrades gracefully instead of looping.
Platform-specific configuration:
{
"mcpServers": {
"agent-circuit": {
"command": "npx",
"args": [
"-y",
"agent-circuit"
]
}
}
}Add the config above to .claude/settings.json under the mcpServers key.
When tools fail, your agent degrades gracefully instead of looping.
Stop agent tool loops, enforce cost caps, and degrade gracefully. One decorator. Zero dependencies. Works with Claude Code, MCP, OpenAI Agents SDK, LangChain, and CrewAI.
Your agent calls a failing API. It retries 47 times. That burns $12, wastes 90 seconds, and your user stares at a spinner.
from agent_circuit import CircuitBreaker, CircuitDegraded
breaker = CircuitBreaker(max_failures=3, cost_global_limit=5.0)
@breaker.protect("search_api", cost_per_call=0.26)
def search(query: str) -> str:
return api.search(query)
try:
result = search("latest news")
except CircuitDegraded as e:
print(e.result.message) # "Search API unavailable"
print(e.result.suggestion) # "Skip and proceed with available info"Result: 48 calls reduced to 4. $11.70 saved. 85 seconds saved.
pip install agent-circuitpython -m agent_circuit demoNo API keys needed. Shows before/after comparison with simulated failures.
One command setup. Protects all tool calls automatically:
agent-circuit install-hookThis adds PreToolUse and PostToolUse hooks to .claude/settings.local.json. Restart Claude Code to activate.
Check status:
agent-circuit statusAdd circuit breaking to any MCP server:
from fastmcp import FastMCP
from agent_circuit.integrations.mcp import AgentCircuitMiddleware
mcp = FastMCP("my-server")
mcp.add_middleware(AgentCircuitMiddleware(max_failures=3))
@mcp.tool()
def search(query: str) -> str:
return api.search(query)Install: pip install agent-circuit[mcp]
from agents import Agent
from agent_circuit.integrations.openai_agents import protect_tools
agent = Agent(
name="my-agent",
tools=protLoading reviews...