-
Notifications
You must be signed in to change notification settings - Fork 449
feat: add gemini_tools field to GeminiModel with validation and tests #1050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add support for Gemini-specific tools like GoogleSearch and CodeExecution, with validation to prevent FunctionDeclarations and comprehensive test coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for Gemini-specific built-in tools (e.g., GoogleSearch, CodeExecution) by introducing a new gemini_tools
field to GeminiConfig
. The implementation includes validation to prevent mixing FunctionDeclarations with built-in tools and ensures proper merging of both tool types when making API requests.
Key changes:
- Added
gemini_tools
field toGeminiConfig
for Gemini-specific tools - Implemented validation function to reject FunctionDeclarations in
gemini_tools
- Updated tool formatting to merge standard function declarations with Gemini-specific tools
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/strands/models/gemini.py | Added gemini_tools config field, validation function, and tool merging logic |
tests/strands/models/test_gemini.py | Unit tests for validation logic and tool merging behavior |
tests_integ/models/test_model_gemini.py | Integration test demonstrating code execution tool usage |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
||
model_id: Required[str] | ||
params: dict[str, Any] | ||
gemini_tools: list[genai.types.Tool] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pgrayy thoughts on naming here? Would we want to be consistent among providers - maybe something like built_in_tools?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think built_in_tools is better — it’s more consistent across providers and the meaning is clearer. If you agree, I’ll make the change even though the PR has already been approved.
Add support for Gemini-specific tools like GoogleSearch and CodeExecution, with validation to prevent FunctionDeclarations and comprehensive test coverage.
Description
Background:
Gemini API provides powerful built-in tools that are distinct from standard
FunctionDeclaration
-based tools. These tools are defined in separate fields within the Gemini API'sTool
type (see https://ai.google.dev/api/caching#Tool). The existing Strands tool interface is designed around standard function declarations and cannot accommodate these Gemini-specific capabilities.Solution:
This PR implements support for Gemini's built-in tools by adding a new
gemini_tools
field toGeminiConfig
. This approach was chosen over alternatives (modifying coreToolSpec
interface or using magic string transformations) because it:genai.types.Tool
directly)Implementation Details:
Added
_validate_gemini_tools()
to ensuregemini_tools
doesn't containFunctionDeclarations
(which should use the standard tools interface):Updated
_format_request_tools()
to combine standard function declarations with Gemini-specific tools:Example Usage:
Tool Usage Tracking:
Due to the fundamental differences in how Gemini's built-in tools operate (server-side execution without explicit tool call/result blocks), this PR does not implement execution history tracking for
gemini_tools
. Clear tracking of which specific tool was invoked and when is currently difficult with the server-side execution model, and the usage patterns differ significantly from standard function tools. If tool usage tracking for Gemini built-in tools is needed in the future, it can be addressed in a separate PR. The current implementation is fully functional and independent of any future tracking enhancements.Related Issues
#1049
Documentation PR
Type of Change
New feature
Breaking change
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
hatch run prepare
Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.