本文档介绍了从 Gemini 2.5 Flash Live API 原生音频迁移到 Gemini 3.8 Live 时需要进行的更改。
函数调用变更
Gemini 2.5 Flash Live API 原生音频服务器允许异步工具调用。相比之下,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 原生音频和 Gemini 3.8 Live 在音频、多模态和输出方面的模型行为差异:
| 功能 | Gemini 2.5 Flash Live API 原生音频 | Gemini 3.8 Live |
|---|---|---|
| 共情对话 | 通过 enable_affective_dialog 标志支持。 |
默认情况下始终处于启用状态。 |
| 主动音频 | 通过 proactivity 标志支持。 |
默认情况下始终处于启用状态。 |
| 图片或视频帧 token | 降低默认的每帧预算。 | 传递图片帧时,系统始终支持 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 使用
GoogleVertexLLMServiceoverGeminiLiveLLMService连接器连接 Agent Platform 端点。
网络级 token 使用情况遥测
服务器的每个回合都会返回一个 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消息。思考:清除提示级思考技巧:为防止音频中断,请移除所有试图强制执行分步思考模式或 token 限制的提示文本。