Skip to content

fix: expose original FunctionTool callable#3637

Open
he-yufeng wants to merge 1 commit into
openai:mainfrom
he-yufeng:fix/function-tool-original-func
Open

fix: expose original FunctionTool callable#3637
he-yufeng wants to merge 1 commit into
openai:mainfrom
he-yufeng:fix/function-tool-original-func

Conversation

@he-yufeng

Copy link
Copy Markdown

Summary

Adds a stable FunctionTool.func property for tools created with @function_tool.

The original callable was previously only reachable through private closure-walking on the generated invoker. This stores it on the tool as internal _func metadata and exposes it through a read-only property, so downstream SDKs and tests can introspect the wrapped function without depending on closure internals.

This intentionally does not make FunctionTool callable and does not use functools.update_wrapper. PR #2146 showed that wrapper metadata can interact badly with pytest collection for tool functions whose names start with test_; this version keeps the runtime shape unchanged except for the new property.

Test plan

  • python -m py_compile src\agents\tool.py tests\test_function_tool.py
  • python -m ruff check src\agents\tool.py tests\test_function_tool.py
  • python -m ruff format --check src\agents\tool.py tests\test_function_tool.py
  • $env:PYTHONPATH='src'; python -m pytest tests\test_function_tool.py -q
  • $env:PYTHONPATH='src'; python -c "from agents import function_tool; add=lambda a,b=1:a+b; tool=function_tool(add); assert tool.func is add; assert not callable(tool); print('ok')"

Issue number

Closes #3381

Checks

  • I've added new tests (if relevant)
  • I've added/updated the relevant documentation
  • I've run make lint and make format
  • I've made sure tests pass

@seratch seratch added duplicate This issue or pull request already exists feature:core labels Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists feature:core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide stable public access to the underlying function on FunctionTool

2 participants