Developers can now update scheme instructions or tools in the center of a conversation during keeping the immediate cache intact.
Trey Nguyen
Product Manager, Gemini API
Daniel Kyme
Product Manager, Google Cloud
Listen to article
[[duration]] minutes
This satisfied is generated by Google AI. Generative AI is experimental
Today, mid-conversation scheme education and tool changes are accessible in preview in the Gemini API through the Interactions API. This lets agents modify to new rules and tools mid-session without re-reading the complete conversation or driving up costs.
Long-running agents frequently activity throughout dozens, if not hundreds, of turns. Along the way, rules, permissions and accessible tools change. Until now, you couldn't provision the example a new scheme education or update tools without invalidating the cache.
Developers have commonly relied on two workarounds:
- Putting instructions in a person message: To maintain the cache, you could dispatch new scheme instructions as a person message. These don’t transport the identical importance as your top-level scheme instructions and authorize users to try and imitate them.
- Rewriting scheme education or tools: Rewriting the scheme education or changing tools invalidates the immediate cache. The example reprocesses the complete conversation history, adding disbursal and latency.
The Interactions API now allows you to dispatch a system_input stage at any rotate alongside scheme education or tool changes. It carries the identical authority as your top-level scheme education and takes precedence complete person messages, during before turns remain cached.
How it works
To dispatch an education mid-conversation, continue the former turn's ID in previous_interaction_id and location a system_input stage immediately before user_input in the input array. Keep your top-level system_instruction unchanged throughout turns so the immediate 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 fair spiked on our service. What should I inspect 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 manufacturing deployment freeze is now active. " "Recommend read-only diagnostics and do not authorize additional 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 former as its own stage and stays energetic for the remainder of the meeting alongside the top-level system_instruction. Rules that shield distinct topics remain in consequence together. When a newer system_input conflicts alongside an before instruction, the example favors the most latest instruction.
When you recover an communication alongside client.interactions.get(id=turn2.id), all system_input stage appears in command alongside user_input and model_output, making multi-turn delegate traces straightforward to audit and debug:
{ "steps": [ { "type": "system_input", "content": [ { "type": "text", "text": "A manufacturing deployment freeze is now active. Recommend read-only diagnostics and do not authorize additional 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 manufacturing deployment freeze is active, so we can't release. Here are several checks you can run..." } ] } ] } Because system_input appends at the current rotate boundary, all preceding tokens remain identical from rotate to rotate and reuse the immediate cache. You can dispatch one system_input stage per rotate immediately before user_input, containing content content, tool updates, or both.
How mid-conversation tool updates work
Tool declarations sit at the commencement of the prompt, so changing the top-level tools catalog between turns breaks the immediate cache. With system_input, we propose you depart the identical top-level tools catalog on all rotate and use added_tools and removed_tools to update which functions the example can call as the meeting evolves. Only updating function tools via added_tools and removed_tools is currently supported and not MCP server tools.
In this example, a assistance delegate starts alongside get_store_hours and issue_refund. On the next turn, the app removes issue_refund and adds create_escalation_ticket during keeping the top-level tools catalog identical:
from google import genai client = genai.Client(http_options={"api_version": "v1beta"}) tools = [ { "type": "function", "name": "get_store_hours", "description": "Look up beginning 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 inquiry concerning 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 document is under billing review. Explain " "that refunds are paused and recommendation to escalate." ), } ], "removed_tools": [{"type": "function", "name": "issue_refund"}], "added_tools": [ { "type": "function", "name": "create_escalation_ticket", "description": "Escalate a billing assessment matter to support.", "parameters": { "type": "object", "properties": {"order_id": {"type": "string"}}, "required": ["order_id"], }, } ], }, { "type": "user_input", "content": [{"type": "text", "text": "Refund command 12345."}], }, ], ) print(turn2.output_text) Tool updates remain in consequence until a afterward system_input changes them. When a sole stage includes the two fields, the API processes removed_tools before added_tools, letting you substitute a tool definition in place. Adding a abbreviated content note whenever removing a tool additionally gives the example environment to explain why an act is unavailable.
Keep in intellect that system_input, added_tools, and removed_tools steer example behavior and assist as orchestration controls. Your use should motionless authorize all function call on the backend before executing it and keep untrusted external or end-user satisfied out of system_input.
How you can use it
Session-dependent constraints: Apply rules discovered partway through a conversation, specified as workspace settings, document entitlements, or spending limits.
Long-horizon education reinforcement: Re-emphasize key formatting, tone, or guideline rules profound into multi-turn sessions as environment grows.
Dynamic permissions and manner switches: Enable compose or account-action tools following authentication or scheme approval, and eliminate them whenever returning to read-only review.
Live operational changes: Disable a tool and update direction mid-session whenever a downstream dependency goes offline, afterward reconstruct it formerly assistance recovers.
Large tool catalogs: Start alongside a small set of tools and add additional as the project needs them, without declaring all tool up forefront or breaking the cache.
How pricing and supported models work
Mid-conversation scheme instructions transport no distinct fee. Tokens in system_input steps are billed at the norm input token rates for the example you call. Earlier turns remain eligible for cached-token rates whenever rules or tools change.
Mid-conversation scheme instructions are accessible in community preview throughout all Gemini 4 models in the Interactions API (through v1beta endpoint), in the Gemini API. Support for Gemini Enterprise Agent Platform to arrive soon.
Get started today by study the documentation, comparing Gemini models to discover the correct Gemini 4 example for your workload, and join the conversation on the AI Developer Forum.