Show HN: AgentFuse – A local circuit breaker to prevent $500 OpenAI bills
Hey HN,

I’ve been building agents recently, and I hit a problem: I fell asleep while a script was running, and my agent got stuck in a loop. I woke up to a drained OpenAI credit balance.

I looked for a tool to prevent this, but most solutions were heavy enterprise proxies or cloud dashboards. I just wanted a simple "fuse" that runs on my laptop and stops the bleeding before it hits the API.

So I built AgentFuse.

It is a lightweight, local library that acts as a circuit breaker for LLM calls.

Drop-in Shim: It wraps the openai client (and supports LangChain) so you don't have to rewrite your agent logic.

Local State: It uses SQLite in WAL mode to track spend across multiple concurrent agents/terminal tabs.

Hard Limits: It enforces a daily budget (e.g., stops execution at $5.00).

It’s open source and available on PyPI (pip install agent-fuse).

I’d love feedback on the implementation, specifically the SQLite concurrency logic! I tried to make it as robust as possible without needing a separate server process.

had this happen with a retry loop. hit $80 on anthropic before i caught it. how does this handle retries? seems like an agent could just keep retrying and blow past the limit
That is exactly why we enforce a hard budget cap (default is $1.00).

The system runs a pre-flight check before every LLM call. If you're about to go over budget, it kills the process immediately (SentinelBudgetExceeded).

We don't have a specific "max retries" counter wired up yet, but I'll likely add that soon based on your feedback. For now, the budget cap would have caught it at $1.

I just added loop detection based on your comment. It fingerprints tool actions (tool name + args) and kills the agent if it tries the exact same thing 5 times in a row.