Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/agents/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,20 @@ class ToolCallItem(RunItemBase[Any]):
title: str | None = None
"""Optional short display label if known at item creation time."""

@property
def tool_name(self) -> str | None:
"""Return the tool name from the raw item, if available."""
if isinstance(self.raw_item, dict):
return self.raw_item.get("name")
return getattr(self.raw_item, "name", None)

@property
def call_id(self) -> str | None:
"""Return the call identifier from the raw item, if available."""
if isinstance(self.raw_item, dict):
return self.raw_item.get("call_id") or self.raw_item.get("id")
return getattr(self.raw_item, "call_id", None) or getattr(self.raw_item, "id", None)


ToolCallOutputTypes: TypeAlias = Union[
FunctionCallOutput,
Expand All @@ -382,6 +396,14 @@ class ToolCallOutputItem(RunItemBase[Any]):

type: Literal["tool_call_output_item"] = "tool_call_output_item"

@property
def call_id(self) -> str | None:
"""Return the call identifier from the raw item, if available."""
if isinstance(self.raw_item, dict):
cid = self.raw_item.get("call_id") or self.raw_item.get("id")
return str(cid) if cid is not None else None
return getattr(self.raw_item, "call_id", None) or getattr(self.raw_item, "id", None)

def to_input_item(self) -> TResponseInputItem:
"""Converts the tool output into an input item for the next model turn.

Expand Down