Repository navigation
Conversation
5 tasks done
GradioToolWrapper.__init__ never ran the base Tool initializer (nor set is_initialized like LangChainToolWrapper does), so calling the wrapped tool raised AttributeError in Tool.__call__. Set is_initialized on construction so the wrapper completes the Tool lifecycle and delegates to the gradio tool's run method. Add a regression test covering Tool.from_gradio with a local gradio-style tool. Fixes huggingface#2944. Signed-off-by: Kylinny <64238008+Kylinny@users.noreply.github.com>
Kylinny
force-pushed
the
fix-from-gradio-is-initialized
branch
from
October 10, 2026 13:59
b90ce96 to
d447faa
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.
What
Tool.from_gradiobuilds aGradioToolWrapperwhose__init__sets metadata,inputsandforwardbut never runs the baseToolinitialization —Tool.__init__(which setsself.is_initialized = False) is never called, and unlike the siblingLangChainToolWrapper, the attribute is never set either. So calling the wrapper raisedAttributeErrorinTool.__call__(if not self.is_initialized:) before the underlyingrunmethod was ever reached.The fix sets
self.is_initialized = TrueinGradioToolWrapper.__init__, matching the existing convention inLangChainToolWrapper(which sets it the same way). The wrapper is fully configured at construction time (forwardis already bound to the gradio tool'srun), and it does not overridesetup(), so marking it initialized is correct — no lazy setup work is skipped.Fixes #2944.
Reproducer (copy-paste runnable)
Before (on main, before this fix)
After (with this fix)
Tests
test_from_gradio_wrapper_is_initializedintests/test_tools.py: builds a local gradio-style tool, wraps it withTool.from_gradio, and assertsis_initializedis set, the inputs mapping is correct ({"value": {"type": "integer", "description": ""}}), and repeated calls delegate torun(wrapped(value=4) == "8",wrapped(value=7) == "14").tests/test_tools.py: 69 passed (was 68 before my change; +1 is the new regression test), 3 skipped. The 3 failures + 1 error in the file (test_launch_gradio_demo_does_not_raise[boolean_default_tool_class], MCP-related tests) also fail on pristine main without this change — they are pre-existing environment issues unrelated to this fix.Thanks very much to @yifanxiong272 for the thorough report — the minimal reproducer, full traceback, and root-cause analysis made this straightforward to verify and fix.