Skip to content

Commit 98d2a58

Browse files
authored
fix: updated adk version to 1.10.0 (#589)
* fix: updated adk version to 1.10.0 fix: updated adk version to 1.10.0, and confirmed the demos work properly. * fix: add session resumption fix: add session resumption * fix: adding session resumption to the docs. fix: adding session resumption to the docs.
1 parent f563df6 commit 98d2a58

File tree

6 files changed

+126
-15
lines changed

6 files changed

+126
-15
lines changed

docs/streaming/custom-streaming-ws.md

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ In order to use voice/video streaming in ADK, you will need to use Gemini models
1313

1414
There is also a [SSE](custom-streaming.md) version of the sample is available.
1515

16-
## 1. Install ADK { #install-adk }
16+
## 1. Install ADK {#1.-setup-installation}
1717

1818
Create & Activate Virtual Environment (Recommended):
1919

@@ -64,7 +64,7 @@ adk-streaming-ws/
6464
└── agent.py # Agent definition
6565
```
6666

67-
## 2\. Set up the platform { #set-up-the-platform }
67+
## 2\. Set up the platform {#2.-set-up-the-platform}
6868

6969
To run the sample app, choose a platform from either Google AI Studio or Google Cloud Vertex AI:
7070

@@ -125,7 +125,7 @@ Notice how easily you integrated [grounding with Google Search](https://ai.googl
125125

126126
![intro_components.png](../assets/quickstart-streaming-tool.png)
127127

128-
## 3\. Interact with Your Streaming app { #interact-with-your-streaming-app }
128+
## 3\. Interact with Your Streaming app {#3.-interact-with-your-streaming-app}
129129

130130
1\. **Navigate to the Correct Directory:**
131131

@@ -180,7 +180,7 @@ These console logs are important in case you develop your own streaming applicat
180180
- **When `ws://` doesn't work:** If you see any errors on the Chrome DevTools with regard to `ws://` connection, try replacing `ws://` with `wss://` on `app/static/js/app.js` at line 28. This may happen when you are running the sample on a cloud environment and using a proxy connection to connect from your browser.
181181
- **When `gemini-2.0-flash-exp` model doesn't work:** If you see any errors on the app server console with regard to `gemini-2.0-flash-exp` model availability, try replacing it with `gemini-2.0-flash-live-001` on `app/google_search_agent/agent.py` at line 6.
182182

183-
## 4. Server code overview { #server-code-overview }
183+
## 4. Server code overview {#4.-server-side-code-overview}
184184

185185
This server app enables real-time, streaming interaction with ADK agent via WebSockets. Clients send text/audio to the ADK agent and receive streamed text/audio responses.
186186

@@ -245,6 +245,12 @@ async def start_agent_session(user_id, is_audio=False):
245245
# Set response modality
246246
modality = "AUDIO" if is_audio else "TEXT"
247247
run_config = RunConfig(response_modalities=[modality])
248+
249+
# Optional: Enable session resumption for improved reliability
250+
# run_config = RunConfig(
251+
# response_modalities=[modality],
252+
# session_resumption=types.SessionResumptionConfig()
253+
# )
248254

249255
# Create a LiveRequestQueue for this session
250256
live_request_queue = LiveRequestQueue()
@@ -276,6 +282,49 @@ This function initializes an ADK agent live session.
276282

277283
**Returns:** `(live_events, live_request_queue)`.
278284

285+
### Session Resumption Configuration
286+
287+
ADK supports live session resumption to improve reliability during streaming conversations. This feature enables automatic reconnection when live connections are interrupted due to network issues.
288+
289+
#### Enabling Session Resumption
290+
291+
To enable session resumption, you need to:
292+
293+
1. **Import the required types**:
294+
```py
295+
from google.genai import types
296+
```
297+
298+
2. **Configure session resumption in RunConfig**:
299+
```py
300+
run_config = RunConfig(
301+
response_modalities=[modality],
302+
session_resumption=types.SessionResumptionConfig()
303+
)
304+
```
305+
306+
#### Session Resumption Features
307+
308+
- **Automatic Handle Caching** - The system automatically caches session resumption handles during live conversations
309+
- **Transparent Reconnection** - When connections are interrupted, the system attempts to resume using cached handles
310+
- **Context Preservation** - Conversation context and state are maintained across reconnections
311+
- **Network Resilience** - Provides better user experience during unstable network conditions
312+
313+
#### Implementation Notes
314+
315+
- Session resumption handles are managed internally by the ADK framework
316+
- No additional client-side code changes are required
317+
- The feature is particularly beneficial for long-running streaming conversations
318+
- Connection interruptions become less disruptive to the user experience
319+
320+
#### Troubleshooting
321+
322+
If you encounter errors with session resumption:
323+
324+
1. **Check model compatibility** - Ensure you're using a model that supports session resumption
325+
2. **API limitations** - Some session resumption features may not be available in all API versions
326+
3. **Remove session resumption** - If issues persist, you can disable session resumption by removing the `session_resumption` parameter from `RunConfig`
327+
279328
### `agent_to_client_messaging(websocket, live_events)`
280329

281330
```py
@@ -440,7 +489,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: int, is_audio: str):
440489
* `agent_to_client_messaging`: ADK `live_events` -> Client WebSocket.
441490
4. Bidirectional streaming continues until disconnection or error.
442491

443-
## 5. Client code overview { #client-code-overview }
492+
## 5. Client code overview {#5.-client-side-code-overview}
444493

445494
The JavaScript `app.js` (in `app/static/js`) manages client-side interaction with the ADK Streaming WebSocket backend. It handles sending text/audio and receiving/displaying streamed responses.
446495

docs/streaming/custom-streaming.md

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This article overviews the server and client code for a custom asynchronous web
1818

1919
There is also a [WebSocket](custom-streaming-ws.md) version of the sample is available.
2020

21-
## 1. Install ADK { #install-adk }
21+
## 1. Install ADK {#1.-setup-installation}
2222

2323
Create & Activate Virtual Environment (Recommended):
2424

@@ -69,7 +69,7 @@ adk-streaming/
6969
└── agent.py # Agent definition
7070
```
7171

72-
## 2\. Set up the platform { #set-up-the-platform }
72+
## 2\. Set up the platform {#2.-set-up-the-platform}
7373

7474
To run the sample app, choose a platform from either Google AI Studio or Google Cloud Vertex AI:
7575

@@ -105,7 +105,7 @@ To run the sample app, choose a platform from either Google AI Studio or Google
105105
```
106106

107107

108-
## 3\. Interact with Your Streaming app { #interact-with-your-streaming-app }
108+
## 3\. Interact with Your Streaming app {#3.-interact-with-your-streaming-app}
109109

110110
1\. **Navigate to the Correct Directory:**
111111

@@ -158,7 +158,7 @@ These console logs are important in case you develop your own streaming applicat
158158
- **When your browser can't connect to the server via SSH proxy:** SSH proxy used in various cloud services may not work with SSE. Please try without SSH proxy, such as using a local laptop, or try the [WebSocket](custom-streaming-ws.md) version.
159159
- **When `gemini-2.0-flash-exp` model doesn't work:** If you see any errors on the app server console with regard to `gemini-2.0-flash-exp` model availability, try replacing it with `gemini-2.0-flash-live-001` on `app/google_search_agent/agent.py` at line 6.
160160

161-
## 4. Agent definition { #agent-definition }
161+
## 4. Agent definition
162162

163163
The agent definition code `agent.py` in the `google_search_agent` folder is where the agent's logic is written:
164164

@@ -184,7 +184,7 @@ Notice how easily you integrated [grounding with Google Search](https://ai.googl
184184

185185
The server and client architecture enables real-time, bidirectional communication between web clients and AI agents with proper session isolation and resource management.
186186

187-
## 5. Server side code overview { #server-side-code-overview }
187+
## 5. Server side code overview {#5.-server-side-code-overview}
188188

189189
The FastAPI server provides real-time communication between web clients and the AI agent.
190190

@@ -210,6 +210,11 @@ The FastAPI server provides real-time communication between web clients and the
210210
- **Stream Resilience** - SSE streams handle exceptions and perform cleanup automatically
211211
- **Connection Recovery** - Clients can reconnect by re-establishing SSE connection
212212

213+
#### Session Resumption:
214+
- **Live Session Resumption** - Enables transparent reconnection to interrupted live conversations
215+
- **Handle Caching** - System automatically caches session handles for recovery
216+
- **Reliability Enhancement** - Improves resilience against network instability during streaming
217+
213218

214219
### Agent Session Management
215220

@@ -234,6 +239,12 @@ async def start_agent_session(user_id, is_audio=False):
234239
# Set response modality
235240
modality = "AUDIO" if is_audio else "TEXT"
236241
run_config = RunConfig(response_modalities=[modality])
242+
243+
# Optional: Enable session resumption for improved reliability
244+
# run_config = RunConfig(
245+
# response_modalities=[modality],
246+
# session_resumption=types.SessionResumptionConfig()
247+
# )
237248

238249
# Create a LiveRequestQueue for this session
239250
live_request_queue = LiveRequestQueue()
@@ -382,6 +393,49 @@ async def sse_endpoint(user_id: int, is_audio: str = "false"):
382393

383394
- **Cleanup Logic** - Handles connection termination by closing the request queue and removing from active sessions, with error handling for stream interruptions.
384395

396+
### Session Resumption Configuration
397+
398+
ADK supports live session resumption to improve reliability during streaming conversations. This feature enables automatic reconnection when live connections are interrupted due to network issues.
399+
400+
#### Enabling Session Resumption
401+
402+
To enable session resumption, you need to:
403+
404+
1. **Import the required types**:
405+
```py
406+
from google.genai import types
407+
```
408+
409+
2. **Configure session resumption in RunConfig**:
410+
```py
411+
run_config = RunConfig(
412+
response_modalities=[modality],
413+
session_resumption=types.SessionResumptionConfig()
414+
)
415+
```
416+
417+
#### Session Resumption Features
418+
419+
- **Automatic Handle Caching** - The system automatically caches session resumption handles during live conversations
420+
- **Transparent Reconnection** - When connections are interrupted, the system attempts to resume using cached handles
421+
- **Context Preservation** - Conversation context and state are maintained across reconnections
422+
- **Network Resilience** - Provides better user experience during unstable network conditions
423+
424+
#### Implementation Notes
425+
426+
- Session resumption handles are managed internally by the ADK framework
427+
- No additional client-side code changes are required
428+
- The feature is particularly beneficial for long-running streaming conversations
429+
- Connection interruptions become less disruptive to the user experience
430+
431+
#### Troubleshooting
432+
433+
If you encounter errors with session resumption:
434+
435+
1. **Check model compatibility** - Ensure you're using a model that supports session resumption
436+
2. **API limitations** - Some session resumption features may not be available in all API versions
437+
3. **Remove session resumption** - If issues persist, you can disable session resumption by removing the `session_resumption` parameter from `RunConfig`
438+
385439
#### Message Sending Endpoint
386440

387441
```py
@@ -427,7 +481,7 @@ async def send_message_endpoint(user_id: int, request: Request):
427481
- **Error Handling** - Returns appropriate error responses for unsupported MIME types or missing sessions.
428482

429483

430-
## 6. Client side code overview { #client-side-code-overview }
484+
## 6. Client side code overview {#6.-client-side-code-overview}
431485

432486
The client-side consists of a web interface with real-time communication and audio capabilities:
433487

examples/python/snippets/streaming/adk-streaming-ws/app/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from google.adk.runners import InMemoryRunner
3131
from google.adk.agents import LiveRequestQueue
3232
from google.adk.agents.run_config import RunConfig
33+
from google.genai import types
3334

3435
from fastapi import FastAPI, WebSocket
3536
from fastapi.staticfiles import StaticFiles
@@ -66,7 +67,10 @@ async def start_agent_session(user_id, is_audio=False):
6667

6768
# Set response modality
6869
modality = "AUDIO" if is_audio else "TEXT"
69-
run_config = RunConfig(response_modalities=[modality])
70+
run_config = RunConfig(
71+
response_modalities=[modality],
72+
session_resumption=types.SessionResumptionConfig()
73+
)
7074

7175
# Create a LiveRequestQueue for this session
7276
live_request_queue = LiveRequestQueue()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google-adk==1.9.0
1+
google-adk==1.10.0

examples/python/snippets/streaming/adk-streaming/app/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from google.adk.runners import InMemoryRunner
3030
from google.adk.agents import LiveRequestQueue
3131
from google.adk.agents.run_config import RunConfig
32+
from google.genai import types
3233

3334
from fastapi import FastAPI, Request
3435
from fastapi.staticfiles import StaticFiles
@@ -66,7 +67,10 @@ async def start_agent_session(user_id, is_audio=False):
6667

6768
# Set response modality
6869
modality = "AUDIO" if is_audio else "TEXT"
69-
run_config = RunConfig(response_modalities=[modality])
70+
run_config = RunConfig(
71+
response_modalities=[modality],
72+
session_resumption=types.SessionResumptionConfig()
73+
)
7074

7175
# Create a LiveRequestQueue for this session
7276
live_request_queue = LiveRequestQueue()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google-adk==1.2.1
1+
google-adk==1.10.0

0 commit comments

Comments
 (0)