diff --git a/src/agents/items.py b/src/agents/items.py index 9d6219f37d..349a21404f 100644 --- a/src/agents/items.py +++ b/src/agents/items.py @@ -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, @@ -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.