Gemini Interactions API: Change an Agent's Rules and Tools Mid-Conversation
How system_input steps on the Gemini Interactions API change an agent's rules and tools mid-conversation, why the cache survives, and where it stops.
Published

On Gemini, an agent's rules and tools used to be fixed at the top of its prompt, so changing either one partway through a conversation made the model reprocess everything said so far. Since December 3, 2026, the Gemini Interactions API accepts a system_input step: a new rule, or a function added or taken away, sent in the middle of the conversation while the turns before it stay cached. It is a public preview, for three Gemini 4 models.
The Interactions API, for a generateContent developer
If you know only generateContent, the difference is where the conversation lives. generateContent is stateless: you send the whole history in contents on every call and read the answer from candidates. On the Interactions API, each call creates an Interaction, a stored record of one turn written as a timeline of steps: user_input, the model's thoughts, function_call, function_result, model_output. To continue, you pass the last turn's ID as previous_interaction_id and the server brings back the history. Interactions API overview · Google's migration guide
As of June 2026 the Interactions API is generally available and Google's recommended interface for new projects; generateContent is now called legacy and remains fully supported. If you are still deciding where Gemini fits, what Google AI Studio is for covers the ground first.
One detail explains the rest. previous_interaction_id carries the conversation only. tools, system_instruction and generation_config belong to the single request, so you send them again on every turn. Until December 3, sending a different instruction or a different tool list on a later turn was the only way to change them.
Interactions are stored by default: for 55 days on the paid tier and 1 day on the free tier. store=false opts out, and also rules out previous_interaction_id.
What shipped on December 3
Mid-conversation system instructions (Public Preview): The Interactions API now supports
system_inputsteps (v1beta). Send new system instructions or update function tools (added_toolsandremoved_tools) mid-conversation without invalidating the prompt cache. Mid-conversation system instructions work with Gemini 4 models (gemini-4-carbon,gemini-4-neon, andgemini-4-hydrogen) in the Interactions API.
Google's guide names three jobs for it: reinforcing a rule late in a long session, adding a constraint you learn partway through (a budget cap, a jurisdiction rule), and switching functions on or off, for example after a user finishes signing in with OAuth or when a feature is paused. Google's mid-conversation instructions guide · Gemini API release notes · Gemini 4 Neon, explained
Why changing the rules used to cost the whole conversation
Gemini 4 caches implicitly: when the start of a request matches the start of a recent one, the matching tokens are billed at the cached rate. Google's caching guide says the match runs from the first token onward, and the first token that differs breaks the cache for everything after it. So what matters is where your change lands in the prompt. Google's caching guide
As of Dec 4, 2026 · Source: Google AI Studio, Context caching and Mid-conversation system instructions
Tool declarations sit above the system instruction, which is why a new tool list is the most expensive change: Google's table says adding, removing or reordering non-deferred tools invalidates the system instruction and the entire history. Editing the system instruction leaves the tools cached and invalidates every turn below it. A system_input step is part of the history, so it is appended after the turns you already sent and changes nothing above it.
Next request carries a new instruction or tool list
The prompt differs near its top
Every earlier turn is processed again at the input rate
Next request carries the same tools and instruction
The prompt matches up to the new step
Earlier turns can be read from the cache; the step is new input
The same logic is behind a mistake Google lists among the common cache breakers: leaving tools, system_instruction or generation_config out of a previous_interaction_id follow-up. Because they are not stored with the conversation, leaving them out changes the prompt just as editing them would. Changing thinking_level mid-session is worse still: it comes first, so it invalidates the whole prefix.
How a system_input step works
Chain the turn
Pass the previous turn's ID in
previous_interaction_id, and keep sending the sametools,system_instructionandgeneration_configyou sent before.Put the step before the user's words
In the
inputarray, place onesystem_inputstep directly before theuser_inputstep. Itscontentholds text.Add tool changes on the same step
To take a function away or offer a new one, put
removed_toolsoradded_toolson that step. A text note is optional only when the step changes tools.
This is Google's own Python example. The API version must be set to v1beta, because the latest SDKs call v1 unless told otherwise: Google changed that default with the November 2026 major releases. API versions explained
from google import genai
client = genai.Client(http_options={"api_version": "v1beta"})
first = client.interactions.create(
model="gemini-4-hydrogen",
input="Hi, I'd like some help with my account.",
)
interaction = client.interactions.create(
model="gemini-4-hydrogen",
previous_interaction_id=first.id,
input=[
{
"type": "system_input",
"content": [
{
"type": "text",
"text": "The user is in California. Show the CCPA disclosure before sharing any address data.",
}
],
},
{
"type": "user_input",
"content": [
{"type": "text", "text": "Can you show me all stored addresses on my account?"}
],
},
],
)
print(interaction.output_text)When you fetch that interaction back with client.interactions.get, the new rule appears as its own step, in order. This is the response Google's guide prints, as a conversation.
Hi, I'd like some help with my account.
Stored · its id becomes previous_interaction_id
The user is in California. Show the CCPA disclosure before sharing any address data.
Can you show me all stored addresses on my account?
Before I share your stored addresses, please review our CCPA disclosure...
How new rules combine with old ones
A system_input step adds; it never replaces. Your top-level system_instruction and every earlier system_input stay in the model's context for the rest of the conversation. Rules that do not conflict all keep applying. When a new rule conflicts with an older one, the model favors the most recent, and because the older one is still there, Google advises saying what changed. Its example: "Refunds are available again. Ignore the earlier instruction that paused refunds."
The rules the API enforces
The API answers HTTP 400 when a request breaks any of these:
- the
system_inputstep is not directly before auser_inputstep; - there is more than one
system_inputin the turn; - it is sent on its own, or during a function-calling loop, when you are returning a
function_result(wait for the next user turn); - its
contentholds anything other than text; - it has no text and changes no tools.
Add or remove a function without touching the tools list
The tools part follows one idea: the top-level tools list never changes, and the step records the difference. Google's rules, as of December 2026:
- Keep passing the original
toolslist on every turn, including functions you removed. The API checks the stored history against it, so dropping a removed function returns 400 on later turns. - Leave functions you added out of
toolson later turns. Declaring an active added function there returns 400. removed_toolstakes objects,[{"type": "function", "name": "issue_refund"}], not bare names.added_toolstakes full declarations, in the same schema astools.- If one step has both, removals are applied first. A change holds until another
system_inputchanges it. - Only custom
functiontools can be added or removed. MCP servers and built-in tools such as Google Search or code execution are not supported here yet. tool_choicemodes apply only to the originaltoolslist. The model can still call a function you added mid-conversation, soallowed_toolscannot fence it off. Function calling with the Gemini API
Here is what that means across three turns of Google's own refund example, below:
If your agent carries dozens of functions, Gemini API tool retrieval is the companion feature: deferred tools load their schemas into the steps on demand, which also leaves the top of the prompt alone.
What the cache is worth, and what it does not promise
On Gemini 4, implicit caching is the only kind: the Interactions API and the Gemini 4 models do not offer explicit caches. It needs no setup and has no storage fee, and Google says cached input tokens cost 95% less on Gemini 4 models. These are Google's paid-tier Standard rates, per million tokens, as of December 2026. Gemini API pricing
Carbon and Neon are not on the free tier; Hydrogen is free of charge there. Read the rest of the caching guide before you plan on the cached rate:
- Nothing is guaranteed. Google calls implicit caching opportunistic, with no guaranteed retention window or cost saving. Entries live in memory for up to 24 hours, best effort. Since December 4, Gemini 4 can also keep evicted prefixes on encrypted SSD for up to 12 hours at the same discount and no fee, except for projects with an approved zero data retention exception.
- There is a floor. Caching starts at 4,096 input tokens on Gemini 4.
- The tail is always recomputed. Every request reprocesses a trailing window of 2,050 tokens at the standard rate. In Google's own table, a 10,000-token conversation followed by a 400-token exchange gets 7,950 tokens from the cache and 2,450 at the standard rate; an agent turn that adds 3,200 tokens of thoughts and tool results keeps all 10,000 cached.
- Measure it. Divide
usage.total_cached_tokensbyusage.total_input_tokenson every turn, and a prompt edit that breaks the cache shows up in your logs.
How much a long conversation holds before any of this matters is covered in what a context window is and what fits.
Three patterns, built from these parts
A support agent whose policy changes when the case escalates
Google's own tools example is this pattern. The account goes under billing review mid-conversation, so the refund function is withdrawn, an escalation function is offered, and a line of text tells the model why, so it can explain to the customer. Google recommends that note whenever you remove a tool.
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"],
},
},
]
first = client.interactions.create(
model="gemini-4-hydrogen",
input="Hi, I have a question about my order.",
tools=tools,
)
interaction = client.interactions.create(
model="gemini-4-hydrogen",
previous_interaction_id=first.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": "Please refund order 12345."}],
},
],
)
print(interaction.output_text)When the review clears, send another system_input that says so in plain words, in the form of Google's "Refunds are available again" example. The guide does not show a removed function from the original list being offered again, so test that step before you build on it.
A coding agent that gets a deploy function only after the tests pass
The rule that shapes this one is timing. A system_input step cannot ride along with a function_result, so the deploy function cannot appear in the middle of the agent's test loop. It arrives with the next user turn.
As of Dec 4, 2026 · Source: Google AI Studio, Mid-conversation system instructions
The code below is our adaptation, not Google's: the function name, its description and the wording of the rule are ours, written to the field names in Google's guide, and we have not run it. tools is the list you sent on the first turn.
# Our adaptation of the guide's pattern. Names and wording are ours; not run.
deploy_to_staging = {
"type": "function",
"name": "deploy_to_staging",
"description": "Deploy one commit to the staging environment.",
"parameters": {
"type": "object",
"properties": {"commit": {"type": "string"}},
"required": ["commit"],
},
}
interaction = client.interactions.create(
model="gemini-4-neon",
previous_interaction_id=last.id,
tools=tools, # unchanged since turn 1; deploy_to_staging is never added here
input=[
{
"type": "system_input",
"content": [
{
"type": "text",
"text": "The full test suite passed on the current commit. You may now deploy that commit to staging. Production deploys remain unavailable.",
}
],
"added_tools": [deploy_to_staging],
},
{
"type": "user_input",
"content": [{"type": "text", "text": "Ship it to staging."}],
},
],
)Two cautions from the docs apply. tool_choice cannot restrict a function added this way, so the check that a deploy is allowed belongs in your own handler, where Google's function-calling guide says to validate every call before running it. And when you want the function gone, say after the deploy, a later step with removed_tools takes it away.
A voice agent handed to another role
Which API carries the call decides how this works. If your voice agent runs turn by turn through the Interactions API, with your own speech step on either side, a hand-off from receptionist to billing specialist is one more system_input. Write what changed, since the receptionist's rules stay in context:
# Our adaptation: the role text and lookup_invoice are ours; not run.
{
"type": "system_input",
"content": [
{
"type": "text",
"text": "From this turn you are the billing specialist. The earlier instruction to transfer billing questions no longer applies.",
}
],
"added_tools": [lookup_invoice],
}If the call runs on the Live API's open connection with gemini-4-live, system_input is not there. Gemini 4 Live has its own mid-session update, send_context_update, and it behaves differently. Live API session management · Building a voice agent with the Gemini Live API
On the Live API, a supplied instruction replaces the first one, so carry forward anything the new role still needs. Google describes both fields as part of the model's preamble there and advises updating them only when needed. To add background context without touching the preamble, it points to send_client_content with turn_complete=False.
The limits, and what "preview" means here
Preview means Google may still change the API's shape: the guide says the surface may change before general availability, and Google describes v1beta as the version for features still being refined on feedback. Build it behind a switch you can turn off. As of December 2026:
- Interactions API only.
generateContentdoes not acceptsystem_input. - Model interactions only. Agent interactions, such as the Deep Research agent, are not supported.
- Three models. Carbon, Neon and Hydrogen; any other model returns 400.
gemini-4-argonis not on the list; it is deprecated, and from December 15 its requests route to Carbon. Gemini 4 Carbon, explained · Gemini 4 Hydrogen, explained - Permanent steps. Each
system_inputstays in context for the rest of the conversation and cannot be removed, so it also counts toward the context you carry. - Custom functions only for
added_toolsandremoved_tools. tool_choicedoes not reach added functions.- A stored chain. The guide's examples continue with
previous_interaction_id, which relies on stored interactions: 55 days on the paid tier, 1 day on the free tier.
Google's own advice for keeping it clean: put baseline behavior in system_instruction, keep system_input for what changes mid-session, and when you reverse a rule, tell the model to ignore the earlier one.
The same need on other makers' APIs
Anthropic's Messages API appends a role: "system" message to messages and changes tools with tool_addition and tool_removal blocks in beta, leaving tools as first sent (Anthropic's docs). OpenAI's Responses API appends a new developer message instead of editing the first one and adds tools with an additional_tools item; from GPT-6.2, top-level instructions are turn-scoped and billed at the uncached input rate (OpenAI's docs).
Questions developers ask
Does system_input replace my system_instruction?
No. It is added to the conversation as its own step. Your system_instruction and every earlier system_input stay in context, and on a conflict the model favors the most recent instruction. Keep sending the same system_instruction on every turn.
Can I send system_input while the model is calling my functions?
No. Sending it on its own, or with a function_result during a function-calling loop, returns HTTP 400. Send it with the next user_input turn.
Does it work with generateContent or the Live API?
Not with generateContent. The Live API has a separate mechanism for gemini-4-live, send_context_update, which overrides the instruction and replaces the tool list instead of adding to them.
Is the cached rate guaranteed once I use system_input?
No. It keeps the earlier turns eligible for the cache, but Google calls implicit caching opportunistic, with no guaranteed retention or saving, and every request recomputes its last 2,050 tokens at the standard rate.
AI agent frameworks compared
LangGraph, the OpenAI Agents SDK, the Claude Agent SDK, Google ADK and more: what to build the rest of your agent on.
- Published
- Category
- Build








