Skip to content

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

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

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

Conversation

@zhanghm783-hash

@zhanghm783-hash zhanghm783-hash commented Dec 2, 2026 •

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. Empty tuples and nested empty tuples retain minItems=maxItems=0 without requiring an items schema; the type mapper recurses only when items exists.

Testing Plan

Unit tests

The eight new cases fail on the unmodified source with KeyError: 'items'. After the initial fix, these files reported 258 passed. The four empty-tuple regressions (tuple[()] and list[tuple[()]] through both adapters) fail on that revision with KeyError('items'). After guarding recursion on the presence of items, the following related files report 262 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.

@suirindo

suirindo commented Dec 2, 2026

Copy link
Copy Markdown

Could the adapter regression include tuple[()] and list[tuple[()]]? At 4052d54, Pydantic emits an array with minItems=maxItems=0 and no items for an empty tuple. I ran the PR's normalizer and type mapper in isolation: both cases raise KeyError('items') because the mapper indexes items for every array. Could it recurse only when items is present and preserve both zero bounds? I did not run the full suite or call a live provider.

AI-assisted review; verification scope described above.

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.

2 participants