Skip to main content

An agent completes a task correctly most of the time but sometimes goes badly wrong. How do you debug it?

Agents and tools · Intermediate 3

Short answer

Collect traces of the failing runs: every model call, tool call, argument, result and token count. Compare them with good runs to find the step where they diverge, usually a bad tool result, a misread instruction or missing context. Fix that step, then rerun a set of tasks to check the fix and catch regressions.

Deeper answer

Without traces you are guessing. Use structured logs or a tracing tool so each run is a tree of steps you can inspect. Group failures by cause: tool errors, wrong tool choice, poor planning, context overflow. Fixes differ: improve tool descriptions or error messages, add a validation step, shrink the context, or turn part of the agent into a fixed workflow.

Turn every real failure into a test case, so the eval set grows with production experience. Track success rate, steps and cost per task over time.

What a strong answer covers

Answer it out loud in the mock interview about 1.5 min

Follow-ups to expect

Common mistakes

Learn it

Logs and traces for agents

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.