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,
ToolSearchCallItem,
ToolSearchOutputItem,
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
ToolSearchCallItem
dataclass
Bases: RunItemBase[ToolSearchCallRawItem]
Represents a Responses API tool search request emitted by the model.
Source code in src/agents/items.py
raw_item
instance-attribute
The raw tool search call item, preserving partial dict snapshots when needed.
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
ToolSearchOutputItem
dataclass
Bases: RunItemBase[ToolSearchOutputRawItem]
Represents the output of a Responses API tool search.
Source code in src/agents/items.py
raw_item
instance-attribute
The raw tool search output item, preserving partial dict snapshots when needed.
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
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
description
class-attribute
instance-attribute
Optional tool description if known at item creation time.
title
class-attribute
instance-attribute
Optional short display label if known at item creation time.
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
476 477 478 479 480 481 482 483 484 485 486 487 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 | |
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.
tool_namespace
class-attribute
instance-attribute
Optional Responses API namespace for function-tool approvals.
tool_lookup_key
class-attribute
instance-attribute
Canonical function-tool lookup metadata when the approval targets a function tool.
name
property
Return the tool name from tool_name or raw_item (backwards compatible).
qualified_name
property
Return a display-friendly tool name, collapsing synthetic deferred namespaces.
__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.
request_id
class-attribute
instance-attribute
The transport request ID for this model call, if provided by the model SDK.
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
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 | |
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.
Source code in src/agents/items.py
coerce_tool_search_call_raw_item
Prefer the typed SDK tool_search call model while tolerating partial snapshots.
Source code in src/agents/items.py
coerce_tool_search_output_raw_item
Prefer the typed SDK tool_search output model while tolerating partial snapshots.