Skip to content

Commit 52674e7

Browse files
xuanyang15copybara-github
authored andcommitted
fix: Update AgentTool to use Agent's description when input_schema is provided in FunctionDeclaration
Co-authored-by: Xuan Yang <xygoogle@google.com> PiperOrigin-RevId: 835379243
1 parent 777dba3 commit 52674e7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/google/adk/tools/agent_tool.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def _get_declaration(self) -> types.FunctionDeclaration:
7979
result = _automatic_function_calling_util.build_function_declaration(
8080
func=self.agent.input_schema, variant=self._api_variant
8181
)
82+
# Override the description with the agent's description
83+
result.description = self.agent.description
8284
else:
8385
result = types.FunctionDeclaration(
8486
parameters=types.Schema(

tests/unittests/tools/test_agent_tool.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,26 @@ async def before_agent_callback(self, **kwargs):
679679

680680
# Plugin should only be called for root_agent, not tool_agent
681681
assert tracking_plugin.before_agent_calls == 1
682+
683+
684+
def test_agent_tool_description_with_input_schema():
685+
"""Test that agent description is propagated when using input_schema."""
686+
687+
class CustomInput(BaseModel):
688+
"""This is the Pydantic model docstring."""
689+
690+
custom_input: str
691+
692+
agent_description = 'This is the agent description that should be used'
693+
tool_agent = Agent(
694+
name='tool_agent',
695+
model=testing_utils.MockModel.create(responses=['test response']),
696+
description=agent_description,
697+
input_schema=CustomInput,
698+
)
699+
700+
agent_tool = AgentTool(agent=tool_agent)
701+
declaration = agent_tool._get_declaration()
702+
703+
# The description should come from the agent, not the Pydantic model
704+
assert declaration.description == agent_description

0 commit comments

Comments
 (0)