Skip to content

Commit 5940387

Browse files
committed
fix: update links to the sample code and other minor fixes
fix: update links to the sample code and other minor fixes
1 parent df4d12a commit 5940387

6 files changed

Lines changed: 131 additions & 77 deletions

File tree

docs/streaming/dev-guide/part1.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,15 @@ In the following sections, you'll see each phase detailed, showing exactly when
410410

411411
These components are created once when your application starts and shared across all streaming sessions. They define your agent's capabilities, manage conversation history, and orchestrate the streaming execution.
412412

413+
!!! info "Python Version Requirement"
414+
415+
ADK requires **Python 3.10 or higher**. As of ADK v1.19.0, Python 3.9 is no longer supported. Ensure your development and production environments meet this requirement before installing ADK.
416+
413417
#### Define Your Agent
414418

415419
The `Agent` is the core of your streaming application—it defines what your AI can do, how it should behave, and which AI model powers it. You configure your agent with a specific model, tools it can use (like Google Search or custom APIs), and instructions that shape its personality and behavior.
416420

417-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/google_search_agent/agent.py#L10-L15" target="_blank">agent.py:10-15</a>'
421+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/google_search_agent/agent.py#L10-L15" target="_blank">agent.py:10-15</a>'
418422
"""Google Search Agent definition for ADK Bidi-streaming demo."""
419423

420424
import os
@@ -448,7 +452,7 @@ The ADK [Session](https://google.github.io/adk-docs/sessions/session/) manages c
448452

449453
To create a `Session`, or get an existing one for a specified `session_id`, every ADK application needs to have a [SessionService](https://google.github.io/adk-docs/sessions/session/#managing-sessions-with-a-sessionservice). For development purpose, ADK provides a simple `InMemorySessionService` that will lose the `Session` state when the application shuts down.
450454

451-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L46" target="_blank">main.py:46</a>'
455+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L37" target="_blank">main.py:37</a>'
452456
from google.adk.sessions import InMemorySessionService
453457

454458
# Define your session service
@@ -457,11 +461,18 @@ session_service = InMemorySessionService()
457461

458462
For production applications, choose a persistent session service based on your infrastructure:
459463

464+
**Use `SqliteSessionService` if:**
465+
466+
- You need lightweight local persistence without external dependencies
467+
- You're building a single-server application or development environment
468+
- You want automatic database initialization with minimal configuration
469+
- Example: `SqliteSessionService(db_path="sessions.db")`
470+
460471
**Use `DatabaseSessionService` if:**
461472

462-
- You have existing PostgreSQL/MySQL/SQLite infrastructure
473+
- You have existing PostgreSQL/MySQL infrastructure
463474
- You need full control over data storage and backups
464-
- You're running outside Google Cloud or in hybrid environments
475+
- You're running multi-server deployments requiring shared state
465476
- Example: `DatabaseSessionService(connection_string="postgresql://...")`
466477

467478
**Use `VertexAiSessionService` if:**
@@ -471,13 +482,13 @@ For production applications, choose a persistent session service based on your i
471482
- You need tight integration with Vertex AI features
472483
- Example: `VertexAiSessionService(project="my-project")`
473484

474-
Both provide the same session persistence capabilities—choose based on your infrastructure. With persistent session services, the state of the `Session` will be preserved even after application shutdown. See the [ADK Session Management documentation](https://google.github.io/adk-docs/sessions/ for more details.
485+
All three provide session persistence capabilities—choose based on your infrastructure and scale requirements. With persistent session services, the state of the `Session` will be preserved even after application shutdown. See the [ADK Session Management documentation](https://google.github.io/adk-docs/sessions/ for more details.
475486

476487
#### Define Your Runner
477488

478489
The [Runner](https://google.github.io/adk-docs/runtime/) provides the runtime for the `Agent`. It manages the conversation flow, coordinates tool execution, handles events, and integrates with session storage. You create one runner instance at application startup and reuse it for all streaming sessions.
479490

480-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L34" target="_blank">main.py:34,49-53</a>'
491+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L50" target="_blank">main.py:50,53</a>'
481492
from google.adk.runners import Runner
482493

483494
APP_NAME = "bidi-demo"
@@ -533,7 +544,7 @@ This design enables scenarios like:
533544

534545
The recommended production pattern is to check if a session exists first, then create it only if needed. This approach safely handles both new sessions and conversation resumption:
535546

536-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L110-L121" target="_blank">main.py:110-121</a>'
547+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L127-L133" target="_blank">main.py:127-133</a>'
537548
# Get or create session (handles both new sessions and reconnections)
538549
session = await session_service.get_session(
539550
app_name=APP_NAME,
@@ -560,7 +571,7 @@ This pattern works correctly in all scenarios:
560571

561572
[RunConfig](part4.md) defines the streaming behavior for this specific session—which modalities to use (text or audio), whether to enable transcription, voice activity detection, proactivity, and other advanced features.
562573

563-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L89-L95" target="_blank">main.py:89-95</a>'
574+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L98-L104" target="_blank">main.py:98-104</a>'
564575
from google.adk.agents.run_config import RunConfig, StreamingMode
565576
from google.genai import types
566577

@@ -581,7 +592,7 @@ run_config = RunConfig(
581592

582593
`LiveRequestQueue` is the communication channel for sending messages to the agent during streaming. It's a thread-safe async queue that buffers user messages (text content, audio blobs, activity signals) for orderly processing.
583594

584-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L123" target="_blank">main.py:123</a>'
595+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L135" target="_blank">main.py:135</a>'
585596
from google.adk.agents.live_request_queue import LiveRequestQueue
586597

587598
live_request_queue = LiveRequestQueue()
@@ -603,7 +614,7 @@ Once the streaming loop is running, you can send messages to the agent and recei
603614

604615
Use `LiveRequestQueue` methods to send different types of messages to the agent during the streaming session:
605616

606-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L136-L176" target="_blank">main.py:136-176</a>'
617+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L141-L189" target="_blank">main.py:141-189</a>'
607618
from google.genai import types
608619

609620
# Send text content
@@ -626,7 +637,7 @@ See [Part 2: Sending messages with LiveRequestQueue](part2.md) for detailed API
626637

627638
The `run_live()` async generator continuously yields `Event` objects as the agent processes input and generates responses. Each event represents a discrete occurrence—partial text generation, audio chunks, tool execution, transcription, interruption, or turn completion.
628639

629-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L178-L190" target="_blank">main.py:178-190</a>'
640+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L191-L206" target="_blank">main.py:191-206</a>'
630641
async for event in runner.run_live(
631642
user_id=user_id,
632643
session_id=session_id,
@@ -649,7 +660,7 @@ When the streaming session should end (user disconnects, conversation completes,
649660

650661
Send a close signal through the queue to terminate the streaming loop:
651662

652-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L213" target="_blank">main.py:213</a>'
663+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L225" target="_blank">main.py:225</a>'
653664
live_request_queue.close()
654665
```
655666

@@ -661,7 +672,7 @@ Here's a complete FastAPI WebSocket application showing all four phases integrat
661672

662673
!!! note "Complete Demo Implementation"
663674

664-
For the production-ready implementation with multimodal support (text, audio, image), see the complete [`main.py`](https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py) file.
675+
For the production-ready implementation with multimodal support (text, audio, image), see the complete [`main.py`](https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py) file.
665676

666677
**Complete Implementation:**
667678

@@ -795,7 +806,7 @@ async def websocket_endpoint(websocket: WebSocket, user_id: str, session_id: str
795806

796807
The upstream task continuously receives messages from the WebSocket client and forwards them to the `LiveRequestQueue`. This enables the user to send messages to the agent at any time, even while the agent is generating a response.
797808

798-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L129-L176" target="_blank">main.py:129-176</a>'
809+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L141-L189" target="_blank">main.py:141-189</a>'
799810
async def upstream_task() -> None:
800811
"""Receives messages from WebSocket and sends to LiveRequestQueue."""
801812
try:
@@ -811,7 +822,7 @@ async def upstream_task() -> None:
811822

812823
The downstream task continuously receives `Event` objects from `run_live()` and sends them to the WebSocket client. This streams the agent's responses, tool executions, transcriptions, and other events to the user in real-time.
813824

814-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L178-L190" target="_blank">main.py:178-190</a>'
825+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L191-L206" target="_blank">main.py:191-206</a>'
815826
async def downstream_task() -> None:
816827
"""Receives Events from run_live() and sends to WebSocket."""
817828
async for event in runner.run_live(
@@ -829,7 +840,7 @@ async def downstream_task() -> None:
829840

830841
Both tasks run concurrently using `asyncio.gather()`, enabling true Bidi-streaming. The `try/finally` block ensures `LiveRequestQueue.close()` is called even if exceptions occur, minimizing the session resource usage.
831842

832-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L195-L213" target="_blank">main.py:195-213</a>'
843+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L210-L225" target="_blank">main.py:210-225</a>'
833844
try:
834845
await asyncio.gather(
835846
upstream_task(),
@@ -855,7 +866,7 @@ This example shows the core pattern. For production applications, consider:
855866
- **Authentication and authorization**: Implement authentication and authorization for your endpoints
856867
- **Rate limiting and quotas**: Add rate limiting and timeout controls. For guidance on concurrent sessions and quota management, see [Part 4: Concurrent Live API Sessions and Quota Management](part4.md#concurrent-live-api-sessions-and-quota-management).
857868
- **Structured logging**: Use structured logging for debugging.
858-
- **Persistent session services**: Consider using persistent session services (`DatabaseSessionService` or `VertexAiSessionService`). See the [ADK Session Services documentation](https://google.github.io/adk-docs/sessions/) for more details.
869+
- **Persistent session services**: Consider using persistent session services (`SqliteSessionService`, `DatabaseSessionService`, or `VertexAiSessionService`). See the [ADK Session Services documentation](https://google.github.io/adk-docs/sessions/) for more details.
859870

860871
## 1.6 What We Will Learn
861872

docs/streaming/dev-guide/part2.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ graph LR
7373

7474
The `send_content()` method sends text messages in turn-by-turn mode, where each message represents a discrete conversation turn. This signals a complete turn to the model, triggering immediate response generation.
7575

76-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L157-L158" target="_blank">main.py:157-158</a>'
76+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L166-L171" target="_blank">main.py:166-171</a>'
7777
content = types.Content(parts=[types.Part(text=json_message["text"])])
7878
live_request_queue.send_content(content)
7979
```
@@ -103,7 +103,7 @@ For Live API, multimodal inputs (audio/video) use different mechanisms (see `sen
103103

104104
The `send_realtime()` method sends binary data streams—primarily audio, image and video—flow through the `Blob` type, which handles transmission in realtime mode. Unlike text content that gets processed in turn-by-turn mode, blobs are designed for continuous streaming scenarios where data arrives in chunks. You provide raw bytes, and Pydantic automatically handles base64 encoding during JSON serialization for safe network transmission (configured in `LiveRequest.model_config`). The MIME type helps the model understand the content format.
105105

106-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L141-L145" target="_blank">main.py:141-145</a>'
106+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L153-L156" target="_blank">main.py:153-156</a>'
107107
audio_blob = types.Blob(
108108
mime_type="audio/pcm;rate=16000",
109109
data=audio_data
@@ -163,7 +163,7 @@ The `close` signal provides graceful termination semantics for streaming session
163163

164164
See [Part 4: Understanding RunConfig](part4.md#streamingmode-bidi-or-sse) for detailed comparison and when to use each mode.
165165

166-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L195-L213" target="_blank">main.py:195-213</a>'
166+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L210-L225" target="_blank">main.py:210-225</a>'
167167
try:
168168
logger.debug("Starting asyncio.gather for upstream and downstream tasks")
169169
await asyncio.gather(
@@ -199,7 +199,7 @@ Understanding how `LiveRequestQueue` handles concurrency is essential for buildi
199199

200200
**Why synchronous send methods?** Convenience and simplicity. You can call them from anywhere in your async code without `await`:
201201

202-
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/main/python/agents/bidi-demo/app/main.py#L129-L158" target="_blank">main.py:129-158</a>'
202+
```python title='Demo implementation: <a href="https://github.com/google/adk-samples/blob/4274c70ae3f4c68595f543ee504474747ea9f0da/python/agents/bidi-demo/app/main.py#L141-L171" target="_blank">main.py:141-171</a>'
203203
async def upstream_task() -> None:
204204
"""Receives messages from WebSocket and sends to LiveRequestQueue."""
205205
while True:

0 commit comments

Comments
 (0)