-
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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.
Contributor
Author
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. The intention is to give users the ability to choose different models than the root agent for Google Search to use to summarize search results. |
||
| 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): | ||
|
|
||
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