Results
RunResultBase
dataclass
Bases: ABC
Source code in src/agents/result.py
input
instance-attribute
input: str | list[TResponseInputItem]
The original input items i.e. the items before run() was called. This may be a mutated version of the input, if there are handoff input filters that mutate the input.
new_items
instance-attribute
new_items: list[RunItem]
The new items generated during the agent run. These include things like new messages, tool calls and their outputs, etc.
raw_responses
instance-attribute
raw_responses: list[ModelResponse]
The raw LLM responses generated by the model during the agent run.
input_guardrail_results
instance-attribute
input_guardrail_results: list[InputGuardrailResult]
Guardrail results for the input messages.
output_guardrail_results
instance-attribute
output_guardrail_results: list[OutputGuardrailResult]
Guardrail results for the final output of the agent.
final_output_as
A convenience method to cast the final output to a specific type. By default, the cast
is only for the typechecker. If you set raise_if_incorrect_type
to True, we'll raise a
TypeError 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 of the given type. |
False
|
Returns:
Type | Description |
---|---|
T
|
The final output casted to the given type. |
Source code in src/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 in src/agents/result.py
RunResult
dataclass
RunResultStreaming
dataclass
Bases: RunResultBase
The result of an agent run in streaming mode. You can use the stream_events
method to
receive 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 in src/agents/result.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
final_output
instance-attribute
The final output of the agent. This is None until the agent has finished running.
is_complete
class-attribute
instance-attribute
Whether the agent has finished running.
last_agent
property
last_agent: Agent[Any]
The last agent that was run. Updates as the agent run progresses, so the true last agent is only available after the agent run is complete.
stream_events
async
stream_events() -> AsyncIterator[StreamEvent]
Stream deltas for new items as they are generated. We're using the types from the
OpenAI Responses API, so these are semantic events: each event has a type
field that
describes 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.