InfraLoka AcademyPathwayAI
PathwayAI

Module 3 · Chapter 3: The first agent

Reading an agent's trace

4 min read5 min readReviewed 26 October 2026

In short

An agent's final report is a claim; its execution trace is the evidence. For every important claim, find the tool calls and their output in the trace, and record the turns and cost of every run.

After this lesson you can

  • Read an execution trace to see what the agent actually did
  • Match a claim of done against the output of the commands the agent ran

Terms in this lesson

Understand

Every time an agent works, it produces two things: a report at the end, and an execution trace along the way. The report is the model's writing about what it believes happened. The trace is an ordered record of what actually happened: every model message, every tool call with its input, every result or error that came back, and the cost and number of turns.

The two often match, but not always. A model can report "all tests pass" when the last test it ran still failed, or it never ran it at all. A model can write "I checked every file" when it opened three out of twenty. This is not deliberate lying; the model writes what seems a fitting end to the task. That is why the report is a claim, and the trace is evidence.

Reading a trace need not be complicated. Start from the end: what does the report claim? Then find in the trace the tool calls that should prove that claim, and read their output yourself. If the report says tests pass, find the last test output. If it says five files were changed, count the edit-file tool calls. If the evidence is not there, the claim is not proven, however confident the sentence.

Besides matching claims, a trace tells you three other useful things:

  • Wasted turns. A search repeated with the same words, a file read twice, or a tool that keeps returning the same error. This signals that the goal or a tool description needs fixing.
  • Touches nobody asked for. Files or folders opened that were not relevant, especially those holding personal data or secrets. This signals that permissions need narrowing.
  • Cost per task. The number of turns, tokens in and out, and the cost estimate, including the cost of subagents the main agent calls. Record these numbers for every run; that is how you know whether a prompt change made the agent cheaper or more wasteful.

For one run, reading the trace does feel slow. But this habit is what lets you trust an agent later. After a few dozen runs you will know the normal pattern, and an unusual trace stands out at once. The next step is systematic evaluation: a set of test tasks rerun every time something changes. That is the project at the end of this phase.

A step specific to Anthropic: check the latest version.

As a worked example, the Claude Agent SDK for Python streams the trace as a series of messages from query(). AssistantMessage holds the model's writing and its tool requests; the ResultMessage at the end holds subtype (success or the kind of error), num_turns, duration_ms, total_cost_usd and usage (input tokens, output tokens and cache tokens):

import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage, ResultMessage

async def main():
    options = ClaudeAgentOptions(tools=["Read", "Glob", "Grep"], allowed_tools=["Read", "Glob", "Grep"], permission_mode="dontAsk", max_turns=12)
    async for message in query(prompt="I need a list of decisions with their source file names.", options=options):
        if isinstance(message, AssistantMessage):
            print(message)
        if isinstance(message, ResultMessage):
            print(message.subtype, message.num_turns, message.duration_ms)
            print(message.total_cost_usd, message.usage)

asyncio.run(main())

As in the previous lesson: tools makes only three read tools available, allowed_tools lets them run without asking, and permission_mode="dontAsk" refuses any other call that would ask. Without tools, dontAsk alone still lets through calls that need no approval, such as read-only shell commands and starting a subagent. For agents that use subagents, usage covers only the main loop; read model_usage, which covers the whole tree of calls.

Save those messages to a log file per run, without secrets, so they can be reread and compared. total_cost_usd is the library's estimate; for the official bill, use the provider's report. A step specific to Anthropic; check the latest version in its documentation, because message and field names can change.

Worked example

Before

The prompt

Is the task done?

What came back

Weak output: Yes, the task is done. I fixed the date function and all tests pass.

After

The prompt

Goal: I want to verify the claim "all tests pass" in your report. Material: the trace of this run. Limits: do not run anything else; only quote from the trace. Shape: paste the last test command you ran and its output as is, then list the files you changed with the tool that changed them. Check: if there is no test output in the trace, write "no evidence".

What came back

The last test command in the trace ran before the second change to the date function. Its output: one test failed. After the second change, the tests were not run again. For the claim "all tests pass": no evidence. Files changed: one, through the edit-file tool, twice.

What changed

  • The first question only asks for the report again, and the model repeats its claim.
  • The second asks for quotes from the trace and allows the answer "no evidence".
  • Next step: run the tests yourself, or have the agent run them and paste the output.

Common mistake

Mistake
Copying the agent's final report into team notes as the work status, without looking at its trace.
Why it hurts
An unproven claim becomes a "fact" in the team notes. The next person builds on it, and the mistake only surfaces once it reaches users, far from where it began.
Do this instead
For every important claim in the report, find its evidence in the trace: command output, files actually changed. Write the status with its evidence, not just the agent's sentence.

Try

The agent's report says: "I checked all twenty contracts and found no penalty clause." What is the best evidence for that claim?

You see this pattern in a trace. What does it mean?

Take home

Reading the trace after every run

  • I find evidence in the trace for every important claim
  • I look for wasted turns and unrequested touches
  • I record turns, tokens and cost per run
  • Trace logs are stored without secrets
  • Status in team notes always comes with its evidence

An exercise for your agent's next run: before reading its report, write down three claims you expect to see, for example "tests pass", "two files changed", "no file outside the folder was touched". Then open the trace and look for evidence for all three. Note how many claims were proven, how many had no evidence and how many turned out wrong. After ten runs, those numbers give an honest picture of how far your agent's reports can be trusted, and which parts you always need to check yourself.

What went wrong for us

Incident, October 2026

A green pipeline that replaced nothing

Context
Our deploy pipeline backs up the database, then swaps the app containers for the new version.
What happened
The backup step read its input wrongly and swallowed the rest of the script. The container swap never ran, yet the pipeline still reported success.
Impact
Several releases we thought were live had never been installed.
Root cause
The script did not stop when a step failed, and nothing checked which version was really running after the deploy.
What we did
The backup step was fixed so it no longer reads the script's input, and the pending releases were reinstalled. One app was left for its owner to redeploy.
The guard we keep now
Every step checks its exit code, and the pipeline ends by checking the version of the image that is running.

The lessonGreen means the script finished; check for yourself that the change is live.

What it means for your workA "success" report from automation does not mean the result arrived. Check the end result yourself, such as whether the e-mail was really received.

Sources