Understanding and Debugging Agent Behavior › Debugging Example: The Wrong Answer
AI Agent HandbookAll chapters Understanding and Debugging Agent Behavior › Debugging Example: The Wrong AnswerOne section · Sections in this chapter6 / 10 ↓
Let's walk through a complete debugging session. A user reports that when they asked "How many days until Christmas?", the agent gave the wrong number.
You check the logs:
2025-11-10 18:00:00 - assistant - INFO - User query: How many days until Christmas?
2025-11-10 18:00:00 - assistant - INFO - Tool required: False
2025-11-10 18:00:01 - assistant - INFO - Generating direct response (no tool)
2025-11-10 18:00:01 - assistant - INFO - Assistant response: There are 45 days until Christmas.Today is November 10, and Christmas is December 25. That's 45 days, so the answer looks correct. But wait, you realize the agent is giving a static answer. If someone asks tomorrow, it will still say 45 days.
The root cause: The agent tried to calculate the answer directly instead of using a date calculation tool. It happened to get lucky with the right answer today, but the answer will be wrong tomorrow.
Adjust the tool selection logic to recognize date-related questions as requiring the date calculator tool.
After the fix, the logs look like this:
2025-11-10 18:05:00 - assistant - INFO - User query: How many days until Christmas?
2025-11-10 18:05:00 - assistant - INFO - Tool required: True
2025-11-10 18:05:00 - assistant - INFO - Selected tool: date_calculator
2025-11-10 18:05:01 - assistant - INFO - Calling date_calculator with: days_between(today='2025-11-10', target='2025-12-25')
2025-11-10 18:05:01 - assistant - INFO - Date calculator returned: 45
2025-11-10 18:05:01 - assistant - INFO - Assistant response: There are 45 days until Christmas.Now the agent uses the date calculator tool, which will always compute the correct answer based on the current date. Problem solved.