Gemini Can Now Change an AI Agent's Rules Mid-Conversation. Change Them Twice.
Google made mid-session permission changes cheap. Here is how to use them without trusting the model to enforce them.
Long-running AI agents have an awkward secret. The rules they start with are almost never the rules they should end with.
A support agent opens a chat able to issue refunds. Twenty turns later the account turns out to be under billing review, and refunds should stop. A coding agent starts in read-only review mode, the user approves a plan, and now it needs write access. An operations assistant is helping debug latency when someone declares a deployment freeze. In each case the agent's instructions and its toolbox should change in the middle of the conversation.
Until this week, on the Gemini API, you had two bad options for that moment, and Google's own post describes both. You could slip the new rule into a user message, where it carries less weight and where a user can imitate it. Or you could rewrite the system prompt and tool list, which breaks the prompt cache (the stored, already-processed start of the conversation) and makes the model reread the whole history at full price.
On December 3, Google shipped a third option for the Gemini API. It is a real improvement. It also makes one mistake very easy to make, and the fix fits in one line: change every rule twice, once in the prompt and once in the code that runs the tools.
What Google shipped
The feature is called mid-conversation system instructions, and it lives in Gemini's Interactions API, the newer interface Google now recommends for all new projects. It is in public preview on the v1beta endpoint, for the Gemini 4 models (gemini-4-carbon, gemini-4-neon and gemini-4-hydrogen), according to Google's announcement and the developer docs.
The mechanism is a new kind of message called a system_input step. You place it right before the user's next message. It carries the same authority as your original system instruction and takes precedence over anything the user says.
The clever part is where it goes. Instead of editing the top of the conversation, which would invalidate everything cached after it, a system_input step gets appended at the current turn. The earlier tokens stay unchanged, so earlier turns can still reuse the prompt cache. Think of it as a note clipped to the current page of a long contract, rather than a reprint of the whole contract with a new first page.
A system_input step can also change the toolbox. It accepts two lists:
removed_toolstakes functions out of what the model can call, for example[{"type": "function", "name": "issue_refund"}].added_toolsputs new function definitions in, using the same format as your original tool list.
If one step has both, the API removes first and then adds, which lets you swap a tool's definition in place. Google's example shows a support agent losing issue_refund and gaining create_escalation_ticket in a single turn. There is no separate fee: the new tokens bill at the model's normal input rate, and earlier turns keep their cached rate.
The rules worth knowing before you build on it
The docs list a handful of rules, and some of them shape how you design around the feature. Any violation returns an HTTP 400 error.
- One
system_inputper turn, sent directly before auser_inputstep. You cannot send one on its own, and you cannot send one in the middle of a function-calling loop, while you are returning a tool's result. You wait for the next user turn. - Only your own function tools (functions you define and run yourself) can be swapped. MCP servers (Model Context Protocol, the common standard for plugging outside tools into an agent) and built-in tools such as Google Search or code execution are not supported yet.
- You keep sending the original tool list on every turn, including tools you removed. The API checks the stored history against it, so dropping a removed tool from the list breaks later turns. Tools you added mid-session stay out of that top-level list.
- Instructions stack. Every earlier
system_inputstays in the model's context for the rest of the session and cannot be deleted. When rules conflict, the model favors the newest one, so the docs advise saying what changed, for example "Refunds are available again. Ignore the earlier instruction that paused refunds." tool_choice, the setting that forces or forbids tool calls, only applies to tools in your initial list. The model can still call tools you added later.- It works only for model interactions in the Interactions API. The older
generateContentmethod and Gemini's managed agents do not support it.
That last pair of rules is where the trouble starts.
Why "the model was told" is not the same as "the agent cannot"
Read the feature list quickly and it sounds like permissions. Remove issue_refund, and the agent cannot refund. Add a deploy freeze, and the agent cannot deploy.
Google does not claim that, and says so directly. Its post calls system_input, added_tools and removed_tools "orchestration controls" and says your application "should still authorize every function call on the backend before executing it." It also warns to keep untrusted outside content, or anything an end user typed, out of system_input.
Here is the plain version. When you remove a tool with removed_tools, you change what the model believes it can call. You do not change what your server will execute if a request arrives. Those are two different places, and only one of them is under your control.
Consider how a request can reach your refund endpoint after you removed the tool in the prompt:
- A bug in your own app replays an old function call from a cached response.
- A prompt injection, text hidden in a web page or document the agent reads, convinces the model to emit a call it should not. Instructions in context reduce that risk. They do not remove it.
- A long session drifts. The docs themselves list "reinforce a rule late in a long multi-turn session" as a use case, which tells you rules can fade as context grows.
- Your code path that executes tool calls never checked the tool name against the current turn's permissions at all, because the team assumed the prompt handled it.
None of these is exotic. The last one is the most likely, and it is a design choice, not an attack.
The insight: change the rule twice
The useful way to think about system_input is as a steering wheel. It points the model in the right direction cheaply, at exactly the turn when the situation changes. You still need brakes, and brakes live in your code.
So every permission change in a long-running agent should happen twice, at the same turn:
- In the prompt, with
system_input, so the model knows the rule, explains it to the user and stops trying the blocked action. - In your backend, in a permission table your tool executor checks before running anything, so a call that slips through still fails.
The two should be driven by the same event. When your billing system flags the account, one function updates the session's allowed-tools record and builds the system_input step from that same record. If they ever disagree, your backend wins.
This sounds like extra work. It is a small amount of work, and it buys you the thing the prompt cannot: a guarantee.
Put this into practice
You need a Gemini API key, the google-genai Python package and a Gemini 4 model. The feature is in preview, so expect the details to move before general availability.
Step 1: keep one source of truth for permissions. Store the session's allowed tools outside the model, in your database or session state. A plain set works for a demo; in production this lives in durable session state tied to an authenticated user:
session_allowed = {"get_store_hours", "issue_refund"}
Step 2: check that set before executing any tool call. This is the brake. Every function call the model returns goes through it:
def run_tool_call(name, args):
if name not in session_allowed:
return {"error": f"{name} is not available in this session"}
return TOOLS[name](**args)
Step 3: when the situation changes, update the set and build the system_input from it. Following Google's documented pattern, send the original tools list unchanged and put the change on the step:
from google import genai
client = genai.Client(http_options={"api_version": "v1beta"})
session_allowed.discard("issue_refund")
session_allowed.add("create_escalation_ticket")
turn = client.interactions.create(
model="gemini-4-neon",
previous_interaction_id=last.id,
tools=tools, # the original list, unchanged
input=[
{
"type": "system_input",
"content": [{"type": "text", "text":
"This account is under billing review. Refunds are paused. "
"Offer to escalate instead."}],
"removed_tools": [{"type": "function", "name": "issue_refund"}],
"added_tools": [ESCALATION_TOOL],
},
{"type": "user_input", "content": [{"type": "text", "text": user_msg}]},
],
)
Step 4: test the brake. Write one test that calls run_tool_call("issue_refund", ...) directly after the change and confirms it fails. If that test passes only because the model behaved, it is not testing anything.
Step 5: log every system_input with the turn it arrived on. When you fetch an interaction, Google returns the system_input steps in order alongside the user and model turns, so a trace can show why the agent could do something at minute five and not at minute forty. Keep your own permission-change log next to it so the two can be compared.
What to expect: in Google's own examples the model reads the new rule and explains it ("a production deployment freeze is active, so we can't release"), which is the main user-facing win. Your cache keeps working across the change, which is the main cost win.
Honest limitations
This is a preview. Google says the API surface may change before general availability, and support for its enterprise agent platform is listed as coming soon.
The MCP gap from the rules list matters most in practice: if your agent gets most of its tools from MCP servers, you cannot swap those mid-session this way yet, and you are back to restarting or rebuilding.
Instructions only pile up. Because no system_input can be removed, a session with many reversals carries a growing stack of "ignore the earlier rule" notes. For very long sessions, a clean restart with a fresh system instruction may still be the better choice now and then.
Storage is on by default. The Interactions API stores requests so it can chain turns with previous_interaction_id; if you cannot keep conversation data on Google's side, read the data retention notes and the store=false option before you design around chaining.
And it is Gemini only. The pattern of changing the rule twice works with any model, but this exact cache-friendly mechanism is Google's.
The part that is up to you
The real shift here is economic. Changing an agent's rules in the middle of a session used to be expensive enough that teams avoided it and gave agents broad permissions up front. Now it costs a few input tokens. That makes it reasonable to give an agent only what it needs for the current step and widen or narrow that as the conversation goes.
Whether that makes your agent safer depends on one decision you make before shipping: whether the rule lives only in the prompt, or also in the code that runs the tools. Google built the steering wheel. The brakes are still yours to install.
Sources: Google: Introducing mid-conversation instructions in the Gemini API (December 3, 2026) · Gemini docs: Mid-conversation system instructions · Gemini docs: Interactions API overview