feat: expose the wrapped callable on FunctionTool (closes #3381)#3692
Open
fede-kamel wants to merge 2 commits into
Open
feat: expose the wrapped callable on FunctionTool (closes #3381)#3692fede-kamel wants to merge 2 commits into
fede-kamel wants to merge 2 commits into
Conversation
Add a public FunctionTool.function attribute holding the original Python callable that @function_tool wrapped (None for tools not backed by a plain function). Gives code outside the runtime a stable hook to introspect, directly test, or re-run the underlying function without a ToolContext/JSON round-trip. Closes openai#3381
dbd627d to
a76a6da
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a public
FunctionTool.functionattribute that holds the original Python callable wrapped by@function_tool.Today the wrapped function is only reachable by walking the closure of
on_invoke_tool(...on_invoke_tool._invoke_tool_impl.__closure__), which is brittle and got an extra hop in 0.16 with the failure-handling indirection. This gives code outside the Agents runtime a stable hook to introspect, directly test, or re-run a tool's body without constructing aToolContextand doing a JSON encode/decode cycle.Nonefor tools not backed by a plain function (agent-as-tool, hosted-tool wrappers), so the attribute is always present and safe to check.FunctionTool.This revives the approach from #2146 (which was closed only over an unrelated pytest fixture-collection regression, not the concept). Happy to rename to
funcor also wire__wrapped__forinspect.unwrap()if preferred.Test plan
tests/test_function_tool_exposes_function.py: sync + async tools expose a runnable.function; directly-constructed tools exposeNone.tests/test_function_tool.py(49 tests) still pass — no regression.make format,make lint,make typecheck(mypy + pyright) clean.Issue number
Closes #3381
Checks
make lintandmake format