mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
feat: Add Google Maps Grounding Tool to ADK
This add `GoogleMapsGroundingTool`, a built-in tool for Gemini 2 models to ground query results with Google Maps. This tool operates internally within the model and is only available when using the VertexAI Gemini API. PiperOrigin-RevId: 808650501
This commit is contained in:
committed by
Copybara-Service
parent
8a92fd18b6
commit
6b49391546
@@ -23,6 +23,7 @@ from .example_tool import ExampleTool
|
||||
from .exit_loop_tool import exit_loop
|
||||
from .function_tool import FunctionTool
|
||||
from .get_user_choice_tool import get_user_choice_tool as get_user_choice
|
||||
from .google_maps_grounding_tool import google_maps_grounding
|
||||
from .google_search_tool import google_search
|
||||
from .load_artifacts_tool import load_artifacts_tool as load_artifacts
|
||||
from .load_memory_tool import load_memory_tool as load_memory
|
||||
@@ -39,6 +40,7 @@ __all__ = [
|
||||
'AuthToolArguments',
|
||||
'BaseTool',
|
||||
'enterprise_web_search',
|
||||
'google_maps_grounding',
|
||||
'google_search',
|
||||
'url_context',
|
||||
'VertexAiSearchTool',
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
# Copyright 2025 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from google.genai import types
|
||||
from typing_extensions import override
|
||||
|
||||
from ..utils.model_name_utils import is_gemini_1_model
|
||||
from ..utils.model_name_utils import is_gemini_model
|
||||
from .base_tool import BaseTool
|
||||
from .tool_context import ToolContext
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..models import LlmRequest
|
||||
|
||||
|
||||
class GoogleMapsGroundingTool(BaseTool):
|
||||
"""A built-in tool that is automatically invoked by Gemini 2 models to ground query results with Google Maps.
|
||||
|
||||
This tool operates internally within the model and does not require or perform
|
||||
local code execution.
|
||||
|
||||
Only available for use with the VertexAI Gemini API (e.g.
|
||||
GOOGLE_GENAI_USE_VERTEXAI=TRUE)
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
# Name and description are not used because this is a model built-in tool.
|
||||
super().__init__(name='google_maps', description='google_maps')
|
||||
|
||||
@override
|
||||
async def process_llm_request(
|
||||
self,
|
||||
*,
|
||||
tool_context: ToolContext,
|
||||
llm_request: LlmRequest,
|
||||
) -> None:
|
||||
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):
|
||||
raise ValueError(
|
||||
'Google Maps grounding tool can not be used with Gemini 1.x models.'
|
||||
)
|
||||
elif is_gemini_model(llm_request.model):
|
||||
llm_request.config.tools.append(
|
||||
types.Tool(google_maps=types.GoogleMaps())
|
||||
)
|
||||
else:
|
||||
raise ValueError(
|
||||
f'Google maps tool is not supported for model {llm_request.model}'
|
||||
)
|
||||
|
||||
|
||||
google_maps_grounding = GoogleMapsGroundingTool()
|
||||
Reference in New Issue
Block a user