Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/google/adk/tools/toolbox_toolset.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,34 @@ 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 = (
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:
# 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):
Expand Down
Loading