Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions google/genai/_extra_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,15 @@ def should_disable_afc(
)
return True

# If there are no tools, disable AFC.
if not config_model.tools:
if config_model.automatic_function_calling:
logger.warning(
'No tools are specified in the config, but automatic_function_calling'
' is enabled. Therefore, automatic function calling is disabled.'
)
return True

# Default to enable AFC if not specified.
if (
not config_model.automatic_function_calling
Expand Down
16 changes: 14 additions & 2 deletions google/genai/tests/afc/test_get_max_remote_calls_for_afc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ def test_config_is_none():


def test_afc_unset_max_unset():
assert get_max_remote_calls_afc(types.GenerateContentConfig()) == 10
assert (
get_max_remote_calls_afc(
types.GenerateContentConfig(
tools=[types.Tool(retrieval=types.Retrieval())]
)
)
== 10
)


def test_afc_unset_max_set():
Expand All @@ -36,6 +43,7 @@ def test_afc_unset_max_set():
automatic_function_calling=types.AutomaticFunctionCallingConfig(
maximum_remote_calls=20,
),
tools=[types.Tool(retrieval=types.Retrieval())],
)
)
== 20
Expand Down Expand Up @@ -72,6 +80,7 @@ def test_afc_d_max_unset():
automatic_function_calling=types.AutomaticFunctionCallingConfig(
disable=False,
),
tools=[types.Tool(retrieval=types.Retrieval())],
)
)
== 10
Expand All @@ -86,6 +95,7 @@ def test_afc_d_max_set():
disable=False,
maximum_remote_calls=5,
),
tools=[types.Tool(retrieval=types.Retrieval())],
)
)
== 5
Expand All @@ -96,10 +106,11 @@ def test_afc_enabled_max_set_to_zero():
with pytest.raises(ValueError):
get_max_remote_calls_afc(
types.GenerateContentConfig(
automatic_function_calling=types.AutomaticFunctionCallingConfig(
automatic_function_calling=types.AutomaticFunctionCallingConfig(
disable=False,
maximum_remote_calls=0,
),
tools=[types.Tool(retrieval=types.Retrieval())],
)
)

Expand All @@ -124,6 +135,7 @@ def test_afc_enabled_max_set_to_float():
disable=False,
maximum_remote_calls=5.0,
),
tools=[types.Tool(retrieval=types.Retrieval())],
)
)
== 5
Expand Down
45 changes: 42 additions & 3 deletions google/genai/tests/afc/test_should_disable_afc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,41 @@ def test_config_is_none():


def test_afc_config_unset():
assert should_disable_afc(types.GenerateContentConfig()) is False
assert should_disable_afc(types.GenerateContentConfig()) is True


def test_afc_config_with_tools():
assert (
should_disable_afc(
types.GenerateContentConfig(
tools=[types.Tool(retrieval=types.Retrieval())]
)
)
is False
)


def test_afc_config_with_empty_tools_when_afc_is_enabled():
assert (
should_disable_afc(
types.GenerateContentConfig(
automatic_function_calling=types.AutomaticFunctionCallingConfig(),
tools=[],
)
)
is True
)


def test_afc_config_without_tools_when_afc_is_enabled():
assert (
should_disable_afc(
types.GenerateContentConfig(
automatic_function_calling=types.AutomaticFunctionCallingConfig()
)
)
is True
)


def test_afc_enable_unset_max_0():
Expand Down Expand Up @@ -71,6 +105,7 @@ def test_afc_enable_unset_max_1():
automatic_function_calling=types.AutomaticFunctionCallingConfig(
maximum_remote_calls=1,
),
tools=[types.Tool(retrieval=types.Retrieval())],
)
)
is False
Expand All @@ -80,9 +115,11 @@ def test_afc_enable_unset_max_1():
def test_afc_enable_unset_max_1_0():
assert (
should_disable_afc(
{'automatic_function_calling': {'maximum_remote_calls': 1.0}}
{
'automatic_function_calling': {'maximum_remote_calls': 1.0},
}
)
is False
is True
)


Expand Down Expand Up @@ -157,6 +194,7 @@ def test_afc_enable_true_max_unset():
automatic_function_calling=types.AutomaticFunctionCallingConfig(
disable=False,
),
tools=[types.Tool(retrieval=types.Retrieval())],
)
)
is False
Expand Down Expand Up @@ -208,6 +246,7 @@ def test_afc_enable_true_max_1():
disable=False,
maximum_remote_calls=1,
),
tools=[types.Tool(retrieval=types.Retrieval())],
)
)
is False
Expand Down