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

Gemini Interactions API: Change an Agent's Rules and Tools Mid-Conversation

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_input steps (v1beta). Send new system instructions or update function tools (added_tools and removed_tools) mid-conversation without invalidating the prompt cache. Mid-conversation system instructions work with Gemini 4 models (gemini-4-carbon, gemini-4-neon, and gemini-4-hydrogen) in the Interactions API.

Google

Gemini API release notes, December 3, 2026

PartAs of December 2026
StatusPublic preview; Google says the API surface may change before general availability
API versionv1beta only
Where it worksThe Interactions API, on model interactions
The new stepsystem_input, sent just before a user_input step
Tool fields on that stepadded_tools and removed_tools, for custom functions
Modelsgemini-4-carbon, gemini-4-neon, gemini-4-hydrogen

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

Google AI Studio's documentation page for mid-conversation system instructions
Google's guide to system_input in the Gemini API docs

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

A change near the top of the prompt reprocesses everything below itThe fixed order Gemini 4 builds each request in, and what three kinds of change do to the cache
Every request, top to bottom
1Model settingsthinking_level first, then built-in server tools
2ToolsYour function declarations, before the instructions
3system_instructionYour developer prompt
4History, then the new inputEarlier turns oldest first; a system_input step lands here
What each change costs the cache
Edit the tools listTools, instructions and every turn are reprocessed
Edit system_instructionEvery earlier turn is reprocessed
Send a system_input stepEarlier turns stay as they were and can match the cache

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.

One rule change late in a long conversation, two ways (an illustration of Google's rules)
Edit system_instruction or tools

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

Send a system_input step

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

  1. Chain the turn

    Pass the previous turn's ID in previous_interaction_id, and keep sending the same tools, system_instruction and generation_config you sent before.

  2. Put the step before the user's words

    In the input array, place one system_input step directly before the user_input step. Its content holds text.

  3. Add tool changes on the same step

    To take a function away or offer a new one, put removed_tools or added_tools on 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

Python
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.

Google's example: the first turn, then the second turn's steps as the API returns them
You · Turn 1

Hi, I'd like some help with my account.

Turn 1

Stored · its id becomes previous_interaction_id

system_input

The user is in California. Show the CCPA disclosure before sharing any address data.

You · user_input

Can you show me all stored addresses on my account?

Agent · model_output

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_input step is not directly before a user_input step;
  • there is more than one system_input in 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 content holds 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 tools list 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 tools on later turns. Declaring an active added function there returns 400.
  • removed_tools takes objects, [{"type": "function", "name": "issue_refund"}], not bare names. added_tools takes full declarations, in the same schema as tools.
  • If one step has both, removals are applied first. A change holds until another system_input changes it.
  • Only custom function tools can be added or removed. MCP servers and built-in tools such as Google Search or code execution are not supported here yet.
  • tool_choice modes apply only to the original tools list. The model can still call a function you added mid-conversation, so allowed_tools cannot fence it off. Function calling with the Gemini API

Here is what that means across three turns of Google's own refund example, below:

Turntools you sendChange on the system_input stepFunctions the model can call
1get_store_hours, issue_refundnoneget_store_hours, issue_refund
2the same tworemoves issue_refund, adds create_escalation_ticketget_store_hours, create_escalation_ticket
3the same two, issue_refund includednoneget_store_hours, create_escalation_ticket

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

ModelInputCached inputOutput, thinking included
gemini-4-carbon$4.00$0.20$20.00
gemini-4-neon$3.00$0.15$15.00
gemini-4-hydrogen$1.50$0.075$7.50

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_tokens by usage.total_input_tokens on 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.

Python
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.

The deploy function arrives with the next user turn, never inside the tool loopWhere a system_input step is allowed in a coding agent's session
One session
1 · Tool loopTests runfunction_call, then your function_result: no system_input here
2 · Model outputThe run reports greenYour code checks the result itself
3 · Next user turnsystem_input with added_toolsThe deploy function is offered from here
4 · AfterIt stays callableUntil a later step removes it

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.

Python
# 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:

Python
# 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

system_input (Interactions API)send_context_update (Live API)
A new instructionIs added; earlier ones stay in contextOverrides the instruction from session setup
ToolsAdd or remove named functionsReplaces the whole active list; [] clears it
Modelsgemini-4-carbon, gemini-4-neon, gemini-4-hydrogengemini-4-live

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. generateContent does not accept system_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-argon is 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_input stays 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_tools and removed_tools.
  • tool_choice does 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.

Published
Category
Build
Related Articles
LM Studio Bionic: What It Is and How to Start

LM Studio Bionic: What It Is and How to Start

How Bionic works alongside LM Studio, where its models run and how to start a coding or document project on your computer.Dec 4, 2026Build
OpenRouter Free Models: Which to Call and What the Limits Are

OpenRouter Free Models: Which to Call and What the Limits Are

Find a free OpenRouter model for your project, make an API call, check your remaining quota, and see which providers may retain or train on prompts.Dec 4, 2026Build
Vapi AI: What It Is, What It Costs and How to Start

Vapi AI: What It Is, What It Costs and How to Start

Learn how Vapi answers and places calls, connects to a calendar or n8n, and what it takes to set up a first phone assistant.Dec 4, 2026Build
Claude-Mem: What It Remembers and How to Use It

Claude-Mem: What It Remembers and How to Use It

See what claude-mem saves between Claude Code sessions, how to install and disable it, and which records can leave your machine.Dec 4, 2026Build
Amazon Bedrock: What It Is, What It Costs, and How to Start

Amazon Bedrock: What It Is, What It Costs, and How to Start

See which models Amazon Bedrock offers, what AWS bills for, and how to try a first request. Decide when to use Bedrock or the model maker’s own API.Dec 4, 2026Build
Claude Code MCP

Claude Code MCP

Connect a local or hosted MCP server to Claude Code, check sign-in, and choose between a shared .mcp.json and a claude.ai connector.Dec 3, 2026Build
Vercel Sandbox Desktop

Vercel Sandbox Desktop

Start a cloud desktop, watch an agent drive Chrome, or open Blender. See the exact commands, SDK example, and what a viewer link lets a teammate do.Dec 3, 2026Build
Claude Code REVIEW.md

Claude Code REVIEW.md

Where Claude Code reads REVIEW.md, what to put in it, and how to check your rules with a sample change. Includes a full web team example.Dec 3, 2026Build
Newsletter

One letter, every Sunday.Working systems, not hot takes.

Weekly. No spam. Unsubscribe anytime.