Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 16 additions & 1 deletion src/google/adk/tools/_function_parameter_parse_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from __future__ import annotations

from enum import Enum
import inspect
import logging
import types as typing_types
Expand Down Expand Up @@ -75,7 +76,7 @@ def _raise_if_schema_unsupported(
):
if variant == GoogleLLMVariant.GEMINI_API:
_raise_for_any_of_if_mldev(schema)
_update_for_default_if_mldev(schema)
# _update_for_default_if_mldev(schema) # No need of this since GEMINI now supports default value


def _is_default_value_compatible(
Expand Down Expand Up @@ -145,6 +146,20 @@ 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:
default_value = (
param.default.value
if isinstance(param.default, Enum)
else param.default
)
if default_value not in schema.enum:
raise ValueError(default_value_error_msg)
schema.default = default_value
_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
30 changes: 30 additions & 0 deletions tests/unittests/tools/test_build_function_declaration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from enum import Enum
from typing import Dict
from typing import List

Expand All @@ -22,6 +23,7 @@
# TODO: crewai requires python 3.10 as minimum
# from crewai_tools import FileReadTool
from pydantic import BaseModel
import pytest


def test_string_input():
Expand Down Expand Up @@ -220,6 +222,34 @@ def simple_function(
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 = InputEnum.AGENT):
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'].default == 'agent'
assert function_decl.parameters.properties['input'].enum == ['agent', 'tool']

def simple_function_with_wrong_enum(input: InputEnum = 'WRONG_ENUM'):
return input.value

with pytest.raises(ValueError):
_automatic_function_calling_util.build_function_declaration(
func=simple_function_with_wrong_enum
)


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