Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
5387476
feat: Added support for enums as arguments for function tools
SOORAJTS2001 Oct 3, 2025
598fee6
feat: Add default value support for function tools
SOORAJTS2001 Oct 4, 2025
35c8949
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 4, 2025
816f2e8
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 5, 2025
936cca2
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 6, 2025
0b09400
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 7, 2025
fdc13e8
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 8, 2025
980f463
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 10, 2025
ab5bd3e
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 11, 2025
d9a2dae
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 12, 2025
644f68c
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 17, 2025
1f19fc7
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 21, 2025
b984403
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 22, 2025
3e2fcb0
Merge branch 'main' into feat/function-tools-enum-support
Jacksunwei Oct 23, 2025
1c445eb
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 24, 2025
4a2cb57
Merge branch 'main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 27, 2025
1f96ce2
Merge branch 'main' into feat/function-tools-enum-support
Jacksunwei Oct 28, 2025
824c6c4
Merge branch 'refs/heads/main' into feat/function-tools-enum-support
SOORAJTS2001 Oct 28, 2025
52d0647
fix: format code with pyink
SOORAJTS2001 Oct 28, 2025
9ad5a93
Merge remote-tracking branch 'origin/feat/function-tools-enum-support…
SOORAJTS2001 Oct 28, 2025
b23782c
Merge branch 'main' into feat/function-tools-enum-support
yyyu-google Oct 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/google/adk/tools/_function_parameter_parse_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from google.genai import types
import pydantic
from enum import Enum

from ..utils.variant_utils import GoogleLLMVariant

Expand Down Expand Up @@ -145,6 +146,15 @@ def _parse_schema_from_parameter(
schema.type = _py_builtin_type_to_schema_type[param.annotation]
_raise_if_schema_unsupported(variant, schema)
return schema
if isinstance(param.annotation, type) and issubclass(param.annotation, Enum):
schema.type = types.Type.STRING
schema.enum = [e.value for e in param.annotation]
if param.default is not inspect.Parameter.empty:
if not _is_default_value_compatible(param.default, param.annotation):
raise ValueError(default_value_error_msg)
schema.default = param.default
Comment thread
yyyu-google marked this conversation as resolved.
Outdated
_raise_if_schema_unsupported(variant, schema)
return schema
if (
get_origin(param.annotation) is Union
# only parse simple UnionType, example int | str | float | bool
Expand Down
20 changes: 19 additions & 1 deletion tests/unittests/tools/test_build_function_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# TODO: crewai requires python 3.10 as minimum
# from crewai_tools import FileReadTool
from pydantic import BaseModel

from enum import Enum

def test_string_input():
def simple_function(input_str: str) -> str:
Expand Down Expand Up @@ -219,6 +219,24 @@ def simple_function(
assert function_decl.parameters.properties['input_dir'].type == 'ARRAY'
assert function_decl.parameters.properties['input_dir'].items.type == 'OBJECT'

def test_enums():

class InputEnum(Enum):
AGENT = "agent"
TOOL = "tool"

def simple_function(input:InputEnum):
return input.value

function_decl = _automatic_function_calling_util.build_function_declaration(
func=simple_function
)

assert function_decl.name == 'simple_function'
assert function_decl.parameters.type == 'OBJECT'
assert function_decl.parameters.properties['input'].type == 'STRING'
assert function_decl.parameters.properties['input'].enum == ['agent', 'tool']
Comment thread
yyyu-google marked this conversation as resolved.


def test_basemodel_list():
class ChildInput(BaseModel):
Expand Down