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
3 changes: 2 additions & 1 deletion src/strands/models/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}),
)

Expand Down
34 changes: 9 additions & 25 deletions tests/strands/models/test_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand All @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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(),
},
Expand Down