Gemini API: Systemanweisungen jetzt mitten im Gespräch änderbar
Google erlaubt in der Gemini API, Systemanweisungen und Tools während einer laufenden Konversation zu aktualisieren, ohne den Prompt-Cache zu verlieren.

Entwickler können jetzt mitten in einer Konversation Systemanweisungen oder Tools aktualisieren, während der Prompt-Cache erhalten bleibt.
Systemanweisungen und Tool-Änderungen während einer Konversation sind ab heute in der Vorschau in der Gemini API über die Interactions API verfügbar. Dadurch können Agenten während einer Sitzung auf neue Regeln und Tools reagieren, ohne die gesamte Konversation erneut einlesen zu müssen oder die Kosten in die Höhe zu treiben.
Langlebige Agenten arbeiten häufig über Dutzende, wenn nicht Hunderte von Zügen hinweg. Dabei ändern sich im Laufe der Zeit Regeln, Berechtigungen und verfügbare Tools. Bisher konnte man dem Modell keine neue Systemanweisung geben oder Tools aktualisieren, ohne den Cache ungültig zu machen.
Entwickler haben üblicherweise auf zwei Behelfslösungen gesetzt:
Die Interactions API erlaubt es nun, in jedem Zug einen system_input-Schritt mit geänderten Systemanweisungen oder Tools zu senden. Dieser hat dieselbe Autorität wie die übergeordnete Systemanweisung am Anfang, hat Vorrang vor Nutzernachrichten, während frühere Zugriffe im Cache erhalten bleiben.
Um eine Anweisung mitten in der Konversation zu senden, übergibt man die ID des vorherigen Zugs in previous_interaction_id und platziert einen system_input-Schritt direkt vor dem user_input im Eingabe-Array. Die übergeordnete system_instruction sollte über alle Züge hinweg unverändert bleiben, damit das Prompt-Präfix im Cache gültig bleibt:
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) Jeder system_input wird als eigener Schritt an den Konversationsverlauf angehängt und bleibt neben der übergeordneten system_instruction für den Rest der Sitzung aktiv.
Regeln, die unterschiedliche Themen betreffen, bleiben gemeinsam in Kraft. Wenn ein neuerer system_input mit einer früheren Anweisung kollidiert, bevorzugt das Modell die jüngste Anweisung.
Wenn man eine Interaktion mit client.interactions.get(id=turn2.id) abruft, erscheint jeder system_input-Schritt in der richtigen Reihenfolge neben user_input und model_output, was mehrstufige Agenten-Traces leicht überprüfbar und debugbar macht:
{ "steps": [ { "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." } ] }, { "type": "model_output", "content": [ { "type": "text", "text": "A production deployment freeze is active, so we can't release. Here are some checks you can run..." } ] } ] } Da system_input an der Grenze des aktuellen Zugs angehängt wird, bleiben alle vorangehenden Tokens von Zug zu Zug identisch und nutzen den Prompt-Cache weiter. Pro Zug kann man genau einen system_input-Schritt direkt vor dem user_input senden, der Textinhalte, Tool-Updates oder beides enthalten kann.
Tool-Deklarationen stehen am Anfang des Prompts, weshalb das Ändern der übergeordneten Tools-Liste zwischen den Zügen den Prompt-Cache bricht. Mit system_input wird empfohlen, in jedem Zug dieselbe übergeordnete Tools-Liste beizubehalten und added_tools sowie removed_tools zu verwenden, um zu aktualisieren, welche Funktionen das Modell im Laufe der Sitzung aufrufen kann. Derzeit werden nur Aktualisierungen von Function-Tools über added_tools und removed_tools unterstützt, nicht jedoch MCP-Server-Tools.
In diesem Beispiel startet ein Support-Agent mit get_store_hours und issue_refund. Im nächsten Zug entfernt die App issue_refund und fügt create_escalation_ticket hinzu, während die übergeordnete Tools-Liste identisch bleibt:
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) Tool-Updates bleiben wirksam, bis ein späterer system_input sie ändert. Wenn ein einzelner Schritt beide Felder enthält, verarbeitet die API removed_tools vor added_tools, sodass man eine Tool-Definition direkt ersetzen kann.
Beim Entfernen eines Tools zusätzlich eine kurze Textnotiz hinzuzufügen, gibt dem Modell außerdem Kontext, um zu erklären, warum eine Aktion nicht verfügbar ist.
Bedenke, dass system_input, added_tools und removed_tools das Modellverhalten steuern und als Orchestrierungsinstrumente dienen. Deine Anwendung sollte dennoch jeden Funktionsaufruf im Backend autorisieren, bevor sie ihn ausführt, und nicht vertrauenswürdige externe oder nutzerstammende Inhalte aus system_input fernhalten.
Sitzungsabhängige Einschränkungen: Regeln anwenden, die im Verlauf einer Konversation entdeckt werden, etwa Workspace-Einstellungen, Kontoberechtigungen oder Ausgabenlimits.
Verstärkung von Anweisungen über lange Zeiträume: Wichtige Formatierungs-, Tonfall- oder Richtlinienregeln tief in mehrstufigen Sitzungen erneut betonen, wenn der Kontext wächst.
Dynamische Berechtigungen und Moduswechsel: Schreib- oder Kontoaktions-Tools nach Authentifizierung oder Planfreigabe aktivieren und beim Rückkehr in die Nur-Lese-Prüfung wieder entfernen.
Live-Betriebsänderungen: Ein Tool deaktivieren und die Anleitung mitten in der Sitzung aktualisieren, wenn eine nachgelagerte Abhängigkeit ausfällt, und es wiederherstellen, sobald der Dienst wieder läuft.
Große Tool-Kataloge: Mit einer kleinen Menge an Tools starten und weitere hinzufügen, sobald die Aufgabe sie erfordert, ohne jedes Tool vorab zu deklarieren oder den Cache zu brechen.
Systemanweisungen während der Konversation kosten keine gesonderte Gebühr. Tokens in system_input-Schritten werden zu den üblichen Eingabe-Token-Preisen des aufgerufenen Modells abgerechnet. Frühere Züge bleiben für Cached-Token-Preise qualifiziert, wenn sich Regeln oder Tools ändern.
Systemanweisungen während der Konversation sind in der öffentlichen Vorschau für alle Gemini-4-Modelle über die Interactions API (über den v1beta-Endpunkt) in der Gemini API verfügbar. Unterstützung für die Gemini Enterprise Agent Platform folgt in Kürze.
Starte noch heute, indem du die Dokumentation liest, Gemini-Modelle vergleichst, um das passende Gemini-4-Modell für deine Arbeitslast zu finden, und an der Diskussion im AI Developer Forum teilnimmst.
Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.
Original (Englisch) anzeigen
Developers can now update system instructions or tools in the middle of a conversation while keeping the prompt cache intact.
Today, mid-conversation system instruction and tool changes are available in preview in the Gemini API through the Interactions API. This lets agents adapt to new rules and tools mid-session without re-reading the entire conversation or driving up costs.
Long-running agents often work across dozens, if not hundreds, of turns. Along the way, rules, permissions and available tools change. Until now, you couldn't give the model a new system instruction or update tools without invalidating the cache.
Developers have commonly relied on two workarounds:
The Interactions API now allows you to send a system_input step at any turn with system instruction or tool changes. It carries the same authority as your top-level system instruction and takes precedence over user messages, while earlier turns stay cached.
To send an instruction mid-conversation, pass the previous turn's ID in previous_interaction_id and place a system_input step directly before user_input in the input array. Keep your top-level system_instruction unchanged across turns so the prompt prefix stays valid in the cache:
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) Each system_input appends to the conversation history as its own step and stays active for the rest of the session alongside the top-level system_instruction.
Rules that cover different topics remain in effect together. When a newer system_input conflicts with an earlier instruction, the model favors the most recent instruction.
When you retrieve an interaction with client.interactions.get(id=turn2.id), each system_input step appears in order alongside user_input and model_output, making multi-turn agent traces straightforward to audit and debug:
{ "steps": [ { "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." } ] }, { "type": "model_output", "content": [ { "type": "text", "text": "A production deployment freeze is active, so we can't release. Here are some checks you can run..." } ] } ] } Because system_input appends at the current turn boundary, all preceding tokens remain identical from turn to turn and reuse the prompt cache. You can send one system_input step per turn directly before user_input, containing text content, tool updates, or both.
Tool declarations sit at the start of the prompt, so changing the top-level tools list between turns breaks the prompt cache. With system_input, we recommend you leave the same top-level tools list on every turn and use added_tools and removed_tools to update which functions the model can call as the session evolves. Only updating function tools via added_tools and removed_tools is currently supported and not MCP server tools.
In this example, a support agent starts with get_store_hours and issue_refund. On the next turn, the app removes issue_refund and adds create_escalation_ticket while keeping the top-level tools list identical:
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) Tool updates stay in effect until a later system_input changes them. When a single step includes both fields, the API processes removed_tools before added_tools, letting you replace a tool definition in place.
Adding a short text note when removing a tool also gives the model context to explain why an action is unavailable.
Keep in mind that system_input, added_tools, and removed_tools steer model behavior and serve as orchestration controls. Your application should still authorize every function call on the backend before executing it and keep untrusted external or end-user content out of system_input.
Session-dependent constraints: Apply rules discovered partway through a conversation, such as workspace settings, account entitlements, or spending limits.
Long-horizon instruction reinforcement: Re-emphasize key formatting, tone, or policy rules deep into multi-turn sessions as context grows.
Dynamic permissions and mode switches: Enable write or account-action tools after authentication or plan approval, and remove them when returning to read-only review.
Live operational changes: Disable a tool and update guidance mid-session when a downstream dependency goes offline, then restore it once service recovers.
Large tool catalogs: Start with a small set of tools and add more as the task needs them, without declaring every tool up front or breaking the cache.
Mid-conversation system instructions carry no separate fee. Tokens in system_input steps are billed at the standard input token rates for the model you call. Earlier turns remain eligible for cached-token rates when rules or tools change.
Mid-conversation system instructions are available in public preview across all Gemini 4 models in the Interactions API (through v1beta endpoint ), in the Gemini API. Support for Gemini Enterprise Agent Platform to come soon.
Get started today by reading the documentation, comparing Gemini models to find the right Gemini 4 model for your workload, and join the discussion on the AI Developer Forum.