Skip to content

Agent tools erroring when using output schema #2664

Closed

Description

@mattmcc-attest

** 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

  1. added
    core[Component] This issue is related to the core interface and implementation
    on Aug 21, 2025
  2. added theissue type on Aug 21, 2025
  3. changed the title [-]Agent tools erroring when using input schema[/-] [+]Agent tools erroring when using output schema[/+] on Aug 21, 2025
  4. dylan-apex commented on Aug 21, 2025

    @dylan-apex
    Contributor

    This is a limitation in the Google API - the response_schema can't have Union types. The response schema has to be set in stone.

    You'll pretty much have to redefine your Animal class to have similar fields as the Dog and Cat classes.

    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."}}]}
  5. boyangsvl commented on Aug 21, 2025

    @boyangsvl
    Collaborator

    Moving to discussions as this is not a bug of ADK.

  6. locked and limited conversation to collaborators on Aug 21, 2025
  7. converted this issue into a discussion #2670 on Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

core[Component] This issue is related to the core interface and implementation

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions