fix(tool): resolve default failure handler at invoke time#2460
Merged
seratch merged 2 commits intoFeb 10, 2026
Merged
Conversation
Contributor
Author
|
Follow-up fix pushed in 6e00ced for CI Root cause:
Fix:
Local verification after the fix:
|
seratch
approved these changes
Feb 10, 2026
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
Fixes #945 by resolving the default tool failure handler at invocation time instead of binding it at decorator definition time.
This allows instrumentation libraries (for example Sentry) to patch
default_tool_error_functionafter import and still have function tools use the patched handler.What changed
function_tool(..., failure_error_function=...)to distinguish:None(re-raise exceptions)function_toolto resolvedefault_tool_error_functioninside the invocation path.default_tool_error_functionafter creating the tool still affects tool failure handling.Tests
uv run ruff check src/agents/tool.py tests/test_function_tool.pyuv run mypy src/agents/tool.py tests/test_function_tool.pyuv run pytest tests/test_function_tool.py -qmake format-checkuv run python -m trace --count --coverdir /tmp/openai_agents_945_trace.Ig3U8E --module pytest tests/test_function_tool.py -qCoverage note: changed branches in
src/agents/tool.pyare all hit by tests (including omitted/default, explicitNone, and explicit custom handler paths).