diff --git a/google/genai/_extra_utils.py b/google/genai/_extra_utils.py index e0fb9c105..9cd80be2a 100644 --- a/google/genai/_extra_utils.py +++ b/google/genai/_extra_utils.py @@ -438,6 +438,8 @@ def should_disable_afc( return True # Default to enable AFC if not specified. + if not config_model.tools or len(config_model.tools) == 0: + return True if ( not config_model.automatic_function_calling or config_model.automatic_function_calling.disable is None diff --git a/google/genai/tests/afc/test_should_disable_afc.py b/google/genai/tests/afc/test_should_disable_afc.py index 188bf2b57..c89085f24 100644 --- a/google/genai/tests/afc/test_should_disable_afc.py +++ b/google/genai/tests/afc/test_should_disable_afc.py @@ -26,7 +26,7 @@ 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_enable_unset_max_0(): @@ -71,6 +71,9 @@ def test_afc_enable_unset_max_1(): automatic_function_calling=types.AutomaticFunctionCallingConfig( maximum_remote_calls=1, ), + tools=[types.Tool(function_declarations=[ + types.FunctionDeclaration(name='tool_name') + ])], ) ) is False @@ -80,7 +83,10 @@ 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}, + 'tools': [{'function_declarations': [{'name': 'tool_name'}]}] + } ) is False ) @@ -157,6 +163,9 @@ def test_afc_enable_true_max_unset(): automatic_function_calling=types.AutomaticFunctionCallingConfig( disable=False, ), + tools=[types.Tool(function_declarations=[ + types.FunctionDeclaration(name='tool_name') + ])], ) ) is False @@ -210,5 +219,5 @@ def test_afc_enable_true_max_1(): ), ) ) - is False + is True )