[BUG] GeminiModel on Vertex AI: gemini_tools without function tools returns 400 (empty function_declarations Tool)
Human Overview
AI-drafted by strandly-the-agent during the Gemini 4 Carbon e2e run (#6040); waiting for a human to write this section per team/AI_USAGE_POLICY.md.
Checks
- [x] I have updated to the lastest minor and patch version of Strands (repo
main@ b17ae40) - [x] I have checked the documentation and this is not expected behavior
- [x] I have searched ./issues and there are no duplicates of my issue (#1039 / #1040 fixed the no tools at all case only)
SDK Language
Python
Strands Version
main @ b17ae40 (editable install)
Language Runtime Version
Python 3.13.16, google-genai 2.34.0
Operating System
Linux 6.1 (aarch64)
Installation Method
git clone
Steps to Reproduce
On Vertex AI (vertexai=True client), configure only gemini_tools and give the agent no function tools:
from google import genai
from strands import Agent
from strands.models.gemini import GeminiModel
model = GeminiModel(
client_args={"vertexai": True, "project": "<project>", "location": "global"},
model_id="gemini-4-carbon", # same on gemini-4-argon and gemini-3.1-flash-lite
gemini_tools=[genai.types.Tool(code_execution=genai.types.ToolCodeExecution())],
)
Agent(model=model)("What is the sum of the first 50 prime numbers? Run code.")
It's the same setup as tests_integ/models/test_model_gemini.py::test_agent_with_gemini_code_execution_tool run against Vertex.
Expected Behavior
The request carries only the code-execution tool, and the model runs code and answers (5117).
Actual Behavior
google.genai.errors.ClientError: 400 Bad Request. {"error": {"code": 400, "message": "The GenerateContentRequest proto is invalid:\n * tools[0].tool_type: required one_of 'tool_type' must have one initialized field", "status": "INVALID_ARGUMENT"}}
GeminiModel._format_request_tools (strands-py/src/strands/models/gemini.py:360-376) always emits Tool(function_declarations=[]) first, even when there are no tool specs. AI Studio accepts that; Vertex rejects it, which is the same failure #1040 fixed for the no-tools-at-all case. Reproduced on gemini-4-carbon, gemini-4-argon and gemini-3.1-flash-lite, so it isn't specific to any one model. The TS GoogleModel (strands-ts/src/models/google/model.ts:327) only adds functionDeclarations when toolSpecs is non-empty, so it isn't affected.
Possible Solution
Only add the function_declarations Tool when tool_specs is non-empty. I checked this locally by monkeypatching _format_request_tools to drop the empty Tool: the same repro then runs code and answers. A unit test in tests/strands/models/test_gemini.py should assert that gemini_tools alone produces exactly those tools.
Additional Context
Artifacts
strands-agents/harness-sdk/issue/6040/vertex_gemini_tools_repro.py+vertex-gemini-tools-repro.logstrands-agents/harness-sdk/issue/6040/pytest-gemini-4-carbon-vertex.log(full integ run)
Related Issues
Part of #6038; found in #6040. Related: #1039, #1040.
I'd like to take this one if no one on the team has started it.
The fix I have in mind is small: in GeminiModel._format_request_tools, add the function_declarations Tool only when tool_specs is non-empty. This matches what the TS GoogleModel already does. The no-tools case still returns None, as #1040 intended. I'd add unit tests in tests/strands/models/test_gemini.py for:
gemini_toolsonly: no emptyfunction_declarationsTool.- function tools only.
- both: the function declarations come first, then the configured Gemini tools.
It doesn't change the public API. #3441 renames things in the same function, but it has been idle since August, so I'll keep this change minimal to avoid conflicts.
Could a maintainer confirm before I open a PR?
AI disclosure: I used Claude (Anthropic) to help investigate and draft this. I'll write and test the change myself and am responsible for it.
The scope looks good. You can take this one.