<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: afonso</title>
    <description>The latest articles on DEV Community by afonso (@tritium007).</description>
    <link>https://dev.to/tritium007</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3271792%2Fd82272eb-fda9-4e60-a177-1a781ee20e5e.png</url>
      <title>DEV Community: afonso</title>
      <link>https://dev.to/tritium007</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tritium007"/>
    <language>en</language>
    <item>
      <title>We built a circuit breaker for AI agents — here's why it matters</title>
      <dc:creator>afonso</dc:creator>
      <pubDate>Tue, 08 Sep 2026 00:02:08 +0000</pubDate>
      <link>https://dev.to/tritium007/we-built-a-circuit-breaker-for-ai-agents-heres-why-it-matters-pih</link>
      <guid>https://dev.to/tritium007/we-built-a-circuit-breaker-for-ai-agents-heres-why-it-matters-pih</guid>
      <description>&lt;p&gt;An agent gets a routine cleanup task. It lists old records, constructs a SQL statement, and calls the database tool. A missing tenant filter turns the intended delete into a production-wide delete. The tool call is syntactically valid, the database accepts it, and the agent reports success.&lt;/p&gt;

&lt;p&gt;The same failure mode appears with APIs. An agent enters a retry loop around a non-idempotent endpoint and sends 10,000 requests before anyone notices. The application has request logs, but no point where a person can stop the next call.&lt;/p&gt;

&lt;p&gt;This is not a model-quality problem. It is an execution-control problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  The exposed boundary
&lt;/h2&gt;

&lt;p&gt;Every team deploying tool-using agents has some version of this boundary today:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;model output -&amp;gt; framework dispatcher -&amp;gt; shell / database / HTTP API
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Frameworks make tool registration and dispatch convenient. They generally assume that once arguments satisfy a schema, the call should run. Schema validation can reject malformed input; it cannot decide whether &lt;code&gt;DROP TABLE users&lt;/code&gt; is appropriate right now.&lt;/p&gt;

&lt;p&gt;Application code can add checks to individual tools, but that approach fragments quickly. Shell tools use one policy, database tools use another, and framework adapters emit incompatible logs. A missing check becomes an execution path around the policy.&lt;/p&gt;

&lt;p&gt;The useful control point is immediately before dispatch, independent of the model and mostly independent of the agent framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three lines around an existing tool
&lt;/h2&gt;

&lt;p&gt;Agentwall is a Python and TypeScript middleware layer for that boundary. An existing Python function can be intercepted directly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;wall&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Agentwall&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;safe_bash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wall&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;bash&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="n"&gt;bash&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;safe_bash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rm -rf /tmp/build-cache&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final line does not execute automatically. Agentwall classifies the arguments as destructive and waits for an approval decision. A denial is recorded and the wrapped function is never called.&lt;/p&gt;

&lt;p&gt;The policy is local and deterministic. It does not ask another language model whether a command looks dangerous. Rules live in &lt;code&gt;agentwall.yaml&lt;/code&gt;, can be reviewed with the code, and can be overridden by environment variables at deployment time.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Interception
&lt;/h2&gt;

&lt;p&gt;The interceptor sits around the actual tool function, not around prompt generation. It therefore sees the tool name and arguments that are about to execute. The same core handles decorated Python functions, TypeScript callables, OpenAI function calls, Anthropic &lt;code&gt;tool_use&lt;/code&gt; blocks, and LangChain tools.&lt;/p&gt;

&lt;p&gt;Each call is assigned one of three levels: &lt;code&gt;safe&lt;/code&gt;, &lt;code&gt;cautious&lt;/code&gt;, or &lt;code&gt;destructive&lt;/code&gt;. Read-only SQL is normally safe. A file write is cautious. Destructive SQL, recursive deletion, or an authenticated mutating HTTP request is destructive. Ordered regex and HTTP-method rules let a project replace or refine those defaults.&lt;/p&gt;

&lt;p&gt;This layer is intentionally small. It does not require moving tools into a hosted runtime and it does not own the agent loop.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Approval gates
&lt;/h2&gt;

&lt;p&gt;By default, destructive calls require human approval. A CLI process gets a fail-closed &lt;code&gt;y/N&lt;/code&gt; prompt. A service can use the webhook provider to route the same decision to an internal dashboard, Slack workflow, or approval queue.&lt;/p&gt;

&lt;p&gt;Timeouts, malformed responses, and unavailable approval services deny the call. That matters: an enforcement dependency should not silently become allow-all when it fails.&lt;/p&gt;

&lt;p&gt;Teams can also require approval for cautious calls. The classification policy and approval threshold are separate, so changing operational posture does not require rewriting rules.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Structured logging
&lt;/h2&gt;

&lt;p&gt;Every attempt produces a JSON event, including blocked calls. The event records the timestamp, session and agent IDs, tool name, redacted arguments, classification, decision, output or error, and duration.&lt;/p&gt;

&lt;p&gt;The default sink writes JSONL locally. Other included sinks write to stdout or an HTTP endpoint, and applications can implement the sink interface directly. Credential-like keys are recursively redacted before persistence.&lt;/p&gt;

&lt;p&gt;These logs answer two different questions: what did the agent try to do, and what actually ran? Keeping the decision alongside the call avoids reconstructing that distinction from scattered application logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Rollback
&lt;/h2&gt;

&lt;p&gt;Some actions have a practical compensating operation: delete a file that was just created, remove a draft record, or restore a previous configuration value. A tool can register that operation as its rollback.&lt;/p&gt;

&lt;p&gt;Agentwall records rollback hooks only after the forward call succeeds. If a session fails or is aborted, it invokes them in reverse order. One rollback failure does not prevent later hooks from being attempted.&lt;/p&gt;

&lt;p&gt;This is compensation, not distributed transaction magic. Rollback functions must be idempotent, and external systems can still fail. The value is that the recovery path is declared next to the tool and runs consistently instead of depending on ad hoc cleanup code in every agent loop.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try the boundary, not another prompt
&lt;/h2&gt;

&lt;p&gt;Agents will continue to produce incorrect calls. The engineering question is whether those calls cross an uncontrolled boundary.&lt;/p&gt;

&lt;p&gt;Try Agentwall around one real tool, inspect the JSONL output, and test both approval outcomes. If the approach is useful, star the repository and open an issue with the framework adapter or policy primitive your deployment needs next.&lt;/p&gt;

&lt;p&gt;It's available &lt;a href="https://github.com/anakatt/agentwall" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
