From d755031840d10200938044bef0788f56f3522ed1 Mon Sep 17 00:00:00 2001 From: techi101 Date: Tue, 27 Oct 2026 13:37:10 +0530 Subject: [PATCH] fix(tools): send an AgentTool's aliased input_schema to the agent by alias AgentTool validated the model's arguments by alias but dumped them to JSON by field name. The agent's node then re-validated that JSON against the same schema and raised a ValidationError, failing the whole run when the input_schema used aliases (for example alias_generator=to_camel). --- src/google/adk/tools/agent_tool.py | 7 ++-- tests/unittests/tools/test_agent_tool.py | 41 ++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/google/adk/tools/agent_tool.py b/src/google/adk/tools/agent_tool.py index f47ec0a2431..6bd76147e2e 100644 --- a/src/google/adk/tools/agent_tool.py +++ b/src/google/adk/tools/agent_tool.py @@ -241,12 +241,15 @@ async def run_async( if input_schema: input_value = input_schema.model_validate(args) # The text must stay a bare JSON document: the node runtime re-validates - # it against this same schema, so any prose here fails that parse. + # it against this same schema, so any prose here fails that parse. It + # is dumped by alias for the same reason. content = types.Content( role='user', parts=[ types.Part.from_text( - text=input_value.model_dump_json(exclude_none=True) + text=input_value.model_dump_json( + exclude_none=True, by_alias=True + ) ) ], ) diff --git a/tests/unittests/tools/test_agent_tool.py b/tests/unittests/tools/test_agent_tool.py index 9c45b8ae54b..c080e4ac4bd 100644 --- a/tests/unittests/tools/test_agent_tool.py +++ b/tests/unittests/tools/test_agent_tool.py @@ -50,6 +50,8 @@ from google.genai import types from google.genai.types import Part from pydantic import BaseModel +from pydantic import ConfigDict +from pydantic.alias_generators import to_camel import pytest from pytest import mark @@ -817,6 +819,45 @@ class CustomOutput(BaseModel): assert mock_model.requests[1].config.response_mime_type == 'application/json' +def test_input_schema_with_aliases(): + """Tests that an aliased input_schema reaches the agent by its aliases.""" + + class CustomInput(BaseModel): + model_config = ConfigDict(alias_generator=to_camel) + city_name: str + + tool_agent_model = testing_utils.MockModel.create(responses=['sunny']) + tool_agent = Agent( + name='tool_agent', + model=tool_agent_model, + input_schema=CustomInput, + ) + function_call = Part.from_function_call( + name='tool_agent', args={'cityName': 'Paris'} + ) + root_agent = Agent( + name='root_agent', + model=testing_utils.MockModel.create(responses=[function_call, 'done']), + tools=[AgentTool(agent=tool_agent)], + ) + + runner = testing_utils.InMemoryRunner(root_agent) + + assert testing_utils.simplify_events(runner.run('test1')) == [ + ('root_agent', function_call), + ( + 'root_agent', + Part.from_function_response( + name='tool_agent', response={'result': 'sunny'} + ), + ), + ('root_agent', 'done'), + ] + assert testing_utils.simplify_contents( + tool_agent_model.requests[0].contents + ) == [('user', '{"cityName":"Paris"}')] + + @mark.parametrize( 'env_variables', [