Skip to content

Commit 6b49391

Browse files
KMarkertcopybara-github
authored andcommitted
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
1 parent 8a92fd1 commit 6b49391

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/google/adk/tools/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .exit_loop_tool import exit_loop
2424
from .function_tool import FunctionTool
2525
from .get_user_choice_tool import get_user_choice_tool as get_user_choice
26+
from .google_maps_grounding_tool import google_maps_grounding
2627
from .google_search_tool import google_search
2728
from .load_artifacts_tool import load_artifacts_tool as load_artifacts
2829
from .load_memory_tool import load_memory_tool as load_memory
@@ -39,6 +40,7 @@
3940
'AuthToolArguments',
4041
'BaseTool',
4142
'enterprise_web_search',
43+
'google_maps_grounding',
4244
'google_search',
4345
'url_context',
4446
'VertexAiSearchTool',
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import annotations
16+
17+
from typing import TYPE_CHECKING
18+
19+
from google.genai import types
20+
from typing_extensions import override
21+
22+
from ..utils.model_name_utils import is_gemini_1_model
23+
from ..utils.model_name_utils import is_gemini_model
24+
from .base_tool import BaseTool
25+
from .tool_context import ToolContext
26+
27+
if TYPE_CHECKING:
28+
from ..models import LlmRequest
29+
30+
31+
class GoogleMapsGroundingTool(BaseTool):
32+
"""A built-in tool that is automatically invoked by Gemini 2 models to ground query results with Google Maps.
33+
34+
This tool operates internally within the model and does not require or perform
35+
local code execution.
36+
37+
Only available for use with the VertexAI Gemini API (e.g.
38+
GOOGLE_GENAI_USE_VERTEXAI=TRUE)
39+
"""
40+
41+
def __init__(self):
42+
# Name and description are not used because this is a model built-in tool.
43+
super().__init__(name='google_maps', description='google_maps')
44+
45+
@override
46+
async def process_llm_request(
47+
self,
48+
*,
49+
tool_context: ToolContext,
50+
llm_request: LlmRequest,
51+
) -> None:
52+
llm_request.config = llm_request.config or types.GenerateContentConfig()
53+
llm_request.config.tools = llm_request.config.tools or []
54+
if is_gemini_1_model(llm_request.model):
55+
raise ValueError(
56+
'Google Maps grounding tool can not be used with Gemini 1.x models.'
57+
)
58+
elif is_gemini_model(llm_request.model):
59+
llm_request.config.tools.append(
60+
types.Tool(google_maps=types.GoogleMaps())
61+
)
62+
else:
63+
raise ValueError(
64+
f'Google maps tool is not supported for model {llm_request.model}'
65+
)
66+
67+
68+
google_maps_grounding = GoogleMapsGroundingTool()

0 commit comments

Comments
 (0)