OpenAI Agents SDKopenai-agents 0.22 · Python 3.10+
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
25 small wins to finish your pathNext lesson

Seeing what it did

When an agent gives a strange answer, the question is always the same: what did it actually do? Everything you need is already on the result.

python
for item in result.new_items:
    if item.type == "tool_call_item":
        print(f"asked for   {item.raw_item.name}({item.raw_item.arguments})")
    elif item.type == "tool_call_output_item":
        print(f"tool said   {item.output}")
    elif item.type == "message_output_item":
        print(f"replied     {ItemHelpers.text_message_output(item)}")
Example
print("what the run actually did")
print("-" * 46)
for item in result.new_items:
    if item.type == "tool_call_item":
        print(f"asked for   {item.raw_item.name}({item.raw_item.arguments})")
    elif item.type == "tool_call_output_item":
        print(f"tool said   {item.output}")
    elif item.type == "message_output_item":
        print(f"replied     {ItemHelpers.text_message_output(item)}")
print("-" * 46)
print("model calls:", len(result.raw_responses))

Eleven lines and you can read a run like a transcript. This is the first thing to write when an agent starts behaving oddly, and it needs nothing but the result you already have.

The three questions it answers

QuestionWhat to look at
Why did it pick that tool?the arguments it sent, and that tool's description
Why did it not use a tool?whether the tool was in the list at all
Why is the answer wrong?what the tool actually returned, above the reply

Most agent bugs are one of those three, and all three are visible in the transcript above. The model is rarely the problem; the description it was given usually is.

The hosted version

OpenAI also records runs for you, with timing and token counts, in a dashboard. It is on by default and this course turns it off, because it needs a key and there is nothing to send from a browser.

python
from agents import set_tracing_disabled

set_tracing_disabled(True)     # what this course does

On your own machine, with a key in the environment, take that line out and every run appears at platform.openai.com under Traces, with the same items you printed above plus how long each took and what it cost.

It sends your data
Tracing sends your prompts and your tool arguments to a hosted service. That is a decision worth making deliberately rather than by leaving a default alone, which is the other reason this course names it.
Try it yourself
  • Print len(result.raw_responses) and compare it with the item count.
  • Add a second tool call and read the transcript again.
  • Print item.raw_item for a tool call and see the exact JSON the model produced.

You understood something today that you didn't yesterday.