Skip to content

Allow enums in input schemas #2733

@mattmcc-attest

Description

@mattmcc-attest

I am not sure if there is an intentional restriction around this but I believe we should allow enums as part of an input_schema when using an agent as a tool.

Here is an example that doesn't work:

from __future__ import annotations
from pydantic import BaseModel, Field
from typing import Optional
from enum import Enum
from google.adk.models.google_llm import types
from google.adk.agents import Agent
from google.adk.tools.agent_tool import AgentTool

class ColourOfFur(str, Enum):
    GINGER = 'ginger'
    WHITE = 'white'
    BLACK = 'black'
    BROWN = 'brown'

class Cat(BaseModel):
    name: str
    colour_of_fur: Optional[ColourOfFur] = Field(
        description="The color of the cat's fur",
    )

cat_agent = Agent(
    name="cat_agent",
    model='gemini-2.5-flash',
    description="Gets information about cats.",
    instruction=f"""
    You're job is to provide some information about pedigrees of cats.
    
    Cat 1 has ginger hair
    Cat 2 has red fur
    """,
    input_schema=Cat,
    output_schema=Cat,
)
root_agent = Agent(
    name="root_agent",
    model='gemini-2.5-flash',
    description="Animal triage agent",
    instruction=f"""
    You're job is to get information about animals, specifically dogs and cats.

    TOOLS:
    When calling the {cat_agent.name} tool use the following format:
    {cat_agent.name}(input=Cat)
    call with an empty Cat object and you'll get the Cats information back in the same format.

    """,
    generate_content_config=types.GenerateContentConfig(
        temperature=0,
    ),
    tools=[
        AgentTool(agent=cat_agent)
        ],
)

It doesn't work because:

    schema = _function_parameter_parse_util._parse_schema_from_parameter(
  File ".venv/lib/python3.9/site-packages/google/adk/tools/_function_parameter_parse_util.py", line 240, in _parse_schema_from_parameter
    schema_in_any_of = _parse_schema_from_parameter(
  File "/.venv/lib/python3.9/site-packages/google/adk/tools/_function_parameter_parse_util.py", line 310, in _parse_schema_from_parameter
    raise ValueError(
ValueError: Failed to parse the parameter item: animals.agent.ColourOfFur of function Cat for automatic function calling. Automatic function calling works best with simpler function signature schema, consider manually parsing your function declaration for function Cat.

Describe the solution you'd like
I would like to be able to use an Enum as part of my schema. It has a definitive set of values so I don't see a reason to not allow this.

Alternatives
I don't want to have to change my data models away from Enums but I did also try converting colour of fur to a Literal rather than an enum and it worked (but I had to remove the Optional wrapper on the enum)

due to

  File "venv/lib/python3.9/site-packages/google/adk/models/llm_request.py", line 102, in append_tools
    declaration = tool._get_declaration()
  File "//lib/python3.9/site-packages/google/adk/tools/agent_tool.py", line 70, in _get_declaration
    result = _automatic_function_calling_util.build_function_declaration(
  File "venv/lib/python3.9/site-packages/google/adk/tools/_automatic_function_calling_util.py", line 235, in build_function_declaration
    from_function_with_options(func, variant)
  File "/.venv/lib/python3.9/site-packages/google/adk/tools/_automatic_function_calling_util.py", line 309, in from_function_with_options
    schema = _function_parameter_parse_util._parse_schema_from_parameter(
  File "/.venv/lib/python3.9/site-packages/google/adk/tools/_function_parameter_parse_util.py", line 237, in _parse_schema_from_parameter
    if arg.__name__ == 'NoneType':  # Optional type
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/typing.py", line 701, in __getattr__
    raise AttributeError(attr)
AttributeError: __name__

Metadata

Metadata

Assignees

Labels

bot triaged[Bot] This issue is triaged by ADK botcore[Component] This issue is related to the core interface and implementation

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions