Repository navigation
Description
** 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.
packages/google/adk/tools/_function_parameter_parse_util.py", line 276, in _parse_schema_from_parameter
_raise_if_schema_unsupported(variant, schema)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
packages/google/adk/tools/_function_parameter_parse_util.py", line 77, in _raise_if_schema_unsupported
_raise_for_any_of_if_mldev(schema)
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
packages/google/adk/tools/_function_parameter_parse_util.py", line 58, in _raise_for_any_of_if_mldev
raise ValueError(
'AnyOf is not supported in function declaration schema for Google AI.'
)
ValueError: AnyOf is not supported in function declaration schema for Google AI.
{"error": "AnyOf is not supported in function declaration schema for Google AI."}
To Reproduce
Here is a dummy example of what I am trying to do:
from __future__ import annotations
from pydantic import BaseModel, Field
from typing import List, Union, Literal
from google.adk.agents import Agent
from google.adk.tools.agent_tool import AgentTool
from pydantic import BaseModel, Field
from typing import List, Union
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",
)
Animal = Union[
Dog,
Cat,
]
class ResponseMessage(BaseModel):
request_id: str = Field(description="The ID of the original request", alias="requestId")
summary: str = Field(description="A brief summary of the animals.")
do: List[Animal] = Field(description="A list of animals.")
class AnimalList(BaseModel):
animals: List[Animal] = Field(description="List of animals")
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=AnimalList,
)
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=AnimalList,
)
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,
)
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):
- OS: MacOs
- Python version(python -V): Python 3.13.5
- ADK version(pip show google-adk): 1.12.0
Model Information:
gemini-2.5-flash
Thank you for your help!
Activity
[-]Agent tools erroring when using input schema[/-][+]Agent tools erroring when using output schema[/+]dylan-apex commentedon Aug 21, 2025
This is a limitation in the Google API - the
response_schemacan't haveUniontypes. The response schema has to be set in stone.You'll pretty much have to redefine your
Animalclass to have similar fields as theDogandCatclasses.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."}}]}boyangsvl commentedon Aug 21, 2025
Moving to discussions as this is not a bug of ADK.