谷歌更新 Gemini Interactions API:会话中动态更新指令,兼顾提示缓存有效性Google Updates Gemini Interactions API: Dynamic Instructions Within a Session While Preserving Prompt Cache


AI free token/AI免费积分

IT之家 12 月 4 日消息,谷歌宣布已在 Gemini Interactions API 中推出会话中途修改平台指令和工具列表的能力,当下暂处于预览阶段。

开发者可以在智能体运行过程中的任意一轮添加新的平台指令,或动态调整模型可调用的工具,无需重新处理此前的完整对话历史,也不会因而产生额外的历史上下文处理成本。

谷歌更新 Gemini Interactions API:会话中动态更新指令,兼顾提示缓存有效性

在此次更新之前,长时间运行的 AI 智能体如果需要调整行为规则,通常有两种方式:一是将新指令作为使用者消息发送,二是直接重写平台指令或替换工具列表。首要种方式存在指令优先级不足的难题,使用者也可能借助模仿相关指令影响智能体行为;第二种方式则可能导致提示缓存失效,模型需要重新处理整段对话历史,从而增加调用成本和响应延迟。

此次更新引入了新的 system_input 字段。开发者可以在后续请求中传入上一轮交互的 ID,即 previous_interaction_id,并在输入数组中将 system_input 放在 user_input 之前,以便在不中断现有会话的情况下追加平台指令。

谷歌建议开发者保持顶层 system_instruction 不变,将需要动态调整的规则放入独立的 system_input 步骤中。这样可以保留提示词前缀的缓存有效性,避免因修改顶层平台指令而重新处理历史内容。

新加入的 system_input 会作为独立步骤追加到对话历史,并与原有顶层平台指令共同生效。不同轮次添加的规则可以同时发挥作用;如果新旧指令之间存在冲突,模型会优先遵循新近加入的指令。

另外,开发者可以借助 client.interactions.get 获取完整交互记录。返回结果会按照执行顺序排列各个步骤,便于检查平台指令的变化以及多轮智能体的调用过程。

工具列表的动态调整则使用另一套机制。由于工具声明位于提示词前部,如果每轮请求都直接修改顶层 tools 列表,同样可能破坏提示缓存。因而,谷歌建议保持顶层工具列表不变,改用新增的 added_tools 和 removed_tools 字段,分别添加或移除模型可以调用的函数工具。

当下,这项能力仅兼容函数工具的动态更新,尚不兼容 MCP 服务器工具。如果同一个步骤中同时给出 removed_tools 和 added_tools,API 会先处理移除操作,再处理添加操作,从而允许开发者在同一轮请求中替换现有工具定义。

相关阅读:

本文来源:https://www.ithome.com/1/037/286.htm
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

According to IT Home on December 4, Google has announced the launch of a feature in the Gemini Interactions API that allows for the modification of system instructions and tool lists during an ongoing conversation.

This feature is currently in the preview stage.

Developers can add new system instructions at any point during the agent's operation, or dynamically adjust the tools available to the model, without having to reprocess the entire conversation history from before.

This also avoids additional costs for processing historical context.

Prior to this update, there were typically two ways for long-running AI agents to adjust their behavior rules: either by sending new instructions as user messages, or by directly rewriting system instructions or replacing the list of tools.

The first method has the issue of insufficient instruction priority, and users may also influence the agent's behavior by mimicking the relevant instructions.

The second method may cause the prompt cache to become invalid, requiring the model to reprocess the entire conversation history, thereby increasing invocation costs and response latency.

This update introduces a new system_input field.

Developers can pass the ID of the previous interaction, i.

e.

, previous_interaction_id, in subsequent requests and place system_input before user_input in the input array to append system instructions without interrupting the current session.

Google recommends that developers keep the top-level system_instruction unchanged and place rules that need to be dynamically adjusted in a separate system_input step.

This preserves the cache validity of the prompt prefix and avoids reprocessing historical content due to modifications to the top-level system instructions.

The newly added system_input will be appended to the conversation history as a separate step and will take effect together with the original top-level system instruction.

Rules added in different rounds can take effect simultaneously;

if there is a conflict between new and old instructions, the model will prioritize the most recently added instructions.

In addition, developers can retrieve the complete interaction log via client.

interactions.

get.

The returned results will arrange the various steps in the order of execution, making it easy to check changes in system instructions and the invocation process of multi-turn agents.

The dynamic adjustment of the tool list uses a different mechanism.

Since the tool declaration is located at the beginning of the prompt, directly modifying the top-level tools list for each request could also invalidate the prompt cache.

Therefore, Google recommends keeping the top-level tools list unchanged and instead using the newly added added_tools and removed_tools fields to add or remove function tools that the model can call, respectively.

Currently, this capability only supports dynamic updates of function tools and does not yet support MCP server tools.

If both removed_tools and added_tools are provided in the same step, the API will process the removal operation first and then the addition operation, allowing developers to replace existing tool definitions in the same request round.

Related reading: "Google Updates Gemini Privacy Controls, Allowing Chat History to Be Retained Without Being Used for AI Training" "Google Launches Gemini Decisions API for Fast Multimodal Decision-Making, Based on the Gemini Decision 1 Model" "Google Gemini Launches Memory Summaries, Allowing Users to View/Edit/Delete Personal Information Remembered by the AI"

Google Updates Gemini Interactions API: Dynamic Instructions Within a Session While Preserving Prompt Cache

本文来源:https://www.ithome.com/1/037/286.htm
若有版权问题,请来信告知:13951431913#139.com 或在右方提交评论。

暂无评论,快来发表第一条评论吧!No comments yet. Be the first!

📮 需求咨询📮 Inquiry