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
This commit is contained in:
Xuan Yang
2025-11-21 15:25:27 -08:00
committed by Copybara-Service
parent 777dba3033
commit 52674e7fac
2 changed files with 25 additions and 0 deletions
+2
View File
@@ -79,6 +79,8 @@ class AgentTool(BaseTool):
result = _automatic_function_calling_util.build_function_declaration(
func=self.agent.input_schema, variant=self._api_variant
)
# Override the description with the agent's description
result.description = self.agent.description
else:
result = types.FunctionDeclaration(
parameters=types.Schema(
+23
View File
@@ -679,3 +679,26 @@ def test_include_plugins_false():
# Plugin should only be called for root_agent, not tool_agent
assert tracking_plugin.before_agent_calls == 1
def test_agent_tool_description_with_input_schema():
"""Test that agent description is propagated when using input_schema."""
class CustomInput(BaseModel):
"""This is the Pydantic model docstring."""
custom_input: str
agent_description = 'This is the agent description that should be used'
tool_agent = Agent(
name='tool_agent',
model=testing_utils.MockModel.create(responses=['test response']),
description=agent_description,
input_schema=CustomInput,
)
agent_tool = AgentTool(agent=tool_agent)
declaration = agent_tool._get_declaration()
# The description should come from the agent, not the Pydantic model
assert declaration.description == agent_description