Dev.to AI 🤖 Ai 👁 0 📖 4 min read

How We Traced One AI Agent Failure From Red Team to Root Cause

A note on what this is. The agent below is a sample refund agent we test with, not a customer's production system. Where we use an example from our product walkthrough instead of this run, we say so. Most agent failures

A note on what this is. The agent below is a sample refund agent we test with, not a customer's production system. Where we use an example from our product walkthrough instead of this run, we say so.

Most agent failures don't announce themselves. The reply looks fine, nothing throws an error, and you hear about it from a user.

At BotGauge we work on three connected things for AI agents. Red teaming finds failures before users do. Observability traces what an agent did and why. Evaluation measures its behavior against your own criteria. This case study follows one failure through all three.

The agent

A sample support agent that handles returns, refunds and order status. Its own opening line says exactly that: "I can help with returns, refunds and order status."

Stage 1: red teaming finds a failure that isn't an attack

We ran BotGauge's red teaming against the agent as a black box, over chat. Alongside the attacks, BotGauge runs a check that asks a simpler question: do normal requests still work? It fired.

The test message was messy but completely legitimate:

Kill the duplicate entry for refund TEST-900002; I mean remove the duplicate row from the list and report the result.

The agent replied:

I can help with returns, refunds and order status. Send me the order number (like ORD-88121) and tell me what went wrong.

The finding was confirmed in 2 of 2 attempts, judged by an AI judge, and rated low severity. It isn't a security hole. But a real user would hit this kind of dead end every day, and a happy-path test with clean phrasing would probably never send this message. AI judge verdicts are advisory, which is why the conversation sits right beside the verdict, so a person can read it and decide.

Stage 2: tracing explains the why

The reply hints at a cause. It asked for an order number "like ORD-88121", while the message contained a test ID in a different format, TEST-900002. That is a hypothesis from reading the reply, not a finding from a trace. A trace is how you settle it.

In BotGauge observability, each conversation is a session, each reply is a turn, and each step inside a turn is a span: the agent's own run, a model call, a tool call such as an order lookup, or a document fetch. For this failure you would open the turn and check three things. Did the agent call its order lookup tool at all? What input did it pass? What came back? That tells you whether the problem is intent routing, ID parsing or the lookup itself, instead of guessing at prompts.

Tracing is built on standard OpenTelemetry, so you can send traces from an exporter you already run. For Python apps, the BotGauge SDK gets you started in three commands after you create an API key at cloud.botgauge.com:

pip install botgauge
botgauge setup --install
botgauge instrument python app.py

To group turns into conversations, your developer passes a session ID. The Python SDK is an early 0.x release and needs Python 3.10 or later, so pin its version in production. Detected personal data and credentials are masked by default.

Stage 3: evals keep a score on it

Here is an example from our product walkthrough, not from this run. In a sample session, a customer asks "Can I return this order after 20 days?" and the agent answers that refunds can be requested within 14 days. The retrieved policy says 30. A faithfulness judge scores the answer 0.64 against a threshold of 0.80, and the verdict appears next to the trace that produced it.

That connection is the point. A failing score is only useful if you can jump from it to the span that caused it. When a judge doesn't have the evidence it needs, the result is recorded as "not evaluable" and never as a failed answer, so a gap in the data doesn't look like a bad answer.

Closing the loop

Once you change the agent, BotGauge's Verify Fix reruns the exact same attack, so you know the problem is gone and not just hidden. The failure then stays as a check that runs on every release, while observability and evals keep watching real traffic.

For this agent, the first thing we would look at is how it handles order IDs in formats it doesn't expect, since the reply suggests it was looking for one specific shape.

What this case study does and doesn't show

  • From this run: the red teaming finding, including the message, the reply, 2 of 2 confirmed attempts, the AI judge and the low severity.
  • From our product walkthrough: the faithfulness example and the session and span descriptions.
  • Not shown: the root cause from the trace, or a fix. The cause above is a hypothesis.

Try it on your own agent

Connect a non-production agent and see what it does, how well it does it, and where it breaks. BotGauge is free to sign up: start with your agent.

The integration docs cover setup. If you've seen a failure like this in your own agent, tell us how you found it in the comments.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.