Skip to content

Commit b984403

Browse files
authored
Merge branch 'main' into feat/function-tools-enum-support
2 parents 1f19fc7 + 2f4f561 commit b984403

63 files changed

Lines changed: 6184 additions & 4364 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

contributing/samples/langchain_structured_tool_agent/agent.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@
1717
"""
1818
from google.adk.agents.llm_agent import Agent
1919
from google.adk.tools.langchain_tool import LangchainTool
20-
from langchain.tools import tool
20+
from langchain_core.tools import tool
2121
from langchain_core.tools.structured import StructuredTool
2222
from pydantic import BaseModel
2323

2424

2525
async def add(x, y) -> int:
26+
"""Adds two numbers."""
2627
return x + y
2728

2829

2930
@tool
3031
def minus(x, y) -> int:
32+
"""Subtracts two numbers."""
3133
return x - y
3234

3335

contributing/samples/live_bidi_streaming_multi_agent/agent.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from google.adk.agents.llm_agent import Agent
1818
from google.adk.examples.example import Example
19+
from google.adk.models.google_llm import Gemini
1920
from google.adk.tools.example_tool import ExampleTool
2021
from google.genai import types
2122

@@ -28,6 +29,17 @@ def roll_die(sides: int) -> int:
2829

2930
roll_agent = Agent(
3031
name="roll_agent",
32+
model=Gemini(
33+
# model="gemini-2.0-flash-live-preview-04-09", # for Vertex project
34+
model="gemini-live-2.5-flash-preview", # for AI studio key
35+
speech_config=types.SpeechConfig(
36+
voice_config=types.VoiceConfig(
37+
prebuilt_voice_config=types.PrebuiltVoiceConfig(
38+
voice_name="Kore",
39+
)
40+
)
41+
),
42+
),
3143
description="Handles rolling dice of different sizes.",
3244
instruction="""
3345
You are responsible for rolling dice based on the user's request.
@@ -69,6 +81,17 @@ def check_prime(nums: list[int]) -> str:
6981

7082
prime_agent = Agent(
7183
name="prime_agent",
84+
model=Gemini(
85+
# model="gemini-2.0-flash-live-preview-04-09", # for Vertex project
86+
model="gemini-live-2.5-flash-preview", # for AI studio key
87+
speech_config=types.SpeechConfig(
88+
voice_config=types.VoiceConfig(
89+
prebuilt_voice_config=types.PrebuiltVoiceConfig(
90+
voice_name="Puck",
91+
)
92+
)
93+
),
94+
),
7295
description="Handles checking if numbers are prime.",
7396
instruction="""
7497
You are responsible for checking whether numbers are prime.
@@ -100,8 +123,17 @@ def get_current_weather(location: str):
100123

101124
root_agent = Agent(
102125
# find supported models here: https://google.github.io/adk-docs/get-started/streaming/quickstart-streaming/
103-
model="gemini-2.0-flash-live-preview-04-09", # for Vertex project
104-
# model="gemini-live-2.5-flash-preview", # for AI studio key
126+
model=Gemini(
127+
# model="gemini-2.0-flash-live-preview-04-09", # for Vertex project
128+
model="gemini-live-2.5-flash-preview", # for AI studio key
129+
speech_config=types.SpeechConfig(
130+
voice_config=types.VoiceConfig(
131+
prebuilt_voice_config=types.PrebuiltVoiceConfig(
132+
voice_name="Zephyr",
133+
)
134+
)
135+
),
136+
),
105137
name="root_agent",
106138
instruction="""
107139
You are a helpful assistant that can check time, roll dice and check if numbers are prime.

contributing/samples/oauth_calendar_agent/README.md

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,45 @@
44

55
This sample tests and demos the OAuth support in ADK via two tools:
66

7-
* 1. list_calendar_events
7+
* 1. list_calendar_events
88

9-
This is a customized tool that calls Google Calendar API to list calendar events.
10-
It pass in the client id and client secrete to ADK and then get back the access token from ADK.
11-
And then it uses the access token to call calendar api.
9+
This is a customized tool that calls Google Calendar API to list calendar
10+
events. It pass in the client id and client secrete to ADK and then get back
11+
the access token from ADK. And then it uses the access token to call
12+
calendar api.
1213

13-
* 2. get_calendar_events
14+
* 2. get_calendar_events
1415

15-
This is an google calendar tool that calls Google Calendar API to get the details of a specific calendar.
16-
This tool is from the ADK built-in Google Calendar ToolSet.
17-
Everything is wrapped and the tool user just needs to pass in the client id and client secret.
16+
This is an google calendar tool that calls Google Calendar API to get the
17+
details of a specific calendar. This tool is from the ADK built-in Google
18+
Calendar ToolSet. Everything is wrapped and the tool user just needs to pass
19+
in the client id and client secret.
1820

1921
## How to use
2022

21-
* 1. Follow https://developers.google.com/identity/protocols/oauth2#1.-obtain-oauth-2.0-credentials-from-the-dynamic_data.setvar.console_name. to get your client id and client secret.
22-
Be sure to choose "web" as your client type.
23+
* 1. Follow
24+
https://developers.google.com/identity/protocols/oauth2#1.-obtain-oauth-2.0-credentials-from-the-dynamic_data.setvar.console_name.
25+
to get your client id and client secret. Be sure to choose "web" as your
26+
client type.
2327

24-
* 2. Configure your `.env` file to add two variables:
28+
* 2. Configure your `.env` file to add two variables:
2529

26-
* OAUTH_CLIENT_ID={your client id}
27-
* OAUTH_CLIENT_SECRET={your client secret}
30+
* OAUTH_CLIENT_ID={your client id}
31+
* OAUTH_CLIENT_SECRET={your client secret}
2832

29-
Note: don't create a separate `.env` file , instead put it to the same `.env` file that stores your Vertex AI or Dev ML credentials
33+
Note: don't create a separate `.env` file , instead put it to the same
34+
`.env` file that stores your Vertex AI or Dev ML credentials
3035

31-
* 3. Follow https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred to add http://localhost/dev-ui/ to "Authorized redirect URIs".
36+
* 3. Follow
37+
https://developers.google.com/identity/protocols/oauth2/web-server#creatingcred
38+
to add http://localhost/dev-ui/ to "Authorized redirect URIs".
3239

33-
Note: localhost here is just a hostname that you use to access the dev ui, replace it with the actual hostname you use to access the dev ui.
40+
Note: localhost here is just a hostname that you use to access the dev ui,
41+
replace it with the actual hostname you use to access the dev ui.
3442

35-
* 4. For 1st run, allow popup for localhost in Chrome.
43+
* 4. For 1st run, allow popup for localhost in Chrome.
3644

3745
## Sample prompt
3846

39-
* `List all my today's meeting from 7am to 7pm.`
40-
* `Get the details of the first event.`
47+
* `List all my today's meeting from 7am to 7pm.`
48+
* `Get the details of the first event.`
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
# Output Schema with Tools Sample Agent
22

3-
This sample demonstrates how to use structured output (`output_schema`) alongside other tools in an ADK agent. Previously, this combination was not allowed, but now it's supported through a special processor that handles the interaction.
3+
This sample demonstrates how to use structured output (`output_schema`)
4+
alongside other tools in an ADK agent. Previously, this combination was not
5+
allowed, but now it's supported through a special processor that handles the
6+
interaction.
47

58
## How it Works
69

710
The agent combines:
8-
- **Tools**: `search_wikipedia` and `get_current_year` for gathering information
9-
- **Structured Output**: `PersonInfo` schema to ensure consistent response format
11+
12+
- **Tools**: `search_wikipedia` and `get_current_year` for gathering
13+
information
14+
- **Structured Output**: `PersonInfo` schema to ensure consistent response
15+
format
1016

1117
When both `output_schema` and `tools` are specified:
12-
1. ADK automatically adds a special `set_model_response` tool
13-
2. The model can use the regular tools for information gathering
14-
3. For the final response, the model uses `set_model_response` with structured data
15-
4. ADK extracts and validates the structured response
18+
19+
1. ADK automatically adds a special `set_model_response` tool
20+
2. The model can use the regular tools for information gathering
21+
3. For the final response, the model uses `set_model_response` with structured
22+
data
23+
4. ADK extracts and validates the structured response
1624

1725
## Expected Response Format
1826

19-
The agent will return information in this structured format for user query "Tell me about Albert Einstein":
27+
The agent will return information in this structured format for user query
28+
29+
> Tell me about Albert Einstein.
2030
2131
```json
2232
{
@@ -30,7 +40,7 @@ The agent will return information in this structured format for user query "Tell
3040

3141
## Key Features Demonstrated
3242

33-
1. **Tool Usage**: Agent can search Wikipedia and get current year
34-
2. **Structured Output**: Response follows strict PersonInfo schema
35-
3. **Validation**: ADK validates the response matches the schema
36-
4. **Flexibility**: Works with any combination of tools and output schemas
43+
1. **Tool Usage**: Agent can search Wikipedia and get current year
44+
2. **Structured Output**: Response follows strict PersonInfo schema
45+
3. **Validation**: ADK validates the response matches the schema
46+
4. **Flexibility**: Works with any combination of tools and output schemas

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ test = [
114114
"anthropic>=0.43.0", # For anthropic model tests
115115
"kubernetes>=29.0.0", # For GkeCodeExecutor
116116
"langchain-community>=0.3.17",
117-
"langgraph>=0.2.60, <= 0.4.10", # For LangGraphAgent
117+
"langgraph>=0.2.60, <0.4.8", # For LangGraphAgent
118118
"litellm>=1.75.5, <2.0.0", # For LiteLLM tests
119119
"llama-index-readers-file>=0.4.0", # For retrieval tests
120120
"openai>=1.100.2", # For LiteLLM
@@ -144,7 +144,7 @@ extensions = [
144144
"crewai[tools];python_version>='3.10'", # For CrewaiTool
145145
"docker>=7.0.0", # For ContainerCodeExecutor
146146
"kubernetes>=29.0.0", # For GkeCodeExecutor
147-
"langgraph>=0.2.60", # For LangGraphAgent
147+
"langgraph>=0.2.60, <0.4.8", # For LangGraphAgent
148148
"litellm>=1.75.5", # For LiteLlm class. Currently has OpenAI limitations. TODO: once LiteLlm fix it
149149
"llama-index-readers-file>=0.4.0", # For retrieval using LlamaIndex.
150150
"llama-index-embeddings-google-genai>=0.3.0",# For files retrieval using LlamaIndex.

src/google/adk/agents/base_agent.py

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -282,27 +282,22 @@ async def run_async(
282282
Event: the events generated by the agent.
283283
"""
284284

285-
async def _run_with_trace() -> AsyncGenerator[Event, None]:
286-
with tracer.start_as_current_span(f'invoke_agent {self.name}') as span:
287-
ctx = self._create_invocation_context(parent_context)
288-
tracing.trace_agent_invocation(span, self, ctx)
289-
if event := await self._handle_before_agent_callback(ctx):
290-
yield event
291-
if ctx.end_invocation:
292-
return
293-
294-
async with Aclosing(self._run_async_impl(ctx)) as agen:
295-
async for event in agen:
296-
yield event
297-
298-
if ctx.end_invocation:
299-
return
285+
with tracer.start_as_current_span(f'invoke_agent {self.name}') as span:
286+
ctx = self._create_invocation_context(parent_context)
287+
tracing.trace_agent_invocation(span, self, ctx)
288+
if event := await self._handle_before_agent_callback(ctx):
289+
yield event
290+
if ctx.end_invocation:
291+
return
300292

301-
if event := await self._handle_after_agent_callback(ctx):
293+
async with Aclosing(self._run_async_impl(ctx)) as agen:
294+
async for event in agen:
302295
yield event
303296

304-
async with Aclosing(_run_with_trace()) as agen:
305-
async for event in agen:
297+
if ctx.end_invocation:
298+
return
299+
300+
if event := await self._handle_after_agent_callback(ctx):
306301
yield event
307302

308303
@final
@@ -320,24 +315,19 @@ async def run_live(
320315
Event: the events generated by the agent.
321316
"""
322317

323-
async def _run_with_trace() -> AsyncGenerator[Event, None]:
324-
with tracer.start_as_current_span(f'invoke_agent {self.name}') as span:
325-
ctx = self._create_invocation_context(parent_context)
326-
tracing.trace_agent_invocation(span, self, ctx)
327-
if event := await self._handle_before_agent_callback(ctx):
328-
yield event
329-
if ctx.end_invocation:
330-
return
331-
332-
async with Aclosing(self._run_live_impl(ctx)) as agen:
333-
async for event in agen:
334-
yield event
318+
with tracer.start_as_current_span(f'invoke_agent {self.name}') as span:
319+
ctx = self._create_invocation_context(parent_context)
320+
tracing.trace_agent_invocation(span, self, ctx)
321+
if event := await self._handle_before_agent_callback(ctx):
322+
yield event
323+
if ctx.end_invocation:
324+
return
335325

336-
if event := await self._handle_after_agent_callback(ctx):
326+
async with Aclosing(self._run_live_impl(ctx)) as agen:
327+
async for event in agen:
337328
yield event
338329

339-
async with Aclosing(_run_with_trace()) as agen:
340-
async for event in agen:
330+
if event := await self._handle_after_agent_callback(ctx):
341331
yield event
342332

343333
async def _run_async_impl(

src/google/adk/agents/llm_agent_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class LlmAgentConfig(BaseAgentConfig):
143143
144144
```
145145
# tools.py
146-
my_mcp_toolset = MCPToolset(
146+
my_mcp_toolset = McpToolset(
147147
connection_params=StdioServerParameters(
148148
command="npx",
149149
args=["-y", "@notionhq/notion-mcp-server"],

src/google/adk/agents/run_config.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ class StreamingMode(Enum):
3535

3636

3737
class RunConfig(BaseModel):
38-
"""Configs for runtime behavior of agents."""
38+
"""Configs for runtime behavior of agents.
39+
40+
The configs here will be overriden by agent-specific configurations.
41+
"""
3942

4043
model_config = ConfigDict(
4144
extra='forbid',

0 commit comments

Comments
 (0)