本文說明從 Gemini 2.5 Flash Live API Native Audio 遷移至 Gemini 3.8 Live 時,需要進行哪些變更。
函式呼叫變更
Gemini 2.5 Flash Live API Native Audio 伺服器允許非同步工具呼叫。相較之下,Gemini 3.8 Live 支援非同步函式呼叫,行為變更如下:
如果函式宣告在設定中宣告
behavior=BLOCKING,Gemini 3.8 Live 支援封鎖函式呼叫。如果在執行封鎖函式呼叫期間收到新輸入內容,Gemini Live API 伺服器會取消目前的函式呼叫。scheduling=interrupt的FunctionResponse選項行為有所變更:FunctionResponse排程說話者 Gemini 2.5 Flash Live API 原生音訊 Gemini 3.8 Live interrupt 模型 立即停止模型的回覆,並播放工具的回覆。 立即停止模型的回覆,並播放工具的回覆。 interrupt 使用者 立即中斷,並在使用者說話時播放工具的回覆。 等待使用者說完,再播放工具的回覆。
減少多餘的掃描和函式呼叫重試
如果工具未傳回任何結果,Gemini 3.8 Live 有時會在單一回合中,連續執行多餘的函式呼叫。包括重複變更參數、掃描兩到五次,然後再回應。這種行為會增加第一個音訊生成時間 (TTFA),並產生不準確的備用語音。
Gemini 3.8 Live 嘗試解析查詢時,會導致重複的連續函式呼叫。如果工具傳回無意義或空白的回覆 (例如 {"results": [], "total_available": 0} 或 None),模型就無法區分「永久耗盡」、「查詢時間範圍太窄」或「引數無效」。模型會嘗試擴大或變更查詢,以改善結果,並開始掃描。
請採取下列輔助做法:
傳回資訊豐富的函式回應:每個工具回應都必須包含錯誤或結果的相關資訊,引導 Gemini 3.8 Live 模型如何繼續。
下表說明各種情況、模型應如何回應,以及協助模型所需的酬載範例:
案件 模型應採取的行動 必要酬載內容 有效查詢,但未傳回任何結果。重試並無法解決此問題。 停止搜尋、通知使用者,並提供替代方案。 status: 'no_results'、
retryable: false、
以及清楚易懂的自然語言訊息。引數無效或不存在 (例如「供應商錯誤」)。 停止搜尋,並請使用者釐清或確認。 status: 'invalid_argument'、
reason_code、
retryable: false和
valid_options清單有效查詢,但視窗空白。擴大查詢範圍確實有幫助。 執行一次合理的重試。 status: 'no_results_in_range'、
retryable: true和
retry_hint以下範例示範呼叫
search_appointment,但所有可能日期都無法使用的酬載。使用者希望試用供應商,而不是掃描日期:def search_appointment(vendor: str, date: Datetime): # BEFORE (Invites Sweeping): { "results": [], "total_available": 0 } # AFTER - Exhausted / Dead End (Stops Sweeping): { "results": [], "status": "no_availability", "retryable": false, "message": "No appointments are available for this provider for the foreseeable future. Searching other dates will not surface anything; openings only come from cancellations.", "suggested_next_step": "offer_waitlist_or_a_different_provider" } # AFTER - Invalid Argument (Prompts User Clarification): { "results": [], "status": "invalid_argument", "reason": "no_such_provider", "retryable": false, "message": "There is no provider named 'Mr. Johnson'. Ask the caller to confirm the name.", "valid_options": ["Dr. Johnson", "Dr. Chen"] }以下範例說明
check_user_account未傳回完全比對項目時的處理方式。預期結果是修改搜尋查詢,或將控制權交還給使用者,而不是重試:def check_user_account(user_name: str, phone_suffix: str):... # Checked user account but not existing # BEFORE: insufficient error information { "found": false, "matches": [] } # AFTER: providing sufficient information to the LiveAPI to avoid further retries because the retries have been exhausted. { "status": "EXHAUSTED", "retryable": false, "search_criteria": { "name": "Alex Rivera", "phone_suffix": "4921" }, "search_scope": "Checked active orders, archived accounts, and guest checkouts across all regions.", "guidance": "Exhaustive search completed with 0 matches. Do NOT retry with parameter substrings or variations. Inform the user that no account was found matching those details, and ask if they have an Order ID or billing email." }系統指令重試政策:在系統指令中加入明確限制,補充資訊豐富的回覆:
"When a tool returns no results, tell the user the result before calling the tool again. If a call fails for a reason fundamental to the arguments (for example, the entity does not exist), do not silently retry with variations; ask the user to clarify or confirm. You may broaden a query once when a result set is simply empty. Do not run repeated searches with different parameters on your own initiative. Hard cap: Never issue more than two consecutive function calls without saying something back to the user."
工作階段記錄交換
在 Gemini 2.5 Flash Live API Native Audio 中,send_client_content 用於在第一輪對話前設定歷來記錄,並在對話期間新增額外記錄。
在 Gemini 3.8 Live 中,如要使用 send_client_content 方法設定歷史記錄,請在設定訊息的 HistoryConfig 部分設定 initial_history_in_client_content=True。收到 setup_complete 後。
接著,您可以重複呼叫 send_client_content 來建立記錄,直到設定 turn_complete=True 的最後一則訊息為止。
對話中的系統指令和工具更新
在 Gemini 2.5 Flash Live API Native Audio 中,您可以在工作階段期間,傳送具有 system 角色的用戶端內容,更新系統指令。
在 Gemini 3.8 Live 中,請改為呼叫 Google Gen AI SDK 中的 send_context_update,或透過 WebSocket 傳送 context_update 訊息。可以取代系統指令和/或工具清單。詳情請參閱「使用 Gemini 3.8 Live 更新系統指令和工具」。
模型行為差異
下表說明 Gemini 2.5 Flash Live API Native Audio 和 Gemini 3.8 Live 在音訊、多模態和輸出方面的模型行為差異:
| 功能 | Gemini 2.5 Flash Live API 原生音訊 | Gemini 3.8 Live |
|---|---|---|
| 情緒感知對話 | 透過 enable_affective_dialog 旗標支援。 |
預設一律啟用。 |
| 主動式音訊 | 透過 proactivity 旗標支援。 |
預設一律啟用。 |
| 圖片或影片影格符記 | 降低預設的每影格預算。 | 傳遞圖片影格時,一律支援 media_resolution。可讓您在成本和準確度之間取得平衡。 |
| 轉錄和內容 | 穩定的基準語音轉錄。 |
您可以新增 custom_vocabulary,為特定領域的字詞提供偏誤,提高準確度。 |
下列 Python 程式碼示範如何設定 media_resolution 和 custom_vocabulary:
# Example: Setting media_resolution for image frames in Gemini 3.8 Live
from google import genai
from google.genai import types
client = genai.Client()
config = types.LiveConnectConfig(
response_modalities=["AUDIO"],
media_resolution=types.MediaResolution.MEDIA_RESOLUTION_LOW, # or MEDIA_RESOLUTION_LOW or MEDIA_RESOLUTION_MEDIUM
)
async with client.aio.live.connect(
model="gemini-3.8-live",
config=config,
) as session:
# Send image frames with the configured resolution budget
...
# Example: Setting custom_vocabulary for domain-specific word biasing in Gemini 3.8 Live
from google import genai
from google.genai import types
client = genai.Client()
config = types.LiveConnectConfig(
response_modalities=["AUDIO"],
input_audio_transcription=types.AudioTranscriptionConfig(
custom_vocabulary=["Gemini", "MagicWord", "Lagrangian"],
),
)
async with client.aio.live.connect(
model="gemini-3.8-live",
config=config,
) as session:
...
第三方架構相容性
以下各節說明第三方框架如何與 Gemini 3.8 Live 搭配使用:
LiveKit
LiveKit 的 Google 外掛程式 RealtimeModel 支援 Gemini 3.8 Live,但 LiveKit 的 Google 外掛程式不支援下列設定:
thinking_levelenable_affective_dialogproactivity
使用 LiveKit 的 Google 外掛程式時,請務必格外謹慎,因為必須仔細調整,才能與 Gemini 3.8 Live 搭配使用。
Pipecat
Pipecat 支援 Gemini 3.8 Live,並有下列異動:
思考設定:Gemini 3.8 Live 不支援思考程度,因此請移除。
Pipecat 會透過
GeminiLiveLLMService連接器,使用GoogleVertexLLMService連線至 Agent Platform 端點。
線路層級詞元用量遙測
伺服器每次回覆都會傳回 usage_metadata 影格。Gemini 2.5 Flash Live API Native Audio 和 Gemini 3.8 Live 均適用。用量中繼資料會進一步分類,例如快取詞元、工具使用詞元、不同模態的詞元等。
已知模型限制和因應措施
如要瞭解使用 Gemini 3.8 Live 開發應用程式時的已知限制和緩解措施,請參閱「已知限制」。
遷移工作檢查清單
從 Gemini 2.5 Flash Live API Native Audio 遷移至 Gemini 3.8 Live 時,可參考下列用戶端遷移檢查清單:
呼叫函式:
提供資訊豐富的工具回應:重構所有工具處理常式,傳回明確的狀態碼、可重試標記和自然語言說明。請勿傳回空白的
None或空白的{}。系統指令政策:新增明確限制,禁止在背景重試工具、要求使用者確認引數失敗,以及限制連續工具呼叫次數。
工具呼叫 ID 比對:請確認
FunctionResponse在每次工具回覆時都會傳遞id=fc.id。函式排程行為變更:使用者說話時,
scheduling=interrupt會降級為scheduling=when_idle,提供更流暢的使用者體驗。
工作階段:限制
send_client_content:使用send_client_content,提供合理的HistoryConfig來設定初始記錄。工作階段:使用
context_update更新情境:將使用system角色的工作階段內系統指令更新,替換為 Google Gen AI SDK 中的send_context_update呼叫,或透過 WebSocket 傳送的context_update訊息。思考:清除提示層級的思考技巧:為避免音訊中斷,請移除所有嘗試強制執行逐步思考結構定義或詞元限制的提示文字。