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 in JavaScript. You also saw how to extract the agent's final output from the result object. In this lesson, we'll 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'll know how to inspect and interpret the different properties of the result object, including the final output, the original input, the last agent that ran, and new items generated during the run. You'll 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, you receive a RunResult object. This object provides detailed information about the agent's execution.
Some of the most relevant properties include:
finalOutput: 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 an output type.input: The original input or prompt provided to the agent at the start of the run.lastAgent: The agent instance that produced the final output. This is especially useful in workflows involving multiple agents or handoffs.newItems: An array 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.history: The conversation history, including all messages exchanged during the run.
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.
Creating An Agent For Our Examples
For the examples in this lesson, we'll use a simple travel assistant agent. Here's how you can define and run this agent in JavaScript:
This code creates an agent named "Travel Genie" and runs it with a sample query. The result of the run is stored in the result object, which we'll explore in detail in the following sections.
