Overview
TheAgentResult class encapsulates the complete result of an agent’s execution in non-streaming mode. It provides access to the updated thread, new messages, final output, structured output data, and execution telemetry.
Class Definition
execution is appended after the existing optional fields so existing positional
AgentResult(...) construction keeps the same argument order. In application
code, prefer reading fields by name from the object returned by agent.run(...).
Properties
Thread
The updated thread containing all messages including those added during this execution
List[Message]
List of new messages added during this execution (excludes pre-existing messages)
Optional[str]
The final assistant response content. None if no assistant message was generated
Optional[BaseModel]
When Returns
response_type is provided to agent.run(), this field contains a validated instance
of the Pydantic model. Internally, the agent uses the output-tool pattern: your schema
becomes a special tool, and when the LLM calls it, the arguments are validated against your model.None if response_type was not provided. See the
Structured Output Guide for complete usage.int
Number of structured output validation retry attempts. This is only relevant when
response_type and retry configuration are used.Optional[List[Dict[str, Any]]]
Validation retry details, including attempt numbers, validation errors, and response previews.
ExecutionDetails
Execution telemetry collected during this run, including:
events: orderedExecutionEventobjectsduration_ms: total execution timetotal_tokens: total token usage reported by the LLMtool_calls: structured tool call summaries with name, arguments, result or error, duration, and success
bool
Property that returns
True when the execution completed without any EXECUTION_ERROR events.Usage Examples
Basic Usage
Accessing Metrics
Working with Messages
Error Handling
Thread Management
Common Patterns
Conversation Loop
Result Analysis
Persisting Results
Structured Output Usage
When using structured output, access the validated data throughstructured_data:
Handling Errors
When structured output validation fails after all retries,StructuredOutputError is raised:
See Also
- Thread - Conversation management
- Agent - The main agent class
- RetryConfig - Retry configuration for structured output
- StructuredOutputError - Error when validation fails
- ExecutionEvent - Individual execution events used by streaming and
AgentResult.execution.events