Hello! In our last lesson, we identified the three major challenges in deploying AI agents to production: reliability, cost, and latency. We established that these are not just technical hurdles but fundamental systems design problems rooted in the non-deterministic nature of agents.
Today, we move from identifying what goes wrong to learning how to see it happening. This lesson is about building the observational capacity to diagnose and ultimately fix agentic systems. As a software engineer, you know that you can't fix what you can't see. We will equip you with a mental model for categorizing agent failures and the monitoring strategies required to detect them in the wild.
By the end of this lesson, you will be able to describe common failure modes in agentic systems and the monitoring strategies to detect them, such as tracing and logging.
1. A Taxonomy of Agent Failures
Unlike traditional software where bugs are often deterministic and reproducible (e.g., a null pointer exception), agent failures can be subtle, semantic, and intermittent. An agent might fail not because of a code error, but because it "misunderstood" a tool's output or got stuck in a repetitive reasoning loop.
To bring order to this chaos, it helps to categorize the common ways agents can fail. The following article provides an excellent, detailed breakdown of ten common failure modes observed in production environments.
How to Debug AI Agents: 10 Failure Modes + Fixes
The article 'How to Debug AI Agents: 10 Failure Modes + Fixes' by Galileo.ai is a practical catalog of what can go wrong. We'll use it to build our understanding of the problem space.
Read about the first, second, and fourth failure modes: 'Hallucination cascade,' 'Tool invocation misfires,' and 'Planner infinite loops.' For each one, focus on understanding the cause of the failure.
Based on the article and common industry experience, we can group these failures into a few logical buckets:
A. Reasoning and Output Failures
These are failures in the agent's "thinking" process or its final output.
- Hallucination Cascade: The agent confidently invents a fact (e.g., a non-existent API parameter), and this initial error snowballs, leading subsequent steps down an incorrect path.
- Non-deterministic Output Drift: The same input produces wildly different outputs across multiple runs. This makes testing difficult and erodes user trust, as the agent's behavior feels inconsistent.
B. Process and Control Flow Failures
These relate to how the agent executes its task plan.
- Planner Infinite Loops: As described in the reading, the agent gets stuck repeating a step or cycling between a few steps without making progress. This is a direct cause of the runaway cost and latency issues we discussed in the last lesson.
- Context Window Truncation: The conversation history or provided documents exceed the model's context limit, causing it to "forget" crucial information, often the most recent user instruction. The agent's reasoning may be sound, but it's operating on incomplete information.
C. Interaction and Integration Failures
These occur at the boundary between the agent and the external world.
- Tool Invocation Misfires: The agent calls a tool with incorrect parameters (wrong format, wrong value) or misinterprets a valid but unexpected response. This is one of the most common failure points.
- Latency Spikes & Resource Starvation: An agent's plan might be too complex, involving multiple, slow tool calls in sequence, leading to unacceptable response times for the user.
This diagram offers another way to visualize these failures, particularly in the context of multi-agent systems.

Now that we have a catalog of what can go wrong, let's focus on how to detect these issues.
2. The Observability Toolkit for AI Agents
In software engineering, observability is the ability to understand the internal state of a system from its external outputs. For AI agents, this is not just a "nice-to-have" for debugging; it's a core requirement for building reliable systems.
Traditional observability rests on three pillars: Logs, Metrics, and Traces. Let's start with a quick refresher on these concepts.
How an AI Agent Debugged a Production Incident in 80 Seconds (For 60 Cents)
To build our monitoring strategy, let's revisit the foundational pillars of software observability. This video provides a clear and concise explanation of each.
Watch the segment from 00:58 to 03:18. Focus on the definitions, purposes, and limitations of logs, metrics, and traces.
While these three pillars are the right foundation, their application to AI agents requires some specialization due to non-determinism and complex, multi-step reasoning.
Logs: Capturing the "Why"
For agents, simple text logs are insufficient. You need structured logs that record not just that an event happened, but the context surrounding it: the agent's internal "thought" process, the exact tool it decided to call (action), and the observation it received back.
Many developers new to building agents initially neglect this, leading to painful debugging sessions.
Evaluating and Debugging Non-Deterministic AI Agents
Listen to this segment from Google Cloud developers discussing a common pitfall: forgetting to apply standard software engineering practices like logging to the new domain of AI.
Watch from 04:56 to 06:08. The key insight here is the feeling of debugging a 'non-deterministic black box' and the realization that comprehensive logging is the straightforward solution.
A good structured log for a single agent step might look like this (in JSON format):
{
"step": 3,
"thought": "The user wants to know the weather in Paris. I need to use the `get_weather` tool with the location 'Paris, FR'.",
"action": {
"tool": "get_weather",
"tool_input": { "location": "Paris, FR" }
},
"observation": {
"status": "success",
"data": { "temp_c": 18, "condition": "Cloudy" }
}
}
Traces: Visualizing the Agent's Journey
While logs capture individual steps, traces are what tie them all together. A trace follows a single user request from beginning to end, showing the entire sequence of thought, action, and observation steps. This is arguably the single most important tool for debugging an agent.
By visualizing the trace, you can immediately spot issues like:
- An agent getting stuck in a loop (repeated tool calls).
- A tool returning an error that confuses the agent.
- The agent choosing the wrong tool for the job.
Metrics: Quantifying Performance and Quality
Metrics provide a high-level, aggregate view of your agent's health. You need to track both traditional and AI-specific metrics.
- Traditional Metrics: Latency (P50, P95, P99), error rates (per tool, per agent), CPU/memory usage.
- AI-Specific Metrics: Token usage/cost per request, tool call success rate, hallucination rate, and task success rate.
This diagram helps visualize how these components work together.

To tie this all together, let's look at a guide that formalizes the core components of observability specifically for AI agents.
A Comprehensive Guide to Observability in AI Agents
This guide provides a structured overview of what data you need to collect for effective agent observability, emphasizing the unique requirements of AI systems.
Read the section 'Core Components of Agent Observability.' Focus on the lists under 'AI-Specific Metrics' and the description of what an effective 'Distributed Trace' must include for an agent.
Test your understanding!
An e-commerce agent you built is supposed to help users find products, add them to a cart, and check out. Users report that sometimes, after adding an item to the cart, the agent says the cart is empty.
Using the concepts of logs, metrics, and traces, describe how you would instrument the agent to debug this. What specific information would you look for in each?
Show answer
Here’s a systematic approach using the observability pillars:
-
Traces: First, I'd find a trace for a failed session. The trace would show the entire sequence of agent steps. I would look for the
add_to_carttool call, confirm it was successful, and then inspect the subsequentview_carttool call. The trace would reveal if theview_cartcall failed, or if the agent misinterpreted its output, or perhaps if the agent never even calledview_cartand just hallucinated that it was empty. The trace gives me the ground truth of what actually happened step-by-step. -
Structured Logs: Within that trace, I'd examine the structured logs for each critical step.
- For the
add_to_cartcall: I'd check the log to see the exact product ID and quantity the agent sent. Was it valid? - For the
observationafteradd_to_cart: What did the tool return? Did it confirm the item was added? - For the
thoughtprocess after the user asks to see the cart: What was the agent's reasoning? Did it decide to callview_cartor did it reason incorrectly based on a faulty memory?
- For the
-
Metrics: At a higher level, I would check the metrics dashboards.
- Is there a spike in the error rate for the
add_to_cartorview_carttools? This would indicate a systemic problem with the tool itself (e.g., a database issue). - Is the latency for the
add_to_carttool unusually high? Maybe it's timing out, leading to a race condition where the agent checks the cart before the addition is complete. - A custom metric for "Cart Inconsistency" (e.g., counting instances where an
add_to_cartcall is followed by an empty cart report) could quantify how often this specific failure mode occurs.
- Is there a spike in the error rate for the
Conclusion
You now have a framework for both identifying common agent failures and implementing the monitoring strategies needed to detect them. This moves you from the realm of hoping an agent works to engineering a system where you can observe, diagnose, and improve its performance.
Key Takeaways:
- Agent failures are diverse, spanning issues with reasoning (hallucinations), control flow (infinite loops), and tool integration (misfires).
- Effective monitoring requires adapting the traditional observability pillars for the unique challenges of AI agents.
- Structured logs are essential for capturing the agent's internal state (thought, action, observation) at each step.
- Distributed tracing is the most powerful tool for debugging, providing an end-to-end view of an agent's non-deterministic execution path.
- Monitoring must include AI-specific metrics like token cost, tool usage patterns, and task success rates, in addition to standard metrics like latency and errors.
Now that we know how to detect failures, the next logical step is to handle them. In our next lesson, we will get practical and learn how to implement automatic retries with exponential backoff to make our agent more resilient to transient tool failures.