Inspecting and Understanding Agent Result Properties
Introduction And Lesson Overview
Welcome back! In the previous lesson, you learned how to define and run your first OpenAI agent using the Agents SDK. You also saw how to extract the agent’s final output from the result object. In this lesson, we will take a closer look at the result object that is returned after running an agent. Understanding the structure and properties of this object is key to building more advanced applications, debugging your agent’s behavior, and making the most of the SDK’s features.
By the end of this lesson, you will know how to inspect and interpret the different attributes of the result object, including the final output, the original input, the last agent that ran, new items generated during the run, and the raw responses from the language model. You will also see how these properties can help you understand what happened during the agent’s run and how to use this information in your own projects.
The Structure Of The Result Object
When you run an agent synchronously (using Runner.run_sync) or asynchronously (using Runner.run), you receive a RunResult object. If you run an agent in streamed mode (using Runner.run_streamed), you receive a RunResultStreaming object instead. Both types of result objects provide detailed information about the agent’s execution.
Some of the most relevant properties include:
final_output: The final output produced by the last agent that ran. Its type can vary depending on the agent’s configuration—it may be a string or a more complex object if the agent specifies anoutput_type.input: The original input or prompt provided to the agent at the start of the run.last_agent: The agent instance that produced the final output. This is especially useful in workflows involving multiple agents or handoffs.new_items: A list of items generated during the run, such as messages, tool calls, or handoffs. These items provide a step-by-step record of the agent’s reasoning and actions.raw_responses: The raw outputs from the language model for each step in the agent loop, including generated text, tool calls, and finish reasons.
By inspecting these properties, you gain a comprehensive view of the agent’s execution, including the input, output and intermediate steps. This structure is designed to support both simple and advanced use cases, from basic logging to complex multi-agent workflows.
