Skip to content

add get_tool_call_name method to extract tool name from ToolCallItem #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions src/agents/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,15 @@ def tool_call_output_item(
"output": output,
"type": "function_call_output",
}

@classmethod
def get_tool_call_name(cls, tool_call: ToolCallItem) -> str:
"""Returns the tool name from a ToolCallItem."""
return tool_call.raw_item.name
Comment on lines +253 to +255
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just add this to ToolCallItem instead? so you can just do item.tool_name

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I used it inside ItemHelper, like how you made different methods that take out the agent’s message.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, those are for Responses APIitems, to which we cannot add methods because they are not part of this SDK (they are in the openai sdk). Doing item.tool_name is far better devx than ItemHelper.get_tool_call_name(item)


@classmethod
def tool_response_output(
cls, tool_call: ToolCallOutputItem
):
"""Extracts and returns the output from a ToolCallOutputItem."""
return tool_call.output