Skip to content
Closed
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions src/google/adk/tools/agent_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
],
)
Expand Down
41 changes: 41 additions & 0 deletions tests/unittests/tools/test_agent_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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',
[
Expand Down
Loading