AI最前沿 88Z.ai 12 月 6 日消息,Google 于 2026 年 12 月 3 日在 Gemini API 的 Interactions API 中以公开预览形式推出对话中系统指令与工具更新。开发者可在保持顶层 system_instruction 不变的前提下,用 system_input 追加新规则或增删函数工具,从而继续复用提示缓存,而不必整段重算历史对话。
消息要点
- 在 previous_interaction_id 的下一轮中,把唯一的 system_input 放在 user_input 之前,并保持顶层 system_instruction 不变以保住缓存
- system_input 与顶层系统指令同等权威、优先于用户消息;若与更早的 system_input 冲突,模型采纳最新一条
- 工具更新请保持顶层 tools 列表不变,改用 added_tools 与 removed_tools;目前只支持函数工具,不支持 MCP 服务器工具
- 无单独加价,system_input 令牌按该模型标准输入费率计费;公开预览覆盖 Interactions API v1beta 中的所有 Gemini 4 模型
此前的两种变通及其代价
据 Google 官方博客(2026 年 12 月 3 日,产品经理 Trey Nguyen 与 Daniel Kyme)以及 @GoogleAIStudio 的说明,长周期代理常会在数十甚至上百轮对话中途改规则、改权限或改可用工具。过去常见两条路:把新指令放进用户消息以保住缓存,但这些内容达不到顶层系统指令的权重,也容易被用户仿写;或者直接改写顶层 system_instruction 或工具列表,这会让提示缓存失效,模型必须重新处理整段历史,成本和延迟都会上升。Interactions API 现在允许在任意一轮发送 system_input,用于系统指令或工具变更。
system_input 怎么用:官方步骤与示例
官方步骤是:在请求中传入上一轮的 previous_interaction_id;把 system_input 放在输入数组里、紧挨在 user_input 之前;各轮保持顶层 system_instruction 不变,以便提示前缀仍能命中缓存。每轮只能发送一个 system_input,其中可以包含文本、工具更新,或两者同时出现。该步骤会写入会话历史并在此后与顶层指令一起生效;不同主题的规则可以并存,若与更早的 system_input 冲突,模型采纳最新一条。它与顶层系统指令具有同等权威,并优先于用户消息。用 client.interactions.get(id=turn2.id) 可以按顺序看到 system_input、user_input 和 model_output。客户端需指定 api_version 为 v1beta。官方示例使用模型 gemini-4-neon:
from google import genai client = genai.Client(http_options={"api_version": "v1beta"}) system_instruction = "You are an infrastructure troubleshooting assistant." turn1 = client.interactions.create(model="gemini-4-neon", system_instruction=system_instruction, input="Latency just spiked on our service. What should I check first?") turn2 = client.interactions.create(model="gemini-4-neon", previous_interaction_id=turn1.id, system_instruction=system_instruction, input=[{"type": "system_input", "content": [{"type": "text", "text": "A production deployment freeze is now active. Recommend read-only diagnostics and do not allow further rollouts."}]}, {"type": "user_input", "content": [{"type": "text", "text": "Give me the command to deploy a new release."}]}]) print(turn2.output_text)
用 added_tools 与 removed_tools 改工具而不拆缓存
工具声明位于提示开头,直接改顶层 tools 列表会破坏缓存。官方建议每轮保持相同的顶层工具列表,只通过 added_tools 和 removed_tools 调整模型可调用的函数。目前仅支持函数工具,不支持 MCP 服务器工具。同一 system_input 里若同时出现这两个字段,API 会先处理 removed_tools,再处理 added_tools,因此可以原地替换某个工具定义。移除工具时附一句说明,有助于模型解释为何某项操作暂不可用。官方示例如下:客服代理先拥有 get_store_hours 和 issue_refund;下一轮在账户处于账单审核时移除 issue_refund、加入 create_escalation_ticket,但顶层 tools 列表保持不变。
from google import genai client = genai.Client(http_options={"api_version": "v1beta"}) tools = [{"type": "function", "name": "get_store_hours", "description": "Look up opening hours for a store.", "parameters": {"type": "object", "properties": {"store_id": {"type": "string"}}, "required": ["store_id"]}}, {"type": "function", "name": "issue_refund", "description": "Refund an order.", "parameters": {"type": "object", "properties": {"order_id": {"type": "string"}}, "required": ["order_id"]}}] turn1 = client.interactions.create(model="gemini-4-neon", input="Hi, I have a question about my order.", tools=tools) turn2 = client.interactions.create(model="gemini-4-neon", previous_interaction_id=turn1.id, tools=tools, input=[{"type": "system_input", "content": [{"type": "text", "text": "This account is under billing review. Explain that refunds are paused and offer to escalate."}], "removed_tools": [{"type": "function", "name": "issue_refund"}], "added_tools": [{"type": "function", "name": "create_escalation_ticket", "description": "Escalate a billing review issue to support.", "parameters": {"type": "object", "properties": {"order_id": {"type": "string"}}, "required": ["order_id"]}}]}, {"type": "user_input", "content": [{"type": "text", "text": "Refund order 12345."}]}]) print(turn2.output_text)
安全、计费与可用范围
官方强调,system_input、added_tools 和 removed_tools 只是编排控制:应用仍应在后端执行前授权每一个函数调用,并且不要把不受信任的外部或最终用户内容放入 system_input。该能力没有单独收费,system_input 中的令牌按所调用模型的标准输入费率计费;规则或工具变更后,更早的轮次仍可适用缓存令牌费率。功能目前在 Gemini API 的 Interactions API v1beta 端点上,对所有 Gemini 4 模型公开预览;Gemini Enterprise Agent Platform 的支持“即将提供”。官方列举的用途包括:会话中途才确定的约束(工作区设置、账户权益、支出限额),长对话中再次强调格式或政策,认证或审批后再打开写入类工具、回到只读时再撤掉,下游依赖故障时禁用工具并更新说明,以及先用小工具集再按任务追加而不破坏缓存。完整说明见 https://blog.google/innovation-and-ai/technology/developers-tools/gemini-api-mid-conversation-updates/ 。
资料来源与整理说明
本文由 AI最前沿通过 AI 辅助整理公开资料。产品能力与开放范围按发布方说明转述,未将其视为本站实测或独家采访结论。
- Google AI Studio原始资料发布于
- Google Blog原始资料发布于
以上日期为原始资料发布日期;标题下方日期为本文在 AI最前沿的发布时间。