DEV Community

Deepak Nailwal
Deepak Nailwal

Posted on

Circuit: why AI agents need a circuit breaker before they touch production

Most AI-agent demos follow the same script: give the agent a plain-English instruction, watch it call an API, done. It's a satisfying demo. It's also not the hard part.

The hard part is what happens next. What happens when the agent is wrong? What happens when it's asked — accidentally or on purpose — to do something dangerous, like issuing a refund or deleting a record? What happens when the network drops halfway through a payment and the same request gets retried?

That's the gap I built Circuit to close.

What Circuit actually does

Circuit is a safety layer that sits between an AI agent and the real-world actions it takes through Swytchcode, which handles the actual API execution — auth, retries, schema validation — across more than 2,000 supported services.

Before any action runs, Circuit puts it through four checks:

1) Risk classification. Every action gets tagged LOW, MEDIUM, HIGH, or BLOCKED based on what it does. Reading a list of repos is LOW risk. Issuing a refund is HIGH risk. Deleting a production database is BLOCKED outright, no matter what.
2) Human confirmation. HIGH-risk actions stop and wait. The agent has to show me exactly what it's about to do — service, action, parameters — before I type "yes."
3) Idempotency protection. If the same action is requested twice (say, because a retry fired after a timeout), Circuit recognizes it and returns the cached result instead of executing it again. No double refunds.
4) A permanent audit trail. Every action, allowed or blocked, gets logged with a timestamp and reasoning — so there's always a record of what an agent actually did and why.

The whole thing lives in a single Python file, with a free fallback parser so it can be tested without any API keys at all.

Proving it against a real API, not a simulation

It's easy to build a safety layer that only ever talks to a mock. I wanted proof it worked against something real, so I connected it to the GitHub API through Swytchcode's CLI pipeline — swytchcode get to pull the integration, swytchcode auth connect for OAuth, then swytchcode exec to actually run the call.

The result: a real GitHub issue, created live, with a 201 status code straight from GitHub's API. Not mocked, not simulated — a genuine HTTP round trip triggered by a natural-language instruction, filtered through Circuit's risk checks the whole way.

What actually broke along the way

None of this worked on the first try, and the failures were more instructive than the successes:

Sandbox vs. production mode. New Swytchcode projects default to a sandbox environment that points at localhost instead of the real API. Nothing fails loudly — it just quietly never leaves your machine — until you flip "mode": "sandbox" to "mode": "production" in tooling.json.
Workspace mismatches. Authenticating a provider happens per-workspace. Create a new project directory and you can end up in a fresh, unauthenticated workspace even though the same account already has GitHub connected elsewhere. swytchcode auth workspace to list and switch fixed it.
Windows encoding quirks. The Swytchcode CLI logs status with emoji (🔐) to stderr. Python's subprocess module on Windows defaults to cp1252, which can't decode them, and throws an unrelated-looking UnicodeDecodeError. Forcing UTF-8 decoding with errors="replace" on every subprocess call fixed it for good.
PowerShell quoting. Inline JSON bodies with --body '{"key":"value"}' get mangled by PowerShell's quoting rules. Writing the body to a temp JSON file and passing --body payload.json instead is the reliable path on Windows.



Every one of these was silent or confusing at first — the kind of thing that erodes trust in an agent fast if you don't build in visibility. That's part of why Circuit prints exactly what command it ran, the exit code, and the raw output whenever a real call fails, instead of swallowing the error.

Why this matters more than another API demo

Anyone can wire an agent to one API and call it a project. The interesting question is what happens when that agent is wrong, or asked to do something irreversible, or the network hiccups at the worst possible moment. Those are the conditions real production systems live in, and they're exactly what most agent demos skip.

Circuit doesn't skip them. It's a small, reusable pattern — risk classification, confirmation, idempotency, audit — that works the same way whether the underlying action is a GitHub issue, a Slack message, or a Stripe refund, because it sits on top of Swytchcode's uniform execution layer rather than hand-rolling integration code per service.

Code: https://github.com/deepaknailwal/circuit-agent

Top comments (0)