Items
TResponse
module-attribute
A type alias for the Response type from the OpenAI SDK.
TResponseInputItem
module-attribute
A type alias for the ResponseInputItemParam type from the OpenAI SDK.
TResponseOutputItem
module-attribute
A type alias for the ResponseOutputItem type from the OpenAI SDK.
TResponseStreamEvent
module-attribute
A type alias for the ResponseStreamEvent type from the OpenAI SDK.
ToolCallItemTypes
module-attribute
ToolCallItemTypes: TypeAlias = Union[
ResponseFunctionToolCall,
ResponseComputerToolCall,
ResponseFileSearchToolCall,
ResponseFunctionWebSearch,
]
A type that represents a tool call item.
RunItem
module-attribute
RunItem: TypeAlias = Union[
MessageOutputItem,
HandoffCallItem,
HandoffOutputItem,
ToolCallItem,
ToolCallOutputItem,
ReasoningItem,
]
An item generated by an agent.
RunItemBase
dataclass
Bases: Generic[T]
, ABC
Source code in src/agents/items.py
raw_item
instance-attribute
The raw Responses item from the run. This will always be a either an output item (i.e.
openai.types.responses.ResponseOutputItem
or an input item
(i.e. openai.types.responses.ResponseInputItemParam
).
to_input_item
to_input_item() -> TResponseInputItem
Converts this item into an input item suitable for passing to the model.
Source code in src/agents/items.py
MessageOutputItem
dataclass
Bases: RunItemBase[ResponseOutputMessage]
Represents a message from the LLM.
Source code in src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
Converts this item into an input item suitable for passing to the model.
Source code in src/agents/items.py
HandoffCallItem
dataclass
Bases: RunItemBase[ResponseFunctionToolCall]
Represents a tool call for a handoff from one agent to another.
Source code in src/agents/items.py
raw_item
instance-attribute
The raw response function tool call that represents the handoff.
to_input_item
to_input_item() -> TResponseInputItem
Converts this item into an input item suitable for passing to the model.
Source code in src/agents/items.py
HandoffOutputItem
dataclass
Bases: RunItemBase[TResponseInputItem]
Represents the output of a handoff.
Source code in src/agents/items.py
raw_item
instance-attribute
raw_item: TResponseInputItem
The raw input item that represents the handoff taking place.
to_input_item
to_input_item() -> TResponseInputItem
Converts this item into an input item suitable for passing to the model.
Source code in src/agents/items.py
ToolCallItem
dataclass
Bases: RunItemBase[ToolCallItemTypes]
Represents a tool call e.g. a function call or computer action call.
Source code in src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
Converts this item into an input item suitable for passing to the model.
Source code in src/agents/items.py
ToolCallOutputItem
dataclass
Bases: RunItemBase[Union[FunctionCallOutput, ComputerCallOutput]]
Represents the output of a tool call.
Source code in src/agents/items.py
raw_item
instance-attribute
The raw item from the model.
output
instance-attribute
The output of the tool call. This is whatever the tool call returned; the raw_item
contains a string representation of the output.
to_input_item
to_input_item() -> TResponseInputItem
Converts this item into an input item suitable for passing to the model.
Source code in src/agents/items.py
ReasoningItem
dataclass
Bases: RunItemBase[ResponseReasoningItem]
Represents a reasoning item.
Source code in src/agents/items.py
to_input_item
to_input_item() -> TResponseInputItem
Converts this item into an input item suitable for passing to the model.
Source code in src/agents/items.py
ModelResponse
dataclass
Source code in src/agents/items.py
output
instance-attribute
output: list[TResponseOutputItem]
A list of outputs (messages, tool calls, etc) generated by the model
response_id
instance-attribute
An ID for the response which can be used to refer to the response in subsequent calls to the
model. Not supported by all model providers.
If using OpenAI models via the Responses API, this is the response_id
parameter, and it can
be passed to Runner.run
.
to_input_items
to_input_items() -> list[TResponseInputItem]
Convert the output into a list of input items suitable for passing to the model.
Source code in src/agents/items.py
ItemHelpers
Source code in src/agents/items.py
extract_last_content
classmethod
extract_last_content(message: TResponseOutputItem) -> str
Extracts the last text content or refusal from a message.
Source code in src/agents/items.py
extract_last_text
classmethod
extract_last_text(
message: TResponseOutputItem,
) -> str | None
Extracts the last text content from a message, if any. Ignores refusals.
Source code in src/agents/items.py
input_to_new_input_list
classmethod
input_to_new_input_list(
input: str | list[TResponseInputItem],
) -> list[TResponseInputItem]
Converts a string or list of input items into a list of input items.
Source code in src/agents/items.py
text_message_outputs
classmethod
text_message_outputs(items: list[RunItem]) -> str
Concatenates all the text content from a list of message output items.
Source code in src/agents/items.py
text_message_output
classmethod
text_message_output(message: MessageOutputItem) -> str
Extracts all the text content from a single message output item.
Source code in src/agents/items.py
tool_call_output_item
classmethod
Creates a tool call output item from a tool call and its output.