AI 热点

Google 为 Gemini API 增加会话中途指令更新并保留缓存

Unite.AI更新于 12月4日 03:02

Google Adds Mid-Conversation Instructions to Gemini API, Preserving Cache

AI 导读

Google 为 Gemini API 推出公开预览,开发者可通过 Interactions API 在会话中途更新系统指令和自定义函数工具,同时保留此前提示词 token 的缓存。更新以追加式 system_input 写入历史,冲突时优先采用较新的指令,但旧指令无法删除。该功能仅支持 v1beta Interactions API 的 gemini-4-carbon、gemini-4-neon 和 gemini-4-hydrogen,不支持 MCP 服务器、内置工具、generateContent 或智能体交互,实际函数权限仍须由后端鉴权。

推荐理由

AI 评分 65

新机制兼顾会话中途调整智能体规则与缓存复用,也明确了追加式指令、工具支持和后端鉴权的边界。

主题

标签

正文

Google introduced a public preview on December 3, 2026 that lets Gemini API developers update system instructions and function tools mid-conversation without invalidating cached prompt tokens. The capability runs through the Interactions API, adding system-level controls for agents whose rules and permissions change during a session.

Long-running agents can span dozens or hundreds of turns, during which spending limits, account permissions and available functions may change. Developers previously had two workarounds: inserting instructions into user messages preserved the cache but lacked top-level system authority and could be imitated by users, while rewriting the system instruction or tools list invalidated the cache. The latter forced the model to reprocess the full conversation history, adding cost and latency. The new system_input step carries the same authority as the top-level system instruction and takes precedence over user messages while earlier turns remain cached.

To make an update, the application chains the new turn with previous_interaction_id, allowing the server to retrieve stored conversation history rather than requiring the application to resend it. The request format places one system_input step immediately before user_input and keeps the top-level system_instruction unchanged. Because the new step is appended at the current turn boundary, all preceding tokens remain identical, preserving the cached prompt prefix.

Each update becomes a separate history step rather than replacing earlier instructions. The original system instruction and all previous system_input steps remain in context; nonconflicting rules continue together, while the model favors the newest instruction when rules conflict. When reversing a rule, Google recommends stating what changed and telling the model to ignore the earlier instruction, since previous steps cannot be removed. Retrieved interactions list these steps chronologically alongside user input, model output and tool changes, creating an inspectable record for debugging.

Google’s infrastructure example shows the intended sequence: an assistant troubleshooting a latency spike receives a new production deployment freeze, with instructions to recommend read-only diagnostics and prevent further rollouts. A user then asks for the command to deploy a release. The example’s model reply declines the release and offers diagnostic checks, applying the new rule without resetting the earlier session.

Applications keep sending the original top-level tools list, including functions that have been disabled, and use removed_tools and added_tools on system_input to change the active set. Changes persist until a later update. When both fields appear together, removals are processed before additions, allowing a function definition to be replaced. Only custom function tools are supported; MCP servers and built-in tools such as Google Search and code execution are not.

These fields steer model behavior; they do not enforce application permissions. Google advises authorizing every function call on the backend before execution and keeping untrusted external or end-user content out of system_input. That distinction is central to uses such as enabling write tools after authentication, disabling functions during a downstream outage or expanding a large tool catalog only when a task requires it.

Preview Availability and Token Pricing

The preview requires the v1beta Interactions API, and its API surface may change before general availability. The documentation lists support for gemini-4-carbon, gemini-4-neon and gemini-4-hydrogen; other models return HTTP 400. It is limited to model interactions, leaving generateContent requests and agent interactions unsupported.

Malformed requests can also fail with HTTP 400, including a standalone system_input, one sent during a function-result loop, or later requests that drop a removed function from the original top-level tools list. Added tools must similarly remain outside that top-level list rather than being declared again on subsequent turns.

There is no separate fee for mid-conversation instructions. Tokens in system_input are billed at the called model’s standard input-token rates, while earlier turns remain eligible for cached-token rates. Google says Gemini Enterprise Agent Platform support is coming soon.

The preview gives long-running agents an inspectable way to change policy and capabilities as conditions shift while retaining conversational context. Its main constraint is the append-only design: cached history survives an update, but old instructions remain present, and backend authorization—not the revised tool list—ultimately determines which actions can execute.

来源

Unite.AI