Agent tools erroring when using output schema #2670
Replies: 3 comments 8 replies
-
This is a limitation in the Google API - the You'll pretty much have to redefine your from __future__ import annotations
from pydantic import BaseModel, Field
from typing import List, Literal
from google.adk.agents import Agent
from google.adk.tools.agent_tool import AgentTool
from pydantic import BaseModel, Field
class Cat(BaseModel):
"""Instruction for creating a new survey."""
type: Literal["cat"] = Field(default="cat", description="The type of animal")
colour_of_fur: str = Field(
default=None,
description="The color of the cat's fur",
)
class Dog(BaseModel):
"""Instruction for opening an existing survey."""
type: Literal["dog"] = Field(default="dog", description="The type of animal")
wagginess_of_tail: str = Field(
default=None,
description="The wagging behavior of the dog's tail",
)
class Animal(BaseModel):
type: Literal["dog", "cat"] = Field(description="The type of animal")
name: str = Field(description="The name of the animal")
description: dict = Field(description="A description of the animal")
class ResponseMessage(BaseModel):
summary: str = Field(description="A brief summary of the animals.")
do: List[Animal]
class DogList(BaseModel):
dogs: List[Dog] = Field(description="List of dogs")
class CatList(BaseModel):
cats: List[Cat] = Field(description="List of cats")
model='gemini-2.5-flash'
dog_agent = Agent(
name="dog_agent",
model=model,
description="Gets information about dogs.",
instruction=f"""
You're job is to provide some information about breeds of dogs.
""",
output_schema=DogList,
)
cat_agent = Agent(
name="cat_agent",
model=model,
description="Gets information about cats.",
instruction=f"""
You're job is to provide some information about pedigrees of cats.
""",
output_schema=CatList,
)
root_agent = Agent(
name="root_agent",
model=model,
description="Frontline agent that greets user, identifies intent, and dispatches to appropriate handlers.",
instruction=f"""
You're job is to get information about animals, specifically dogs and cats.
Use the appropriate tool based on the user's request.
""",
tools=[
AgentTool(agent=dog_agent), AgentTool(agent=cat_agent)
],
output_schema=ResponseMessage,
) Response to "Tell me about cats and dogs" {"summary": "Cats are felines often kept as pets, known for their independence and agility. Dogs are canines, also commonly kept as pets, known for their loyalty and for communicating through various means, including tail wagging.",
"do": [
{"type": "cat", "name": "Cat", "description": {}},
{"type": "dog", "name": "Dog", "description":
{"wagginess_of_tail": "Dogs often wag their tails as a form of communication, indicating excitement, happiness, or sometimes apprehension."}}]} |
Beta Was this translation helpful? Give feedback.
-
Moving to discussions as this is not a bug of ADK. |
Beta Was this translation helpful? Give feedback.
-
Thanks for getting back to me. It is strange that if I make Cat or Dog the root agent I can use a Union type in the output schema.
I built and tested all the agents separately and having issues wiring them up now. But I will see if I can modify my Pydantic schema. I tried an abstract base class but that also had issues |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
** Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.
Describe the bug
I can create an Agent with output schema using a Union type and it works when I run that agent. However, if I try to use that agent as a tool for another agent, it does not work.
To Reproduce
Here is a dummy example of what I am trying to do:
Expected behavior
I expect not to get the error
AnyOf is not supported in function declaration schema for Google AI
seeing as I can use the sub agent individually. If I make cat or dog the root agent they work fine.The second I wrap it in a tool and try to use it, it breaks.
It also doesn't work id I remove the root agent output_schema and add input_schema=AnimalList to any of the sub agents
Desktop (please complete the following information):
Model Information:
gemini-2.5-flash
Thank you for your help!
Beta Was this translation helpful? Give feedback.
All reactions