From a497dd4358cfc8d9f95059157db56a6dacf9cb42 Mon Sep 17 00:00:00 2001 From: Kunal Sali <141454228+KunalLikesAI@users.noreply.github.com> Date: Thu, 5 Feb 2026 18:00:18 +0530 Subject: [PATCH 1/2] Fix ADK Toolbox Tool Loading Bug --- src/google/adk/tools/toolbox_toolset.py | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/google/adk/tools/toolbox_toolset.py b/src/google/adk/tools/toolbox_toolset.py index 672302da40..a063cc2921 100644 --- a/src/google/adk/tools/toolbox_toolset.py +++ b/src/google/adk/tools/toolbox_toolset.py @@ -104,7 +104,35 @@ def __init__( async def get_tools( self, readonly_context: Optional[ReadonlyContext] = None ) -> list[BaseTool]: - return await self._delegate.get_tools(readonly_context) + tools = await self._delegate.get_tools(readonly_context) + return [self._adapt_tool(tool) for tool in tools] + + def _adapt_tool(self, tool: BaseTool) -> BaseTool: + """Adapts a tool to ensure it's compatible with ADK.""" + # If the tool already has a working _get_declaration, return it as is. + if tool._get_declaration() is not None: + return tool + + # Attempt to find the function declaration in other common attributes + # expected from toolbox libraries. + declaration = None + if hasattr(tool, "function_declaration"): + declaration = tool.function_declaration + elif hasattr(tool, "declaration"): + declaration = tool.declaration + + # If we found a declaration, we need to ensure _get_declaration returns it. + if declaration: + # We can't easily subclass at runtime without potential issues, + # so we patch the instance method. + # Create a closure to capture the declaration + def _get_declaration_shim(): + return declaration + + # Bind the shim to the instance + tool._get_declaration = _get_declaration_shim + + return tool @override async def close(self): From 0fe3e0b2b7b2f11b5dcb2706bd850991f38464f0 Mon Sep 17 00:00:00 2001 From: Kunal Sali <141454228+KunalLikesAI@users.noreply.github.com> Date: Thu, 5 Feb 2026 18:08:38 +0530 Subject: [PATCH 2/2] Refactor _adapt_tool to robustly check both attributes --- src/google/adk/tools/toolbox_toolset.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/google/adk/tools/toolbox_toolset.py b/src/google/adk/tools/toolbox_toolset.py index a063cc2921..2c5747cd21 100644 --- a/src/google/adk/tools/toolbox_toolset.py +++ b/src/google/adk/tools/toolbox_toolset.py @@ -115,11 +115,10 @@ def _adapt_tool(self, tool: BaseTool) -> BaseTool: # Attempt to find the function declaration in other common attributes # expected from toolbox libraries. - declaration = None - if hasattr(tool, "function_declaration"): - declaration = tool.function_declaration - elif hasattr(tool, "declaration"): - declaration = tool.declaration + declaration = ( + getattr(tool, "function_declaration", None) + or getattr(tool, "declaration", None) + ) # If we found a declaration, we need to ensure _get_declaration returns it. if declaration: