-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Allow google search tool to set different model #4136
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
Open
lwangverizon
wants to merge
3
commits into
google:main
Choose a base branch
from
lwangverizon:feature/allow-google-search-tool-set-different-llm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+57
−1
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,17 +35,26 @@ class GoogleSearchTool(BaseTool): | |
| local code execution. | ||
| """ | ||
|
|
||
| def __init__(self, *, bypass_multi_tools_limit: bool = False): | ||
| def __init__( | ||
| self, | ||
| *, | ||
| bypass_multi_tools_limit: bool = False, | ||
| model: str | None = None, | ||
| ): | ||
| """Initializes the Google search tool. | ||
|
|
||
| Args: | ||
| bypass_multi_tools_limit: Whether to bypass the multi tools limitation, | ||
| so that the tool can be used with other tools in the same agent. | ||
| model: Optional model name to use for processing the LLM request. If | ||
| provided, this model will be used instead of the model from the | ||
| incoming llm_request. | ||
| """ | ||
|
|
||
| # Name and description are not used because this is a model built-in tool. | ||
| super().__init__(name='google_search', description='google_search') | ||
| self.bypass_multi_tools_limit = bypass_multi_tools_limit | ||
| self.model = model | ||
|
|
||
| @override | ||
| async def process_llm_request( | ||
|
|
@@ -54,6 +63,10 @@ async def process_llm_request( | |
| tool_context: ToolContext, | ||
| llm_request: LlmRequest, | ||
| ) -> None: | ||
| # If a custom model is specified, use it instead of the original model | ||
| if self.model is not None: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will actually override the model to which Agent talks to. |
||
| llm_request.model = self.model | ||
|
|
||
| llm_request.config = llm_request.config or types.GenerateContentConfig() | ||
| llm_request.config.tools = llm_request.config.tools or [] | ||
| if is_gemini_1_model(llm_request.model): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The
bypass_multi_tools_limitparameter appears to be unused within theGoogleSearchToolclass. The logic inprocess_llm_requestfor Gemini 1.x models unconditionally raises aValueErrorif other tools are present, and this check does not consultbypass_multi_tools_limit. For Gemini 2.x+ models, multiple tools are supported by default, making the flag seem redundant there as well.If this parameter is obsolete, consider removing it and the corresponding instance attribute
self.bypass_multi_tools_limitto improve code clarity. If it has a purpose that is not immediately apparent, adding a more detailed explanation in the docstring would be helpful.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 will let ADK team decide if this can be removed