fix(bidi): Gemini 3.1 Flash Live compatibility for BidiGeminiLiveModel#2000
Open
jrdeck wants to merge 1 commit intostrands-agents:mainfrom
Open
fix(bidi): Gemini 3.1 Flash Live compatibility for BidiGeminiLiveModel#2000jrdeck wants to merge 1 commit intostrands-agents:mainfrom
jrdeck wants to merge 1 commit intostrands-agents:mainfrom
Conversation
Three fixes for Gemini 3.1 Flash Live (`gemini-3.1-flash-live-preview`):
1. Route text input through `send_realtime_input` instead of
`send_client_content`. Gemini 3.1 only accepts `send_client_content`
for seeding initial context history — mid-session text causes error
1007. `send_realtime_input(text=...)` is compatible with both 2.5
and 3.1 models.
2. Only include `session_resumption` in live config when a handle is
provided. Sending `{"handle": null}` causes Gemini 3.1 to reject
the session with error 1007.
3. Default `api_version` from `v1alpha` to `v1beta`. `v1alpha` is not
a documented Gemini Developer API version; `v1beta` is the correct
endpoint for the Live API.
Closes strands-agents#1999
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes three incompatibilities that prevent
BidiGeminiLiveModelfrom working withgemini-3.1-flash-live-preview.Closes #1999
Changes
1. Route text input through
send_realtime_inputGemini 3.1 Flash Live only allows
send_client_contentfor seeding initial context history. Mid-session text (e.g.BidiTextInputEventfrom aBidiAgentauto-greeting) must usesend_realtime_input(text=...)instead. This path is also compatible with Gemini 2.5 models — no regression.Before:
_send_text_content→send_client_content→ error 1007After:
_send_text_content→send_realtime_input(text=...)→ audio response2. Omit
session_resumptionwhen no handle exists_build_live_configunconditionally injectedsession_resumption: {"handle": None}. Gemini 3.1 rejects this; 2.5 silently accepted it. Now only included when a handle is actually provided.3. Default
api_versiontov1beta_resolve_client_configdefaulted tov1alpha, which is not a documented Gemini Developer API version. Changed tov1beta— the correct endpoint for the Live API per Google's documentation.Test plan
test_gemini_live.pytests passsend_realtime_input(text=...)instead ofsend_client_contentgemini-3.1-flash-live-previewreturns audio chunks in response to text sent viasend_realtime_inputgemini-2.5-flash-native-audio-latestworks with the same code pathContext
Discovered by Clevvi while building a multi-agent voice assistant on Bedrock AgentCore + Strands. The workaround (subclassing
BidiGeminiLiveModel) is deployed in production — this PR upstreams the fix.