Skip to content

Commit c2bca42

Browse files
authored
Merge branch 'main' into fix/cli-help-display
2 parents b64978c + dd8e9b7 commit c2bca42

File tree

39 files changed

+1645
-645
lines changed

39 files changed

+1645
-645
lines changed

contributing/samples/application_integration_agent/agent.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from google.adk.agents.llm_agent import LlmAgent
2121
from google.adk.tools.application_integration_tool import ApplicationIntegrationToolset
2222

23-
2423
# Load environment variables from .env file
2524
load_dotenv()
2625

@@ -29,7 +28,7 @@
2928
connection_location = os.getenv("CONNECTION_LOCATION")
3029

3130

32-
jira_tool = ApplicationIntegrationToolset(
31+
jira_toolset = ApplicationIntegrationToolset(
3332
project=connection_project,
3433
location=connection_location,
3534
connection=connection_name,
@@ -46,5 +45,5 @@
4645
If there is an error in the tool response, understand the error and try and see if you can fix the error and then and execute the tool again. For example if a variable or parameter is missing, try and see if you can find it in the request or user query or default it and then execute the tool again or check for other tools that could give you the details.
4746
If there are any math operations like count or max, min in the user request, call the tool to get the data and perform the math operations and then return the result in the response. For example for maximum, fetch the list and then do the math operation.
4847
""",
49-
tools=jira_tool.get_tools(),
48+
tools=[jira_toolset],
5049
)

contributing/samples/bigquery_agent/agent.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@
2626
oauth_client_secret = os.getenv("OAUTH_CLIENT_SECRET")
2727
bigquery_tool_set.configure_auth(oauth_client_id, oauth_client_secret)
2828

29-
bigquery_datasets_list = bigquery_tool_set.get_tool("bigquery_datasets_list")
30-
bigquery_datasets_get = bigquery_tool_set.get_tool("bigquery_datasets_get")
31-
bigquery_datasets_insert = bigquery_tool_set.get_tool(
32-
"bigquery_datasets_insert"
29+
tools_to_expose = [
30+
"bigquery_datasets_list",
31+
"bigquery_datasets_get",
32+
"bigquery_datasets_insert",
33+
"bigquery_tables_list",
34+
"bigquery_tables_get",
35+
"bigquery_tables_insert",
36+
]
37+
bigquery_tool_set.set_tool_filter(
38+
lambda tool, ctx=None: tool.name in tools_to_expose
3339
)
3440

35-
bigquery_tables_list = bigquery_tool_set.get_tool("bigquery_tables_list")
36-
bigquery_tables_get = bigquery_tool_set.get_tool("bigquery_tables_get")
37-
bigquery_tables_insert = bigquery_tool_set.get_tool("bigquery_tables_insert")
38-
39-
4041
root_agent = Agent(
4142
model="gemini-2.0-flash",
4243
name="bigquery_agent",
@@ -73,12 +74,5 @@
7374
{userInfo?}
7475
</User>
7576
""",
76-
tools=[
77-
bigquery_datasets_list,
78-
bigquery_datasets_get,
79-
bigquery_datasets_insert,
80-
bigquery_tables_list,
81-
bigquery_tables_get,
82-
bigquery_tables_insert,
83-
],
77+
tools=[bigquery_tool_set],
8478
)
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: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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 random
16+
17+
from google.adk import Agent
18+
from google.adk.planners import BuiltInPlanner
19+
from google.adk.planners import PlanReActPlanner
20+
from google.adk.tools.tool_context import ToolContext
21+
from google.genai import types
22+
23+
24+
def roll_die(sides: int, tool_context: ToolContext) -> int:
25+
"""Roll a die and return the rolled result.
26+
27+
Args:
28+
sides: The integer number of sides the die has.
29+
30+
Returns:
31+
An integer of the result of rolling the die.
32+
"""
33+
result = random.randint(1, sides)
34+
if not 'rolls' in tool_context.state:
35+
tool_context.state['rolls'] = []
36+
37+
tool_context.state['rolls'] = tool_context.state['rolls'] + [result]
38+
return result
39+
40+
41+
async def check_prime(nums: list[int]) -> str:
42+
"""Check if a given list of numbers are prime.
43+
44+
Args:
45+
nums: The list of numbers to check.
46+
47+
Returns:
48+
A str indicating which number is prime.
49+
"""
50+
primes = set()
51+
for number in nums:
52+
number = int(number)
53+
if number <= 1:
54+
continue
55+
is_prime = True
56+
for i in range(2, int(number**0.5) + 1):
57+
if number % i == 0:
58+
is_prime = False
59+
break
60+
if is_prime:
61+
primes.add(number)
62+
return (
63+
'No prime numbers found.'
64+
if not primes
65+
else f"{', '.join(str(num) for num in primes)} are prime numbers."
66+
)
67+
68+
69+
async def before_agent_callback(callback_context):
70+
print('@before_agent_callback')
71+
return None
72+
73+
74+
async def after_agent_callback(callback_context):
75+
print('@after_agent_callback')
76+
return None
77+
78+
79+
async def before_model_callback(callback_context, llm_request):
80+
print('@before_model_callback')
81+
return None
82+
83+
84+
async def after_model_callback(callback_context, llm_response):
85+
print('@after_model_callback')
86+
return None
87+
88+
89+
def after_agent_cb1(callback_context):
90+
print('@after_agent_cb1')
91+
92+
93+
def after_agent_cb2(callback_context):
94+
print('@after_agent_cb2')
95+
return types.Content(
96+
parts=[
97+
types.Part(
98+
text='(stopped) after_agent_cb2',
99+
),
100+
],
101+
)
102+
103+
104+
def after_agent_cb3(callback_context):
105+
print('@after_agent_cb3')
106+
107+
108+
def before_agent_cb1(callback_context):
109+
print('@before_agent_cb1')
110+
111+
112+
def before_agent_cb2(callback_context):
113+
print('@before_agent_cb2')
114+
115+
116+
def before_agent_cb3(callback_context):
117+
print('@before_agent_cb3')
118+
119+
120+
def before_tool_cb1(tool, args, tool_context):
121+
print('@before_tool_cb1')
122+
123+
124+
def before_tool_cb2(tool, args, tool_context):
125+
print('@before_tool_cb2')
126+
127+
128+
def before_tool_cb3(tool, args, tool_context):
129+
print('@before_tool_cb3')
130+
131+
132+
def after_tool_cb1(tool, args, tool_context, tool_response):
133+
print('@after_tool_cb1')
134+
135+
136+
def after_tool_cb2(tool, args, tool_context, tool_response):
137+
print('@after_tool_cb2')
138+
return {'test': 'after_tool_cb2', 'response': tool_response}
139+
140+
141+
def after_tool_cb3(tool, args, tool_context, tool_response):
142+
print('@after_tool_cb3')
143+
144+
145+
root_agent = Agent(
146+
model='gemini-2.0-flash-exp',
147+
name='data_processing_agent',
148+
description=(
149+
'hello world agent that can roll a dice of 8 sides and check prime'
150+
' numbers.'
151+
),
152+
instruction="""
153+
You roll dice and answer questions about the outcome of the dice rolls.
154+
You can roll dice of different sizes.
155+
You can use multiple tools in parallel by calling functions in parallel(in one request and in one round).
156+
It is ok to discuss previous dice roles, and comment on the dice rolls.
157+
When you are asked to roll a die, you must call the roll_die tool with the number of sides. Be sure to pass in an integer. Do not pass in a string.
158+
You should never roll a die on your own.
159+
When checking prime numbers, call the check_prime tool with a list of integers. Be sure to pass in a list of integers. You should never pass in a string.
160+
You should not check prime numbers before calling the tool.
161+
When you are asked to roll a die and check prime numbers, you should always make the following two function calls:
162+
1. You should first call the roll_die tool to get a roll. Wait for the function response before calling the check_prime tool.
163+
2. After you get the function response from roll_die tool, you should call the check_prime tool with the roll_die result.
164+
2.1 If user asks you to check primes based on previous rolls, make sure you include the previous rolls in the list.
165+
3. When you respond, you must include the roll_die result from step 1.
166+
You should always perform the previous 3 steps when asking for a roll and checking prime numbers.
167+
You should not rely on the previous history on prime results.
168+
""",
169+
tools=[
170+
roll_die,
171+
check_prime,
172+
],
173+
# planner=BuiltInPlanner(
174+
# thinking_config=types.ThinkingConfig(
175+
# include_thoughts=True,
176+
# ),
177+
# ),
178+
generate_content_config=types.GenerateContentConfig(
179+
safety_settings=[
180+
types.SafetySetting( # avoid false alarm about rolling dice.
181+
category=types.HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT,
182+
threshold=types.HarmBlockThreshold.OFF,
183+
),
184+
]
185+
),
186+
before_agent_callback=[
187+
before_agent_cb1,
188+
before_agent_cb2,
189+
before_agent_cb3,
190+
],
191+
after_agent_callback=[after_agent_cb1, after_agent_cb2, after_agent_cb3],
192+
before_model_callback=before_model_callback,
193+
after_model_callback=after_model_callback,
194+
before_tool_callback=[before_tool_cb1, before_tool_cb2, before_tool_cb3],
195+
after_tool_callback=[after_tool_cb1, after_tool_cb2, after_tool_cb3],
196+
)

0 commit comments

Comments
 (0)