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,
McpCall,
ResponseCodeInterpreterToolCall,
ImageGenerationCall,
LocalShellCall,
dict[str, Any],
]
A type that represents a tool call item.
RunItem
module-attribute
RunItem: TypeAlias = Union[
MessageOutputItem,
HandoffCallItem,
HandoffOutputItem,
ToolCallItem,
ToolCallOutputItem,
CompactionItem,
ReasoningItem,
MCPListToolsItem,
MCPApprovalRequestItem,
MCPApprovalResponseItem,
CompactionItem,
ToolApprovalItem,
]
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 either an output item (i.e.
openai.types.responses.ResponseOutputItem or an input item
(i.e. openai.types.responses.ResponseInputItemParam).
release_agent
Release the strong reference to the agent while keeping a weak reference.
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
MessageOutputItem
dataclass
Bases: RunItemBase[ResponseOutputMessage]
Represents a message from the LLM.
Source code in src/agents/items.py
release_agent
Release the strong reference to the agent while keeping a weak reference.
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.
release_agent
Release the strong reference to the agent while keeping a weak reference.
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
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[Any]
Represents a tool call e.g. a function call or computer action call.
Source code in src/agents/items.py
release_agent
Release the strong reference to the agent while keeping a weak reference.
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[Any]
Represents the output of a tool call.
Source code in src/agents/items.py
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 the tool output into an input item for the next model turn.
Hosted tool outputs (e.g. shell/apply_patch) carry a status field for the SDK's
book-keeping, but the Responses API does not yet accept that parameter. Strip it from the
payload we send back to the model while keeping the original raw item intact.
Source code in src/agents/items.py
release_agent
Release the strong reference to the agent while keeping a weak reference.
Source code in src/agents/items.py
ReasoningItem
dataclass
Bases: RunItemBase[ResponseReasoningItem]
Represents a reasoning item.
Source code in src/agents/items.py
release_agent
Release the strong reference to the agent while keeping a weak reference.
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
MCPListToolsItem
dataclass
Bases: RunItemBase[McpListTools]
Represents a call to an MCP server to list tools.
Source code in src/agents/items.py
release_agent
Release the strong reference to the agent while keeping a weak reference.
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
MCPApprovalRequestItem
dataclass
Bases: RunItemBase[McpApprovalRequest]
Represents a request for MCP approval.
Source code in src/agents/items.py
release_agent
Release the strong reference to the agent while keeping a weak reference.
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
MCPApprovalResponseItem
dataclass
Bases: RunItemBase[McpApprovalResponse]
Represents a response to an MCP approval request.
Source code in src/agents/items.py
release_agent
Release the strong reference to the agent while keeping a weak reference.
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
CompactionItem
dataclass
Bases: RunItemBase[TResponseInputItem]
Represents a compaction item from responses.compact.
Source code in src/agents/items.py
raw_item
instance-attribute
The raw Responses item from the run. This will always be 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
release_agent
Release the strong reference to the agent while keeping a weak reference.
Source code in src/agents/items.py
ToolApprovalItem
dataclass
Bases: RunItemBase[Any]
Tool call that requires approval before execution.
Source code in src/agents/items.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
raw_item
instance-attribute
Raw tool call awaiting approval (function, hosted, shell, etc.).
tool_name
class-attribute
instance-attribute
Tool name for approval tracking; falls back to raw_item.name when absent.
name
property
Return the tool name from tool_name or raw_item (backwards compatible).
__post_init__
Populate tool_name from the raw item if not provided.
Source code in src/agents/items.py
__hash__
__eq__
to_input_item
to_input_item() -> TResponseInputItem
ToolApprovalItem should never be sent as input; raise to surface misuse.
Source code in src/agents/items.py
release_agent
Release the strong reference to the agent while keeping a weak reference.
Source code in src/agents/items.py
ModelResponse
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
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
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.
Accepts either plain values (stringified) or structured outputs using input_text/input_image/input_file shapes. Structured outputs may be provided as Pydantic models or dicts, or an iterable of such items.