Skip to content

Commit b0f0698

Browse files
xuanyang15copybara-github
authored andcommitted
chore: Add a sample agent to demonstrate that built-in google search tool and VertexAiSearchTool can be used together with other tools
PiperOrigin-RevId: 816396360
1 parent db41f54 commit b0f0698

3 files changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
This agent is to demonstrate that the built-in google search tool and the
2+
VertexAiSearchTool can be used together with other tools, even though the model
3+
has the limitation that built-in tool cannot be used by other tools.
4+
5+
It is achieved by the workarounds added in https://github.com/google/adk-python/blob/4485379a049a5c84583a43c85d444ea1f1ba6f12/src/google/adk/agents/llm_agent.py#L124-L149.
6+
7+
To run this agent, set the environment variable `VERTEXAI_DATASTORE_ID`
8+
(e.g.
9+
`projects/{project}/locations/{location}/collections/{collection}/dataStores/{dataStore}`)
10+
and use `adk web`.
11+
12+
You can follow
13+
https://cloud.google.com/generative-ai-app-builder/docs/create-data-store-es
14+
to set up the datastore.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 . import agent
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
import os
16+
import random
17+
18+
from dotenv import load_dotenv
19+
from google.adk import Agent
20+
from google.adk.tools.google_search_tool import google_search
21+
from google.adk.tools.tool_context import ToolContext
22+
from google.adk.tools.vertex_ai_search_tool import VertexAiSearchTool
23+
24+
load_dotenv(override=True)
25+
26+
VERTEXAI_DATASTORE_ID = os.getenv("VERTEXAI_DATASTORE_ID")
27+
if not VERTEXAI_DATASTORE_ID:
28+
raise ValueError("VERTEXAI_DATASTORE_ID environment variable not set")
29+
30+
31+
def roll_die(sides: int, tool_context: ToolContext) -> int:
32+
"""Roll a die and return the rolled result.
33+
34+
Args:
35+
sides: The integer number of sides the die has.
36+
37+
Returns:
38+
An integer of the result of rolling the die.
39+
"""
40+
result = random.randint(1, sides)
41+
if "rolls" not in tool_context.state:
42+
tool_context.state["rolls"] = []
43+
44+
tool_context.state["rolls"] = tool_context.state["rolls"] + [result]
45+
return result
46+
47+
48+
root_agent = Agent(
49+
model="gemini-2.5-pro",
50+
name="hello_world_agent",
51+
description="A hello world agent with multiple tools.",
52+
instruction="""
53+
You are a helpful assistant which can help user to roll dice and search for information.
54+
- Use `roll_die` tool to roll dice.
55+
- Use `VertexAISearchTool` to search for Google Agent Development Kit (ADK) information in the datastore.
56+
- Use `google_search` to search for general information.
57+
""",
58+
tools=[
59+
roll_die,
60+
VertexAiSearchTool(data_store_id=VERTEXAI_DATASTORE_ID),
61+
google_search,
62+
],
63+
)

0 commit comments

Comments
 (0)