Skip to content

Conversation

pshiko
Copy link

@pshiko pshiko commented Oct 16, 2025

Description

GeminiModel fails with 400 INVALID_ARGUMENT when no tools are provided in Vertex AI mode (GOOGLE_GENAI_USE_VERTEXAI=True). This issue does not occur with the standard Gemini API.

Root Cause:
The current implementation always sends a tools field with an empty function_declarations array. Vertex AI strictly enforces the proto oneof definition and rejects empty arrays, while the standard API accepts them.

Solution:
Modified _format_request_config to only include tools when tools are provided:

tools=self._format_request_tools(tool_specs) if tool_specs else None,

Changes:

  • src/strands/models/gemini.py: Updated _format_request_config to conditionally set tools
  • tests/strands/models/test_gemini.py: Updated unit tests to remove empty tools arrays from expected configs

Note:
This is a validation difference between the standard Gemini API and Vertex AI. While it may be a Gemini API inconsistency, the SDK must support both deployment modes. Omitting the tools field when no tools are provided works correctly for both backends.

Related Issues

#1039

Documentation PR

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Copilot Copilot AI review requested due to automatic review settings October 16, 2025 17:44
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Fix GeminiModel to omit empty tools in Vertex AI mode to avoid INVALID_ARGUMENT errors caused by sending an empty function_declarations array.

  • Conditionally set tools in _format_request_config only when tool_specs are provided.
  • Updated tests to remove empty tools arrays from expected request configs.
  • Ensures compatibility with both standard Gemini API and Vertex AI by aligning with Vertex AI’s oneof validation rules.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/strands/models/gemini.py Applies conditional inclusion of tools in GenerateContentConfig to prevent sending empty tools.
tests/strands/models/test_gemini.py Updates expected configs across tests to no longer include empty tools arrays.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant