Items
TResponse
module-attribute
TResponse = Response
A type alias for the Response type.
TResponseInputItem
module-attribute
TResponseInputItem = ResponseInputItemParam
A type alias for the ResponseInputItemParam type.
TResponseOutputItem
module-attribute
TResponseOutputItem = ResponseOutputItem
A type alias for the ResponseOutputItem type.
TResponseStreamEvent
module-attribute
TResponseStreamEvent = ResponseStreamEvent
A type alias for the ResponseStreamEvent type.
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/cai/sdk/agents/items.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
raw_item
instance-attribute
raw_item: T
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/cai/sdk/agents/items.py
58 59 60 61 62 63 64 65 66 67 |
|
MessageOutputItem
dataclass
Bases: RunItemBase[ResponseOutputMessage]
Represents a message from the LLM.
Source code in src/cai/sdk/agents/items.py
70 71 72 73 74 75 76 77 |
|
raw_item
instance-attribute
raw_item: ResponseOutputMessage
The raw response output message.
to_input_item
to_input_item() -> TResponseInputItem
Converts this item into an input item suitable for passing to the model.
Source code in src/cai/sdk/agents/items.py
58 59 60 61 62 63 64 65 66 67 |
|
HandoffCallItem
dataclass
Bases: RunItemBase[ResponseFunctionToolCall]
Represents a tool call for a handoff from one agent to another.
Source code in src/cai/sdk/agents/items.py
80 81 82 83 84 85 86 87 |
|
raw_item
instance-attribute
raw_item: ResponseFunctionToolCall
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/cai/sdk/agents/items.py
58 59 60 61 62 63 64 65 66 67 |
|
HandoffOutputItem
dataclass
Bases: RunItemBase[TResponseInputItem]
Represents the output of a handoff.
Source code in src/cai/sdk/agents/items.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
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/cai/sdk/agents/items.py
58 59 60 61 62 63 64 65 66 67 |
|
ToolCallItem
dataclass
Bases: RunItemBase[ToolCallItemTypes]
Represents a tool call e.g. a function call or computer action call.
Source code in src/cai/sdk/agents/items.py
115 116 117 118 119 120 121 122 |
|
to_input_item
to_input_item() -> TResponseInputItem
Converts this item into an input item suitable for passing to the model.
Source code in src/cai/sdk/agents/items.py
58 59 60 61 62 63 64 65 66 67 |
|
ToolCallOutputItem
dataclass
Bases: RunItemBase[Union[FunctionCallOutput, ComputerCallOutput]]
Represents the output of a tool call.
Source code in src/cai/sdk/agents/items.py
125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
raw_item
instance-attribute
raw_item: FunctionCallOutput | ComputerCallOutput
The raw item from the model.
output
instance-attribute
output: Any
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/cai/sdk/agents/items.py
58 59 60 61 62 63 64 65 66 67 |
|
ReasoningItem
dataclass
Bases: RunItemBase[ResponseReasoningItem]
Represents a reasoning item.
Source code in src/cai/sdk/agents/items.py
140 141 142 143 144 145 146 147 |
|
raw_item
instance-attribute
raw_item: ResponseReasoningItem
The raw reasoning item.
to_input_item
to_input_item() -> TResponseInputItem
Converts this item into an input item suitable for passing to the model.
Source code in src/cai/sdk/agents/items.py
58 59 60 61 62 63 64 65 66 67 |
|
ModelResponse
dataclass
Source code in src/cai/sdk/agents/items.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
output
instance-attribute
output: list[TResponseOutputItem]
A list of outputs (messages, tool calls, etc) generated by the model
referenceable_id
instance-attribute
referenceable_id: str | None
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.
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/cai/sdk/agents/items.py
174 175 176 177 178 179 |
|
ItemHelpers
Source code in src/cai/sdk/agents/items.py
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 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
extract_last_content
classmethod
extract_last_content(message: TResponseOutputItem) -> str
Extracts the last text content or refusal from a message.
Source code in src/cai/sdk/agents/items.py
183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
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/cai/sdk/agents/items.py
197 198 199 200 201 202 203 204 205 |
|
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/cai/sdk/agents/items.py
207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
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/cai/sdk/agents/items.py
221 222 223 224 225 226 227 228 |
|
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/cai/sdk/agents/items.py
230 231 232 233 234 235 236 237 |
|
tool_call_output_item
classmethod
tool_call_output_item(
tool_call: ResponseFunctionToolCall, output: str
) -> FunctionCallOutput
Creates a tool call output item from a tool call and its output.
Source code in src/cai/sdk/agents/items.py
239 240 241 242 243 244 245 246 247 248 |
|