Skip to content

enhancement: Add tool_name to ToolContext to support shared tool handlers #1043

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 4 commits into
base: main
Choose a base branch
from

Conversation

vrtnis
Copy link
Contributor

@vrtnis vrtnis commented Jul 9, 2025

This adds a tool_name field to ToolContext, which gets passed into the on_invoke_tool handler. Helpful for scenarios where we dynamically register multiple tools that all share a single generic handler e.g.in multi-agent setups.

As such, by including the name of the tool that was invoked, the handler can now easily branch logic or route requests accordingly.

Resolves #1030

All tests pass. and here is a script to test it out https://gist.github.com/vrtnis/ca354244f7a5ecd9a73c0a2d34cb194b

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

Thanks for quickly working on this!

@seratch seratch added enhancement New feature or request feature:core labels Jul 10, 2025
@vrtnis
Copy link
Contributor Author

vrtnis commented Jul 10, 2025

Thanks for the thoughtful feedback @seratch! I've pushed an update that addresses it..if any changes are needed further, please lmk!

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

Once the added ### Tool context document section is deleted and #1048 gets merged, this looks good to me.

@rm-openai Can you take a quick look and share thoughts if you have any?

@seratch seratch requested a review from rm-openai July 10, 2025 06:41
Co-authored-by: Kazuhiro Sera <seratch@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature:core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tool_name to ToolContext for generic tool handlers
2 participants