Free lesson · Module 1, lesson 4 of 7

Reading an agent run, step by step

Follow a recorded run of a helpdesk agent through its messages, tool calls and results, and find the step where it went wrong.

Lessons in this module

Lesson notes

For the student

An agent writes down every step it takes. That record is a run (also called a trace). When an answer is wrong, you do not guess: you read the run from the top and find the first wrong step, the way you find the first wrong line on a shop bill.

The four kinds of step

  • User message: what the person asked, for example 1 user: What is the fee for CSE year 2?
  • Tool call: the model asks for a tool by name and gives the arguments, for example 2 call get_fee(branch="CSE", year=2). The model runs nothing itself
  • Tool result: what your program sent back after running the tool, for example 3 result: 85000
  • Final answer: what the model writes for the person, for example 4 answer: The fee is ₹85,000

What a run also records

  • The step count: the run above has 4 steps
  • Tokens: each step the model wrote (a tool call or the final answer) came from one model call, and shows the tokens that call used: 310 + 345 = 655 tokens
  • Time: every step after the first shows how long it took: 1.1 + 0.2 + 1.3 = 2.6 seconds
  • Model calls = tool calls + 1 final answer, when each model call asks for one tool. The run above made 2 model calls

The four checks, in order, on the steps the model wrote

  • Check 1, tool call: does the tool match the subject of the question? A timetable question needs get_timetable, not get_fee
  • Check 2, tool call: does every argument come from an earlier step? A year the user never gave is an invented argument, and it never raises an error
  • Check 3, the step after an error result: the model should retry, or say it could not check. A timeout is not the same as an empty search
  • Check 4, final answer: does it agree with the last tool result?
  • Stop at the first step that fails a check. Later wrong steps are usually consequences of it
  • The user message and the tool results are records. A false tool result is an ordinary bug in your own code, not a choice the model made

A quick first pass

  • Count the model calls, compare the final answer with the last tool result, and scan the results for the word error
  • These tell you that a run is wrong, not where it first went wrong. An invented argument hides from all three, so still read from the top

Try it

  • Read this second recorded run of the Campus Helpdesk, and write down the first wrong step and which check it fails:
  • 1 user: When is my class on Monday?
  • 2 call get_timetable(branch="MECH", day="Monday")
  • 3 result: Workshop at 9 am
  • 4 answer: Your class is the workshop at 9 am
  • Then write what that step should have been instead
  • Check yourself: the first wrong step is a tool call, and it fails check 2

Lesson quiz

Checked in your browser. Nothing is sent or saved.

5 questions

Question 1 · easy

In a recorded run, what is a tool call?

Question 2 · easy

A run has four steps: a user message, a tool call, a tool result and a final answer. Each model call asks for at most one tool. How many model calls did it make?

Question 3 · medium

Why is a quick first pass (count the model calls, compare the answer with the last result, scan for the word error) not enough?

Question 4 · medium

A tool result says the search timed out. What should the model's next step be?

Question 5 · hard

A student asks When is my class on Monday? and the next step is call get_timetable(branch="MECH", day="Monday"). The student never gave a branch. Which check does this step fail first?

When not to build an agentNext: What an AI engineer does: the role, the skills, the interview