Issue Description
I'm experiencing persistent WebSocket 1011 (internal error) disconnections when using the Gemini Live API with ADK in a bidirectional streaming setup. The error occurs specifically during tool execution but not consistently - the same tool works fine sometimes and fails other times.
Error Message
websockets.exceptions.ConnectionClosedError: received 1011 (internal error) Internal error occurred.; then sent 1011 (internal error) Internal error occurred.
Stack Trace
File "/google/adk/flows/llm_flows/base_llm_flow.py", line 278, in _send_to_model
await llm_connection.send_realtime(live_request.blob)
File "/google/adk/models/gemini_llm_connection.py", line 121, in send_realtime
await self._gemini_session.send_realtime_input(media=input)
File "/google/genai/live.py", line 343, in send_realtime_input
await self._ws.send(json.dumps({'realtime_input': realtime_input_dict}))
The error occurs in send_realtime_input when the ADK tries to send audio to Gemini, suggesting Gemini has already closed the connection for an internal reason.
Environment
- ADK Version: 1.20.0
- google-genai Version: 1.53.0
- Python Version: 3.11.13
- Platform: macOS Darwin 24.6.0
- Model: gemini-2.5-flash-native-audio-preview-09-2025
- Sub-agent Model: gemini-2.0-flash-exp (for non-streaming tool calls)
- Streaming Mode: BIDI (bidirectional streaming)
Configuration
RunConfig Setup
run_config = RunConfig(
streaming_mode=StreamingMode.BIDI,
response_modalities=["AUDIO"],
input_audio_transcription=types.AudioTranscriptionConfig(),
output_audio_transcription=types.AudioTranscriptionConfig(),
session_resumption=types.SessionResumptionConfig(),
speech_config=types.SpeechConfig(
enable_proactivity=True,
enable_affective_dialog=True
),
context_window_compression=types.ContextWindowCompressionConfig(
trigger_tokens=100000,
sliding_window=types.SlidingWindow(target_tokens=80000)
)
)
Agent Setup
# Main agent with native-audio model for streaming
agent = Agent(
name="main_agent",
model="gemini-2.5-flash-native-audio-preview-09-2025",
tools=[
google_search_agent_tool, # Sub-agent using gemini-2.0-flash-exp
async_tool_1, # Makes external HTTP API calls
async_tool_2, # Performs Redis operations
async_tool_3, # Uses asyncio.gather for parallel ops
# ... several more async tools
],
instruction=AGENT_INSTRUCTION,
)
# Sub-agent using non-streaming model (required for tool execution)
google_search_sub_agent = Agent(
name="google_search_sub_agent",
model="gemini-2.0-flash-exp", # NOT native-audio
tools=[google_search],
instruction=SEARCH_INSTRUCTION,
)
Reproduction Steps
- Start bidirectional streaming session with Gemini Live API
- Send audio input from client
- Agent processes audio and decides to call an async tool that makes external API calls
- During tool execution, WebSocket connection closes with 1011 error
- Error occurs in
send_realtime_input while tool is still running
Observed Behavior
- Inconsistent: The same tool works fine in some sessions but fails in others with identical inputs
- Timing: Error can occur at various session durations (not consistently time-based)
- Tool-triggered: Happens during async tool execution, particularly tools that:
- Make external HTTP API calls (using httpx.AsyncClient)
- Perform Redis operations (using async redis client)
- Use asyncio.gather for parallel operations
- Session stats when error occurs:
- Duration: Variable (30s - 5min observed)
- Audio sent: Variable amounts
- The error happens during the tool call, not before or after
What We've Already Tried
1. Fixed Sub-Agent Model Issue
- Problem: Sub-agents were using native-audio model for
generateContent API
- Solution: Changed sub-agents to use
gemini-2.0-flash-exp
- Result: Fixed initial 404 errors, but 1011 errors persist
2. Enabled Context Window Compression
context_window_compression=types.ContextWindowCompressionConfig(
trigger_tokens=100000,
sliding_window=types.SlidingWindow(target_tokens=80000)
)
- Result: Eliminates context overflow, but 1011 errors persist
3. Enhanced Error Logging
- Added session duration tracking
- Added audio chunk/byte counting
- Added detailed error diagnostics
- Result: Can track when errors occur, but can't prevent them
4. Reduced Logging Noise
- Filtered out binary audio debug logs
- Set ADK/genai to INFO level
- Result: Cleaner logs, but 1011 errors persist
Verified NOT Quota/Limit Related
I've verified the following:
- Google AI Studio quota dashboard: No quota limits being exceeded
- API quotas: Well within documented limits for requests per minute/day
- Different error for quota issues: When I intentionally exceed quotas, I get explicit quota error messages (not 1011)
- Session duration: Errors occur at various durations (30s - 5min), not at a consistent time limit
The 1011 error is distinct from quota errors and appears to be a backend issue unrelated to documented limits.
Questions
-
Are there known issues with async tool execution during live streaming sessions causing backend disconnections, particularly for:
- Tools that make external API calls?
- Tools with longer execution times (2-5 seconds)?
- Tools using asyncio.gather for parallel operations?
-
Is the preview model (gemini-2.5-flash-native-audio-preview-09-2025) unstable for production use?
-
Could this be a backend timeout during tool execution that's not properly handled or logged?
-
How can we get more detailed error information from Gemini backend? The 1011 error message "Internal error occurred" doesn't provide actionable debugging info.
Related Issues
This appears related to:
However, our case is different because:
- We're using stable models for sub-agents (not preview models)
- Context compression is properly configured
- The same tool works sometimes and fails other times (not consistent resource exhaustion)
Workarounds Attempted
Switching to stable model: Would lose native audio support (critical for our use case)
Disabling tools: Defeats the purpose of using ADK
Reducing context: Already using context compression
None of these workarounds are viable solutions.
Expected Behavior
The WebSocket connection should remain stable during tool execution. If tools fail, they should return error responses rather than crashing the entire streaming session with a 1011 error.
Actual Behavior
Gemini backend closes the WebSocket connection with 1011 during tool execution, requiring full session restart and losing conversation context.
Impact
This issue makes ADK unusable for production voice applications that require tool use, as the connection randomly drops mid-conversation, creating a poor user experience.
Request
- Investigation into why Gemini backend closes connections during tool execution
- More detailed error messages from Gemini backend (why did it close the connection?)
- Guidance on proper error handling for async tool execution in live streaming
- Clarification on preview model stability for production use
Additional Context
We have comprehensive logging and diagnostics in place. Happy to provide more detailed logs or test specific scenarios if helpful for debugging.
Environment Summary:
- google-adk: 1.20.0
- google-genai: 1.53.0
- Python: 3.11.13
- Model: gemini-2.5-flash-native-audio-preview-09-2025 (main) + gemini-2.0-flash-exp (sub-agents)
- Streaming: Bidirectional (BIDI)
- Tools: Multiple async tools including external API calls
Issue Description
I'm experiencing persistent WebSocket 1011 (internal error) disconnections when using the Gemini Live API with ADK in a bidirectional streaming setup. The error occurs specifically during tool execution but not consistently - the same tool works fine sometimes and fails other times.
Error Message
Stack Trace
The error occurs in
send_realtime_inputwhen the ADK tries to send audio to Gemini, suggesting Gemini has already closed the connection for an internal reason.Environment
Configuration
RunConfig Setup
Agent Setup
Reproduction Steps
send_realtime_inputwhile tool is still runningObserved Behavior
What We've Already Tried
1. Fixed Sub-Agent Model Issue
generateContentAPIgemini-2.0-flash-exp2. Enabled Context Window Compression
3. Enhanced Error Logging
4. Reduced Logging Noise
Verified NOT Quota/Limit Related
I've verified the following:
The 1011 error is distinct from quota errors and appears to be a backend issue unrelated to documented limits.
Questions
Are there known issues with async tool execution during live streaming sessions causing backend disconnections, particularly for:
Is the preview model (
gemini-2.5-flash-native-audio-preview-09-2025) unstable for production use?Could this be a backend timeout during tool execution that's not properly handled or logged?
How can we get more detailed error information from Gemini backend? The 1011 error message "Internal error occurred" doesn't provide actionable debugging info.
Related Issues
This appears related to:
However, our case is different because:
Workarounds Attempted
Switching to stable model: Would lose native audio support (critical for our use case)
Disabling tools: Defeats the purpose of using ADK
Reducing context: Already using context compression
None of these workarounds are viable solutions.
Expected Behavior
The WebSocket connection should remain stable during tool execution. If tools fail, they should return error responses rather than crashing the entire streaming session with a 1011 error.
Actual Behavior
Gemini backend closes the WebSocket connection with 1011 during tool execution, requiring full session restart and losing conversation context.
Impact
This issue makes ADK unusable for production voice applications that require tool use, as the connection randomly drops mid-conversation, creating a poor user experience.
Request
Additional Context
We have comprehensive logging and diagnostics in place. Happy to provide more detailed logs or test specific scenarios if helpful for debugging.
Environment Summary: