streaming-patterns
Configure ADK bidi-streaming for real-time multimodal interactions. Use when building live voice/video agents, implementing real-time streaming, configuring LiveRequestQueue, setting up audio/video processing, or when user mentions bidi-streaming, real-time agents, streaming tools, multimodal streaming, or Gemini Live API.
What this skill does
# ADK Streaming Patterns
Comprehensive patterns for configuring Google ADK bidi-streaming (bidirectional streaming) to build real-time, multimodal AI agents with voice, video, and streaming tool capabilities.
## Core Concepts
ADK bidi-streaming enables low-latency, bidirectional communication between users and AI agents with:
- **Real-time interaction**: Process and respond while user is still providing input
- **Natural interruption**: User can interrupt agent mid-response
- **Multimodal support**: Text, audio, and video inputs/outputs
- **Streaming tools**: Tools that yield intermediate results over time
- **Session persistence**: Maintain context across ~10-minute connection timeouts
## Quick Start Patterns
### 1. Basic Bidi-Streaming Setup
```python
from google.adk.agents import Agent
from google.adk.agents.run_config import RunConfig, StreamingMode
from google.genai import types
# Configure for audio streaming
run_config = RunConfig(
response_modalities=["AUDIO"],
streaming_mode=StreamingMode.BIDI
)
# Run agent with bidi-streaming
async for event in agent.run_live(request_queue, run_config=run_config):
if event.server_content:
# Handle streaming response
handle_response(event)
```
### 2. LiveRequestQueue Pattern
```python
from google.adk.agents import LiveRequestQueue
# Create queue for multimodal inputs
request_queue = LiveRequestQueue()
# Enqueue text
await request_queue.put("What's the weather?")
# Enqueue audio chunks
await request_queue.put(audio_bytes)
# Signal activity boundaries
await request_queue.put(types.LiveClientRealtimeInput(
media_chunks=[types.LiveClientRealtimeInputMediaChunk(
data=audio_chunk
)]
))
```
## Configuration Patterns
### Response Modalities
**CRITICAL**: Only ONE response modality per session. Cannot switch mid-session.
```python
# Audio output (voice agent)
RunConfig(response_modalities=["AUDIO"])
# Text output (chat agent)
RunConfig(response_modalities=["TEXT"])
```
### Session Management
**Session Resumption** (automatic reconnection):
```python
RunConfig(
session_resumption=types.SessionResumptionConfig()
)
```
**Context Window Compression** (unlimited sessions):
```python
RunConfig(
context_window_compression=types.ContextWindowCompressionConfig(
trigger_tokens=100000,
sliding_window=types.SlidingWindow(target_tokens=80000)
)
)
```
### Audio Configuration
See templates/audio-config.py for speech and transcription settings.
### Platform Selection
Use environment variable (no code changes needed):
```bash
# Google AI Studio (Gemini Live API)
export GOOGLE_GENAI_USE_VERTEXAI=FALSE
# Vertex AI (Live API)
export GOOGLE_GENAI_USE_VERTEXAI=TRUE
```
## Streaming Tools Pattern
Define tools as async generators for continuous results:
```python
@streaming_tool
async def monitor_stock(symbol: str):
"""Stream real-time stock price updates."""
while True:
price = await fetch_current_price(symbol)
yield f"Current price: ${price}"
await asyncio.sleep(1)
```
See templates/streaming-tool-template.py for complete pattern.
## Event Handling
Process events from run_live():
```python
async for event in agent.run_live(request_queue, run_config=run_config):
# Server content (agent responses)
if event.server_content:
if event.server_content.model_turn:
# Text/audio from model
process_model_response(event.server_content.model_turn)
if event.server_content.turn_complete:
# Agent finished speaking
handle_turn_complete()
# Tool calls
if event.tool_call:
# ADK executes tools automatically
log_tool_execution(event.tool_call)
# Interruptions
if event.interrupted:
handle_interruption()
```
## Multi-Agent Streaming
Transfer stateful sessions between agents:
```python
# Agent 1 creates session
session = await agent1.run_live(request_queue, run_config=config)
# Transfer to Agent 2 (seamless handoff)
await agent2.run_live(
request_queue,
run_config=config,
session=session # Maintains conversation context
)
```
## Workflows
### Complete Bidi-Streaming Agent Workflow
1. **Configure RunConfig**
- Choose response modality (AUDIO or TEXT)
- Enable session resumption
- Configure context window compression (optional)
- Set audio/speech configs (for audio modality)
2. **Create LiveRequestQueue**
- Initialize queue for multimodal inputs
- Enqueue messages as they arrive
- Use activity markers for segmentation
3. **Implement Event Handling**
- Process server_content for agent responses
- Handle tool_call events
- Manage interruption events
- Track turn_complete signals
4. **Define Streaming Tools** (optional)
- Use async generators for continuous output
- Yield intermediate results over time
- Support real-time monitoring/analysis
5. **Test and Deploy**
- Validate audio/video processing
- Test interruption handling
- Verify session resumption
- Monitor quota usage
### Audio/Video Workflow
See examples/audio-video-agent.py for complete multimodal setup including:
- Audio input processing
- Video frame handling
- Speech configuration
- Transcription settings
## Templates
All templates use placeholders only (no hardcoded API keys):
- **templates/bidi-streaming-config.py**: Complete RunConfig patterns
- **templates/streaming-tool-template.py**: Async generator tool pattern
- **templates/audio-config.py**: Speech and transcription setup
- **templates/video-config.py**: Video frame processing
- **templates/liverequest-queue.py**: Queue management patterns
- **templates/event-handler.py**: Event processing patterns
## Scripts
Utility scripts for validation and setup:
- **scripts/validate-streaming-config.py**: Validate RunConfig settings
- **scripts/test-liverequest-queue.py**: Test queue functionality
- **scripts/check-modality-support.py**: Verify modality compatibility
## Examples
Real-world streaming agent implementations:
- **examples/voice-agent.py**: Complete audio streaming agent
- **examples/video-agent.py**: Multimodal video processing agent
- **examples/streaming-tool-agent.py**: Agent with streaming tools
- **examples/multi-agent-handoff.py**: Session transfer between agents
## Best Practices
1. **Choose Modality Carefully**: Cannot switch response modality mid-session
2. **Use Session Resumption**: Prevent disconnection issues
3. **Enable Context Compression**: For extended conversations
4. **Implement Streaming Tools**: For real-time monitoring/analysis
5. **Handle Interruptions**: Natural conversation requires interruption support
6. **Segment Context**: Use activity markers for logical event boundaries
7. **Test Platform Switch**: Verify behavior on both AI Studio and Vertex AI
## Common Patterns
### Pattern 1: Voice Agent with Interruption
See examples/voice-agent.py
### Pattern 2: Streaming Analysis Tool
See examples/streaming-tool-agent.py
### Pattern 3: Multi-Agent Coordination
See examples/multi-agent-handoff.py
## References
- [ADK Bidi-streaming Docs](https://google.github.io/adk-docs/streaming/)
- [RunConfig Guide (Part 4)](https://google.github.io/adk-docs/streaming/dev-guide/part4/)
- [Audio/Video Guide (Part 5)](https://google.github.io/adk-docs/streaming/dev-guide/part5/)
- [Real-Time Multi-Agent Architecture](https://developers.googleblog.com/beyond-request-response-architecting-real-time-bidirectional-streaming-multi-agent-system/)
## Security Compliance
This skill follows strict security rules:
- All code examples use placeholder values only
- No real API keys, passwords, or secrets
- Environment variable references in all code
- `.gitignore` protection documented
Related in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.