- result
- RunResultBase
- RunResult
- RunResultStreaming
- current_agent
- current_turn
- max_turns
- final_output
- is_complete
- last_agent
- input
- new_items
- raw_responses
- input_guardrail_results
- output_guardrail_results
- tool_input_guardrail_results
- tool_output_guardrail_results
- context_wrapper
- last_response_id
- cancel
- stream_events
- release_agents
- final_output_as
- to_input_list
Results
RunResultBasedataclass
Bases:ABC
Source code insrc/agents/result.py
inputinstance-attribute
input:str|list[TResponseInputItem]The original input items i.e. the items before run() was called. This may be a mutatedversion of the input, if there are handoff input filters that mutate the input.
new_itemsinstance-attribute
new_items:list[RunItem]The new items generated during the agent run. These include things like new messages, toolcalls and their outputs, etc.
raw_responsesinstance-attribute
raw_responses:list[ModelResponse]The raw LLM responses generated by the model during the agent run.
input_guardrail_resultsinstance-attribute
input_guardrail_results:list[InputGuardrailResult]Guardrail results for the input messages.
output_guardrail_resultsinstance-attribute
output_guardrail_results:list[OutputGuardrailResult]Guardrail results for the final output of the agent.
tool_input_guardrail_resultsinstance-attribute
tool_input_guardrail_results:list[ToolInputGuardrailResult]Tool input guardrail results from all tools executed during the run.
tool_output_guardrail_resultsinstance-attribute
tool_output_guardrail_results:list[ToolOutputGuardrailResult]Tool output guardrail results from all tools executed during the run.
context_wrapperinstance-attribute
context_wrapper:RunContextWrapper[Any]The context wrapper for the agent run.
last_response_idproperty
Convenience method to get the response ID of the last model response.
release_agents
Release strong references to agents held by this result. After calling this method,accessingitem.agent orlast_agent may returnNone if the agent has been garbagecollected. Callers can use this when they are done inspecting the result and want toeagerly drop any associated agent graph.
Source code insrc/agents/result.py
final_output_as
A convenience method to cast the final output to a specific type. By default, the castis only for the typechecker. If you setraise_if_incorrect_type to True, we'll raise aTypeError if the final output is not of the given type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls | type[T] | The type to cast the final output to. | required |
raise_if_incorrect_type | bool | If True, we'll raise a TypeError if the final output is not ofthe given type. | False |
Returns:
| Type | Description |
|---|---|
T | The final output casted to the given type. |
Source code insrc/agents/result.py
to_input_list
to_input_list()->list[TResponseInputItem]Creates a new input list, merging the original input with all the new items generated.
Source code insrc/agents/result.py
RunResultdataclass
Bases:RunResultBase
Source code insrc/agents/result.py
inputinstance-attribute
input:str|list[TResponseInputItem]The original input items i.e. the items before run() was called. This may be a mutatedversion of the input, if there are handoff input filters that mutate the input.
new_itemsinstance-attribute
new_items:list[RunItem]The new items generated during the agent run. These include things like new messages, toolcalls and their outputs, etc.
raw_responsesinstance-attribute
raw_responses:list[ModelResponse]The raw LLM responses generated by the model during the agent run.
input_guardrail_resultsinstance-attribute
input_guardrail_results:list[InputGuardrailResult]Guardrail results for the input messages.
output_guardrail_resultsinstance-attribute
output_guardrail_results:list[OutputGuardrailResult]Guardrail results for the final output of the agent.
tool_input_guardrail_resultsinstance-attribute
tool_input_guardrail_results:list[ToolInputGuardrailResult]Tool input guardrail results from all tools executed during the run.
tool_output_guardrail_resultsinstance-attribute
tool_output_guardrail_results:list[ToolOutputGuardrailResult]Tool output guardrail results from all tools executed during the run.
context_wrapperinstance-attribute
context_wrapper:RunContextWrapper[Any]The context wrapper for the agent run.
last_response_idproperty
Convenience method to get the response ID of the last model response.
release_agents
Release strong references to agents held by this result. After calling this method,accessingitem.agent orlast_agent may returnNone if the agent has been garbagecollected. Callers can use this when they are done inspecting the result and want toeagerly drop any associated agent graph.
Source code insrc/agents/result.py
final_output_as
A convenience method to cast the final output to a specific type. By default, the castis only for the typechecker. If you setraise_if_incorrect_type to True, we'll raise aTypeError if the final output is not of the given type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls | type[T] | The type to cast the final output to. | required |
raise_if_incorrect_type | bool | If True, we'll raise a TypeError if the final output is not ofthe given type. | False |
Returns:
| Type | Description |
|---|---|
T | The final output casted to the given type. |
Source code insrc/agents/result.py
to_input_list
to_input_list()->list[TResponseInputItem]Creates a new input list, merging the original input with all the new items generated.
Source code insrc/agents/result.py
RunResultStreamingdataclass
Bases:RunResultBase
The result of an agent run in streaming mode. You can use thestream_events method toreceive semantic events as they are generated.
The streaming method will raise:- A MaxTurnsExceeded exception if the agent exceeds the max_turns limit.- A GuardrailTripwireTriggered exception if a guardrail is tripped.
Source code insrc/agents/result.py
177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 | |
final_outputinstance-attribute
The final output of the agent. This is None until the agent has finished running.
is_completeclass-attributeinstance-attribute
Whether the agent has finished running.
last_agentproperty
last_agent:Agent[Any]The last agent that was run. Updates as the agent run progresses, so the true last agentis only available after the agent run is complete.
inputinstance-attribute
input:str|list[TResponseInputItem]The original input items i.e. the items before run() was called. This may be a mutatedversion of the input, if there are handoff input filters that mutate the input.
new_itemsinstance-attribute
new_items:list[RunItem]The new items generated during the agent run. These include things like new messages, toolcalls and their outputs, etc.
raw_responsesinstance-attribute
raw_responses:list[ModelResponse]The raw LLM responses generated by the model during the agent run.
input_guardrail_resultsinstance-attribute
input_guardrail_results:list[InputGuardrailResult]Guardrail results for the input messages.
output_guardrail_resultsinstance-attribute
output_guardrail_results:list[OutputGuardrailResult]Guardrail results for the final output of the agent.
tool_input_guardrail_resultsinstance-attribute
tool_input_guardrail_results:list[ToolInputGuardrailResult]Tool input guardrail results from all tools executed during the run.
tool_output_guardrail_resultsinstance-attribute
tool_output_guardrail_results:list[ToolOutputGuardrailResult]Tool output guardrail results from all tools executed during the run.
context_wrapperinstance-attribute
context_wrapper:RunContextWrapper[Any]The context wrapper for the agent run.
last_response_idproperty
Convenience method to get the response ID of the last model response.
cancel
Cancel the streaming run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode | Literal['immediate', 'after_turn'] | Cancellation strategy:- "immediate": Stop immediately, cancel all tasks, clear queues (default)- "after_turn": Complete current turn gracefully before stopping * Allows LLM response to finish * Executes pending tool calls * Saves session state properly * Tracks usage accurately * Stops before next turn begins | 'immediate' |
Example
Note: After calling cancel(), you should continue consuming stream_events()to allow the cancellation to complete properly.
Source code insrc/agents/result.py
stream_eventsasync
stream_events()->AsyncIterator[StreamEvent]Stream deltas for new items as they are generated. We're using the types from theOpenAI Responses API, so these are semantic events: each event has atype field thatdescribes the type of the event, along with the data for that event.
This will raise:- A MaxTurnsExceeded exception if the agent exceeds the max_turns limit.- A GuardrailTripwireTriggered exception if a guardrail is tripped.
Source code insrc/agents/result.py
release_agents
Release strong references to agents held by this result. After calling this method,accessingitem.agent orlast_agent may returnNone if the agent has been garbagecollected. Callers can use this when they are done inspecting the result and want toeagerly drop any associated agent graph.
Source code insrc/agents/result.py
final_output_as
A convenience method to cast the final output to a specific type. By default, the castis only for the typechecker. If you setraise_if_incorrect_type to True, we'll raise aTypeError if the final output is not of the given type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls | type[T] | The type to cast the final output to. | required |
raise_if_incorrect_type | bool | If True, we'll raise a TypeError if the final output is not ofthe given type. | False |
Returns:
| Type | Description |
|---|---|
T | The final output casted to the given type. |
Source code insrc/agents/result.py
to_input_list
to_input_list()->list[TResponseInputItem]Creates a new input list, merging the original input with all the new items generated.