Skip to content

Commit ac8b632

Browse files
authored
Merge branch 'main' into fix/orphaned-tool-calls-crash-loop
2 parents 562e54c + 42eeaef commit ac8b632

38 files changed

+1529
-575
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# yaml-language-server: $schema=https://raw.githubusercontent.com/google/adk-python/refs/heads/main/src/google/adk/agents/config_schemas/AgentConfig.json
22
name: search_agent
3-
model: gemini-2.0-flash
3+
model: gemini-2.5-flash
44
description: 'an agent whose job it is to perform Google search queries and answer questions about the results.'
55
instruction: You are an agent whose job is to perform Google search queries and answer questions about the results.
66
tools:
77
- name: google_search
88
generate_content_config:
99
temperature: 0.1
1010
max_output_tokens: 2000
11+
thinking_config:
12+
include_thoughts: true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2026 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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2026 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+
"""LiteLLM sample agent for SSE text streaming."""
16+
17+
from __future__ import annotations
18+
19+
from google.adk import Agent
20+
from google.adk.models.lite_llm import LiteLlm
21+
22+
root_agent = Agent(
23+
name='litellm_streaming_agent',
24+
model=LiteLlm(model='gemini/gemini-2.5-flash'),
25+
description='A LiteLLM agent used for streaming text responses.',
26+
instruction='You are a verbose assistant',
27+
)
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Copyright 2026 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+
"""Runs the LiteLLM streaming sample with SSE enabled."""
16+
17+
from __future__ import annotations
18+
19+
import asyncio
20+
21+
from dotenv import load_dotenv
22+
from google.adk.agents.run_config import RunConfig
23+
from google.adk.agents.run_config import StreamingMode
24+
from google.adk.cli.utils import logs
25+
from google.adk.runners import InMemoryRunner
26+
from google.genai import types
27+
28+
from . import agent
29+
30+
load_dotenv(override=True)
31+
logs.log_to_tmp_folder()
32+
33+
34+
async def _run_prompt(
35+
*,
36+
runner: InMemoryRunner,
37+
user_id: str,
38+
session_id: str,
39+
prompt: str,
40+
) -> None:
41+
"""Runs one prompt and prints partial chunks in real time."""
42+
content = types.Content(
43+
role='user',
44+
parts=[types.Part.from_text(text=prompt)],
45+
)
46+
47+
print(f'User: {prompt}')
48+
print('Agent: ', end='', flush=True)
49+
saw_text = False
50+
saw_partial_text = False
51+
52+
# For `adk web`, enable the `Streaming` toggle in the UI to get
53+
# partial SSE responses similar to this script.
54+
async for event in runner.run_async(
55+
user_id=user_id,
56+
session_id=session_id,
57+
new_message=content,
58+
run_config=RunConfig(streaming_mode=StreamingMode.SSE),
59+
):
60+
if not event.content:
61+
continue
62+
text = ''.join(part.text for part in event.content.parts if part.text)
63+
if not text:
64+
continue
65+
66+
if event.partial:
67+
print(text, end='', flush=True)
68+
saw_text = True
69+
saw_partial_text = True
70+
continue
71+
72+
# With SSE mode, ADK emits a final aggregated event after partial chunks.
73+
if not saw_partial_text:
74+
print(text, end='', flush=True)
75+
saw_text = True
76+
77+
if saw_text:
78+
print()
79+
else:
80+
print('(no text response)')
81+
print('------------------------------------')
82+
83+
84+
async def main() -> None:
85+
app_name = 'litellm_streaming_demo'
86+
user_id = 'user_1'
87+
runner = InMemoryRunner(agent=agent.root_agent, app_name=app_name)
88+
session = await runner.session_service.create_session(
89+
app_name=app_name,
90+
user_id=user_id,
91+
)
92+
prompts = [
93+
'Write an essay about the roman empire',
94+
'Now summarize the essay into one sentence.',
95+
]
96+
97+
for prompt in prompts:
98+
await _run_prompt(
99+
runner=runner,
100+
user_id=user_id,
101+
session_id=session.id,
102+
prompt=prompt,
103+
)
104+
105+
106+
if __name__ == '__main__':
107+
asyncio.run(main())

contributing/samples/skills_agent/agent.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@
5252
model="gemini-2.5-flash",
5353
name="skill_user_agent",
5454
description="An agent that can use specialized skills.",
55-
instruction=(
56-
"You are a helpful assistant that can leverage skills to perform tasks."
57-
),
55+
instruction=skill_toolset.DEFAULT_SKILL_SYSTEM_INSTRUCTION,
5856
tools=[
5957
my_skill_toolset,
6058
],

src/google/adk/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
from __future__ import annotations
1616

1717
from . import version
18+
from .agents.context import Context
1819
from .agents.llm_agent import Agent
1920
from .runners import Runner
2021

2122
__version__ = version.__version__
22-
__all__ = ["Agent", "Runner"]
23+
__all__ = ["Agent", "Context", "Runner"]

src/google/adk/agents/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
from .base_agent import BaseAgent
16+
from .context import Context
1617
from .invocation_context import InvocationContext
1718
from .live_request_queue import LiveRequest
1819
from .live_request_queue import LiveRequestQueue
@@ -27,6 +28,7 @@
2728
__all__ = [
2829
'Agent',
2930
'BaseAgent',
31+
'Context',
3032
'LlmAgent',
3133
'LoopAgent',
3234
'McpInstructionProvider',

0 commit comments

Comments
 (0)