Skip to content

Support Enum type for function tool args #398

Closed as duplicate
Closed as duplicate

Description

@paullpp

Is your feature request related to a problem? Please describe.
Currently function tools can only have primitive / simple types. It'd be useful to support Enums, even other complex types, though this issue will focus on Enums.

Describe the solution you'd like
Support for Enum arguments in function tool calls

Describe alternatives you've considered
In the case of Enums, we've considered using literals instead, but find that the Agent can make values up rather than using values in the literal. A workaround is to make the function parameter of string type, and put the valid options into the functions docstring. However, that's tedious for large enums.

Additional context
as an example, calling the following function tool:

from enum import Enum

class CountryCodeEnum(Enum):
    UNITED_STATES = "US"
    CANADA = "CA"
    ...

def get_weather(city: str, country: CountyCodeEnum):
    ...

would throw the following error:

Failed to parse the parameter country of function get_weather for
automatic function calling. Automatic function calling works best with
simpler function signature schema,consider manually parse your
function declaration for function get_weather.

That's because _parse_schema_from_parameter in src/google/adk/tools/function_parameter_parse_util.py does not currently support Enum type args.

Activity

  1. kavinkumar807 commented on Apr 26, 2025

    @kavinkumar807
    Contributor

    @paullpp can you please give me more context?

  2. added
    tools[Component] This issue is related to tools
    on Apr 28, 2025
  3. thomasglow commented on May 3, 2025

    @thomasglow

    Example error:

    GenerateContentRequest.tools[0].function_declarations[32].parameters.properties[countryCode].enum[0]: cannot be empty\n', 'status': 'INVALID_ARGUMENT'}}
    
  4. added this to the FixIt Week milestone on May 28, 2025
  5. juszzz commented on Sep 15, 2025

    @juszzz

    @lucasnobre212 opened a PR to resolve this issue back in May and it seems like its still waiting on a review. Is there anyone with merge permissions who can take a look at it? There are a lot of auto-generated client libraries that make liberal use of enums and it would be nice to drop those library methods in as tools to our agents.

  6. dennisgera commented on Sep 18, 2025

    @dennisgera

    I'm also running into this issue. Would love to have functions accept an enum as a parameter. Just looked at @juszzz's PR, LGTM. Does anyone know when we can have that merged? Is anyone allowed to approve adk PRs?

  7. self-assigned this
    on Oct 14, 2025
  8. added
    core[Component] This issue is related to the core interface and implementation
    on Oct 14, 2025
  9. jpantsjoha commented on Oct 18, 2025

    @jpantsjoha
    Contributor

    I've submitted a documentation PR with Enum workarounds while we wait for native support:

    PR: google/adk-docs#786

    The type annotation guide documents using typing.Literal as an interim solution:

    from typing import Literal, Dict, Any
    
    def configure_setting(
        mode: Literal["auto", "manual", "disabled"]
    ) -> Dict[str, Any]:
        """Set configuration mode to one of the allowed values."""
        return {"mode": mode, "updated": True}

    Benefits:

    • Type checkers validate the literal values
    • Schema generation includes the enum constraint
    • Clear API contract for LLM

    This should help developers until native Enum support is implemented (tracked in this issue and #2733).

  10. Jacksunwei commented on Oct 28, 2025

    @Jacksunwei
    Collaborator

    Thanks @jpantsjoha for documenting the typing.Literal workaround in the ADK docs PR.

    This issue is a duplicate of #3089, which is already being tracked in the 10/27 ADK Week milestone.

    Please continue the discussion in #3089 to keep everything in one place and help maintainers track progress more easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

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

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions