diff --git a/src/strands/models/gemini.py b/src/strands/models/gemini.py index c288595e1..154daff7c 100644 --- a/src/strands/models/gemini.py +++ b/src/strands/models/gemini.py @@ -214,7 +214,8 @@ def _format_request_config( """ return genai.types.GenerateContentConfig( system_instruction=system_prompt, - tools=self._format_request_tools(tool_specs), + # NOTE: Vertex AI rejects empty arrays for `tools` due to oneof constraints + tools=self._format_request_tools(tool_specs) if tool_specs else None, **(params or {}), ) diff --git a/tests/strands/models/test_gemini.py b/tests/strands/models/test_gemini.py index 9eb5a9a7f..dcaaa56b8 100644 --- a/tests/strands/models/test_gemini.py +++ b/tests/strands/models/test_gemini.py @@ -83,7 +83,7 @@ async def test_stream_request_default(gemini_client, model, messages, model_id): await anext(model.stream(messages)) exp_request = { - "config": {"tools": [{"function_declarations": []}]}, + "config": {}, "contents": [{"parts": [{"text": "test"}], "role": "user"}], "model": model_id, } @@ -97,10 +97,7 @@ async def test_stream_request_with_params(gemini_client, model, messages, model_ await anext(model.stream(messages)) exp_request = { - "config": { - "tools": [{"function_declarations": []}], - "temperature": 1, - }, + "config": {"temperature": 1}, "contents": [{"parts": [{"text": "test"}], "role": "user"}], "model": model_id, } @@ -112,7 +109,7 @@ async def test_stream_request_with_system_prompt(gemini_client, model, messages, await anext(model.stream(messages, system_prompt=system_prompt)) exp_request = { - "config": {"system_instruction": system_prompt, "tools": [{"function_declarations": []}]}, + "config": {"system_instruction": system_prompt}, "contents": [{"parts": [{"text": "test"}], "role": "user"}], "model": model_id, } @@ -145,9 +142,7 @@ async def test_stream_request_with_document(content, formatted_part, gemini_clie await anext(model.stream(messages)) exp_request = { - "config": { - "tools": [{"function_declarations": []}], - }, + "config": {}, "contents": [{"parts": [formatted_part], "role": "user"}], "model": model_id, } @@ -172,9 +167,7 @@ async def test_stream_request_with_image(gemini_client, model, model_id): await anext(model.stream(messages)) exp_request = { - "config": { - "tools": [{"function_declarations": []}], - }, + "config": {}, "contents": [ { "parts": [ @@ -213,9 +206,7 @@ async def test_stream_request_with_reasoning(gemini_client, model, model_id): await anext(model.stream(messages)) exp_request = { - "config": { - "tools": [{"function_declarations": []}], - }, + "config": {}, "contents": [ { "parts": [ @@ -276,9 +267,7 @@ async def test_stream_request_with_tool_use(gemini_client, model, model_id): await anext(model.stream(messages)) exp_request = { - "config": { - "tools": [{"function_declarations": []}], - }, + "config": {}, "contents": [ { "parts": [ @@ -326,9 +315,7 @@ async def test_stream_request_with_tool_results(gemini_client, model, model_id): await anext(model.stream(messages)) exp_request = { - "config": { - "tools": [{"function_declarations": []}], - }, + "config": {}, "contents": [ { "parts": [ @@ -370,9 +357,7 @@ async def test_stream_request_with_empty_content(gemini_client, model, model_id) await anext(model.stream(messages)) exp_request = { - "config": { - "tools": [{"function_declarations": []}], - }, + "config": {}, "contents": [{"parts": [], "role": "user"}], "model": model_id, } @@ -613,7 +598,6 @@ async def test_structured_output(gemini_client, model, messages, model_id, weath exp_request = { "config": { - "tools": [{"function_declarations": []}], "response_mime_type": "application/json", "response_schema": weather_output.model_json_schema(), },