Skip to content

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 <[email protected]>
@rm-openai rm-openai merged commit befe19d into openai:main Jul 14, 2025
5 checks passed
rm-openai added a commit that referenced this pull request Jul 14, 2025
rm-openai added a commit that referenced this pull request Jul 14, 2025
… tool handlers (#1043)" (#1105)

Original commit changeset: befe19d

causing test failures, so reverting
rm-openai pushed a commit that referenced this pull request Jul 15, 2025
This is a follow-up to pr #1043 The original changes were reverted due
to missing updates in RealtimeSession, which caused runtime test
failures.

This PR:

- Reapplies the `tool_name` and `tool_call_id` additions to
`ToolContext`.
- Updates `RealtimeSession._handle_tool_call` to instantiate
`ToolContext` with `tool_name=event.name` and
`tool_call_id=event.call_id`.
- Adjusts tests as needed so that all 533 tests (including old-version
Python 3.9) pass cleanly.

Closes #1030

---------

Co-authored-by: Kazuhiro Sera <[email protected]>
seratch added a commit that referenced this pull request Jul 21, 2025
This pull request adds a new script for docs, which generates missing
`ref/**/*.md` files. The script can be executed when you run `make
build-docs` command. The script does not do:
- overwrite the existing ones
- create files for _XXX.py and `__init__.py`

Note that the title part is generated like `tool_context` to `Tool
Context`. `openai_provider` will be `Openai Provider`, so some of them
needs a little manual work to adjust.

The direct need is to add `tool_context.md` for
#1043 but it should
be useful for future maintenance.
vcshih pushed a commit to veris-ai/openai-agents-python that referenced this pull request Aug 15, 2025
This pull request adds a new script for docs, which generates missing
`ref/**/*.md` files. The script can be executed when you run `make
build-docs` command. The script does not do:
- overwrite the existing ones
- create files for _XXX.py and `__init__.py`

Note that the title part is generated like `tool_context` to `Tool
Context`. `openai_provider` will be `Openai Provider`, so some of them
needs a little manual work to adjust.

The direct need is to add `tool_context.md` for
openai#1043 but it should
be useful for future maintenance.
gold-crow-997 added a commit to gold-crow-997/open-ai-agent that referenced this pull request Sep 11, 2025
This pull request adds a new script for docs, which generates missing
`ref/**/*.md` files. The script can be executed when you run `make
build-docs` command. The script does not do:
- overwrite the existing ones
- create files for _XXX.py and `__init__.py`

Note that the title part is generated like `tool_context` to `Tool
Context`. `openai_provider` will be `Openai Provider`, so some of them
needs a little manual work to adjust.

The direct need is to add `tool_context.md` for
openai/openai-agents-python#1043 but it should
be useful for future maintenance.
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

3 participants