Skip to content

Support Enum type for function tool args #398

@paullpp

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.

Metadata

Metadata

Assignees

Labels

tools[Component] This issue is related to tools

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions