Understanding and Debugging Agent Behavior › Tracing Reasoning Chains

Michael BrenndoerferAugust 8, 20253 min read
AI Agent HandbookAll chapters
Part 12 of 15Observability and Debugging - Peering Inside the Agent
Chapter 34Understanding and Debugging Agent Behavior › Tracing Reasoning Chains
Reading section 3 of 10 · Tracing Reasoning Chains · 3 minSection 3 of 10 · 3 min

Book contents

Section 3 of 10 · 3 min read

Understanding and Debugging Agent Behavior › Tracing Reasoning ChainsOne section · Sections in this chapter3 / 10 ↓

When your agent uses chain-of-thought reasoning, the logs become even more valuable. They let you follow the agent's logic step by step and see where its thinking went astray.

Imagine your agent is trying to answer: "If a train travels 60 miles in 45 minutes, how far will it travel in 2 hours?"

The logs might look like this:

2025-11-10 16:10:22 - assistant - INFO - User query: If a train travels 60 miles in 45 minutes, how far will it travel in 2 hours?
2025-11-10 16:10:22 - assistant - INFO - Starting reasoning chain
2025-11-10 16:10:23 - assistant - INFO - Reasoning step 1: First, I need to find the train's speed
2025-11-10 16:10:23 - assistant - INFO - Reasoning step 2: Speed = 60 miles / 45 minutes = 1.33 miles per minute
2025-11-10 16:10:24 - assistant - INFO - Reasoning step 3: Convert 2 hours to minutes: 2 * 60 = 120 minutes
2025-11-10 16:10:24 - assistant - INFO - Reasoning step 4: Distance = speed * time = 1.33 * 120 = 160 miles
2025-11-10 16:10:24 - assistant - INFO - Assistant response: The train will travel 160 miles in 2 hours.

Here the reasoning is correct, and you can verify each step makes sense. But what if the agent made an error?

2025-11-10 16:15:10 - assistant - INFO - User query: If a train travels 60 miles in 45 minutes, how far will it travel in 2 hours?
2025-11-10 16:15:10 - assistant - INFO - Starting reasoning chain
2025-11-10 16:15:11 - assistant - INFO - Reasoning step 1: The train goes 60 miles in 45 minutes
2025-11-10 16:15:11 - assistant - INFO - Reasoning step 2: 2 hours is about 2.5 times longer than 45 minutes
2025-11-10 16:15:12 - assistant - INFO - Reasoning step 3: So the distance is 60 * 2.5 = 150 miles
2025-11-10 16:15:12 - assistant - INFO - Assistant response: The train will travel 150 miles in 2 hours.

Now you can see the problem. In step 2, the agent estimated that 2 hours (120 minutes) is "about 2.5 times" 45 minutes. But 120 / 45 is 2.67, not 2.5. The agent's approximation introduced an error. The logs pinpoint exactly where the reasoning went wrong, making it clear what needs to be fixed. You might adjust the prompt to encourage more precise calculations or have the agent use the calculator tool for division.