Skip to content

fix(tools): handle tuple parameters in external tool adapters - #8480

Open
zhanghm783-hash wants to merge 1 commit into
google:mainfrom
zhanghm783-hash:codex/fix-tuple-adapter-schema
Open

zhanghm783-hash wants to merge 1 commit into
google:mainfrom
zhanghm783-hash:codex/fix-tuple-adapter-schema

Conversation

@zhanghm783-hash

Copy link
Copy Markdown

Link to Issue or Description of Change

Problem

LangChain and CrewAI tools with fixed-length tuple arguments fail while ADK builds their function declarations. Pydantic emits prefixItems without items, and the adapter mapping indexes items directly. A real LangChain wrapper raises ValueError: Failed to build function declaration for Langchain tool: 'items' before the tool can run.

Reproduced on main at e90308ed988bedcf4ba41742eac81886161ea9a5, Windows, Python 3.12.10, google-genai 2.34.0 and langchain-core 1.8.5.

Solution

Reuse the existing tuple-schema normalizer before mapping adapter parameters. This follows the handling already used by the FunctionTool fallback. Regression coverage checks fixed, heterogeneous, nullable and nested tuples through both adapter declaration builders, including item types and length bounds.

Testing Plan

Unit tests

The eight new cases fail on the unmodified source with KeyError: 'items'. After the fix, the following related files report 258 passed.

python -m pytest tests/unittests/tools/test_build_function_declaration.py tests/unittests/tools/test_from_function_with_options.py tests/unittests/tools/test_function_tool.py tests/unittests/integrations/langchain/test_langchain_tool.py -q

Manual adapter verification

With the checkout on PYTHONPATH and its dependencies installed, run this local tool.

import asyncio
from google.adk.integrations.langchain import LangchainTool
from langchain_core.tools import tool

@tool
def add_coordinates(coordinates: tuple[float, float]) -> float:
    """Add two coordinates."""
    return sum(coordinates)

async def main():
    wrapped = LangchainTool(add_coordinates)
    declaration = wrapped._get_declaration()
    parameter = declaration.parameters.properties["coordinates"]
    print(parameter.type, parameter.items.type)
    print(await wrapped.run_async(
        args={"coordinates": [1.5, 2.5]}, tool_context=None
    ))

asyncio.run(main())

Before the change, declaration building raises the error above. After the change, the declaration has an ARRAY of NUMBER values with length bounds of two, and the tool returns 4.0.

This is an offline declaration and tool-execution check. Live model requests, the complete CrewAI wrapper integration, the full repository test matrix and remote CI have not been verified.

isort, pyink, Ruff, codespell, compliance, documentation and whitespace checks passed. The Windows pre-commit launcher could not find /bin/bash for the new-file check. Its Python entry point passed separately with the added-file list generated from the actual diff, which adds no files.

@google-cla

google-cla Bot commented Dec 2, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant