agent.run(), it returns an AgentResult containing the complete execution outcome. The result provides access to messages, token usage, stop reasons, execution metrics, and any errors that occurred during the run.
Why inspect results:
- Understand Completion - Check stop reasons to determine if the agent finished successfully, hit limits, stalled, or failed
- Access Outputs - Retrieve final responses, intermediate messages, and tool call history from the conversation
- Track Resources - Monitor token usage, estimated costs, and execution steps for optimization and budgeting
Stop Reasons
Thestop_reason tells you why the agent stopped:
Accessing Messages
The conversation history is available inresult.messages:
Token Usage and Cost
Track resource consumption:Error Handling
Checkfailed and stop_reason together for complete error handling:
Streaming Events
Useagent.stream() when you need real-time visibility into execution:
event.events, with helpers for filtering:
Thread Snapshot
The result contains a snapshot of the thread state at completion:result.thread gives you the precise state after that specific run.
See the SDK reference for complete AgentResult properties.
