改系统提示不再打爆缓存
别再为改一条规则重跑整段历史。system_input 改规则,缓存还在。
长会话里改一条系统规则,以前要么塞进用户消息,要么改顶层 system_instruction,整段前缀失效、缓存作废。2026-12-03 起,Interactions API 预览可用 system_input 在中途改规则,历史仍走缓存。要把「冻结后只读」摊开,可先在 oakmeet 开一间房间。
可检索的结果是 改系统提示不再打爆缓存。预览面向全部 Gemini 4 模型,v1beta。system_input 的 token 按该模型标准输入价计费。依据 Google Keyword 2026-12-03 与 Mid-conversation instructions。
别改顶层,改这一轮的 system_input
用户消息当系统指令
为了保缓存,把新规则写成 user 文本。权重不够,用户还能仿冒。
重写顶层指令或 tools
前缀变了,缓存作废。模型重处理整段对话,费用和延迟一起上来。
| 做法 | 缓存 | 权威 |
|---|---|---|
| 把规则塞进 user 消息 | 能保住 | 不够,可被仿冒 |
| 改顶层 system_instruction / tools | 作废 | 够,但整段重跑 |
| system_input + 顶层保持原样 | 前缀仍可缓存 | 与顶层同权,压过用户 |
一回合只插一条,插在用户话之前
- 01顶层 system_instruction 每轮一字不改
官方示例:
You are an infrastructure troubleshooting assistant.第二轮仍传同一句。变的是后面的system_input。 - 02带上 previous_interaction_id
client.interactions.create(..., previous_interaction_id=turn1.id)。历史在服务端接上,不必把整段再 POST 一遍。 - 03system_input 紧挨在 user_input 前
input 数组里先
type: system_input,再user_input。每轮一条。内容可以是文本,也可以加added_tools/removed_tools。 - 04工具只加减函数,不动顶层列表
示例:顶层仍是
get_store_hours与issue_refund。第二轮removed_tools去掉退款,added_tools加上create_escalation_ticket。同一条里先 remove 再 add。MCP 工具暂不支持。
from google import genai
client = genai.Client(http_options={"api_version": "v1beta"})
system_instruction = "You are an infrastructure troubleshooting assistant."
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."}]},
{"type": "user_input", "content": [{"type": "text", "text": "Give me the command to deploy a new release."}]},
],
)新规则写在 system_input 里。顶层那一句别动。动了,缓存就没了。
- system_input 会覆盖顶层吗
- 它追加为历史里的一步,与顶层并存。不同主题的规则一起生效;冲突时模型偏向最新一条。
- MCP 工具能 added_tools 吗
- 目前只支持函数工具,不支持 MCP server tools。
- 不可信内容
- system_input 是编排控件。后端仍要授权每次函数调用;不要把外部或终端用户原文写进 system_input。
把「冻结」和「还能调哪些函数」摊成两列
两人争的是发布冻结后还能不能 deploy。把只读诊断和禁区画在同一页。oakmeet 是浏览器白板:空间码进门,不用注册;不是 Gemini API。
仓库里的 CLI 席位见 Gemini CLI 免费档跑不完第一题。Studio 入口见 Google AI Studio。短会对齐:开房间。
这是正式 GA 吗?
Google 写的是 public preview,Interactions API,v1beta,覆盖全部 Gemini 4 模型。Gemini Enterprise Agent Platform 支持「即将到来」。
会不会另收一笔中途更新费?
官方:没有单独费用。system_input 里的 token 按你调用的模型的标准输入价计费。更早的轮次在改规则或工具后仍可走缓存价。
每轮能塞几条 system_input?
每轮一条,且直接放在 user_input 前面。
oakmeet 会替我改 Gemini 系统指令吗?
不会。开始链接只用来摊开冻结和禁区。API 调用仍在你的客户端。