If your agent swaps tools or changes rules mid-session, you already know the hidden bill. Every time you edit top-level system_instruction or rewrite your tools array to narrow an agent's capabilities, the prompt prefix changes and invalidates your cache.
On December 3, 2026, Google introduced a public preview update to the Gemini Interactions API (v1beta) that fixes this. A new system_input step lets you inject mid-conversation system instructions and toggle custom function tools on the fly while prior turns stay cached.
Why mid-session agent changes used to cost 20x more on Gemini 4
Before this release, teams building multi-turn agents on Gemini faced two awkward workarounds whenever session state changed:
-
Put the new rule inside a
user_inputmessage. That kept the prompt prefix intact, but user messages carry lower authority and can be overridden or imitated by end users. -
Rewrite the top-level
system_instructionortoolslist. That kept system authority intact, but changed the start of the prompt and busted the cache across the whole conversation history.
On Gemini 4 models, context caching runs implicitly once a matching prefix reaches at least 4,096 tokens, cutting cached input prices by 95% compared to standard input rates:
-
gemini-4-hydrogen: $1.50 per 1M standard input tokens vs. $0.075 cached ($7.50 output) -
gemini-4-neon: $3.00 per 1M standard input tokens vs. $0.15 cached ($15.00 output) -
gemini-4-carbon: $4.00 per 1M standard input tokens vs. $0.20 cached ($20.00 output)
With Gemini 4 Carbon and Argon moving to standard $4.00 / $20.00 pricing after November 30, every unnecessary prefix miss turns a $0.20 per-million read into a $4.00 read.
How system_input works in the Gemini Interactions API
Instead of mutating the top-level configuration, you chain turns with previous_interaction_id and place one system_input block right before user_input inside the input array. Because the initial system_instruction and tools declaration stay identical across calls, the prefix up to the current turn remains warm in the cache.
Here is the pattern from Google's December 3 announcement using gemini-4-neon on v1beta:
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,
# Keep top-level system_instruction identical so prior turns stay cached
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 carries the same authority as the top-level system_instruction and takes precedence over user turns. Non-conflicting rules stack over the life of the session. When a newer system_input contradicts an earlier rule, the model follows the newest instruction.
How to swap agent tools mid-chat with added_tools and removed_tools
For AI tool builders, the bigger win is tool scoping. Many agents start a session with read-only or general tools, then enable write tools after authentication or strip away sensitive actions when an account enters review.
You can pass removed_tools and added_tools inside the same system_input step:
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)
When both fields appear in one step, the API applies removed_tools before added_tools. That order lets you swap out and replace a tool definition in a single turn without leaving the old schema active. Tool changes persist across later turns until another system_input modifies them.
Five catches to check before shipping this
Before refactoring your agent loop around system_input, check these five limits from Google's release notes:
-
Custom function tools only. Right now,
added_toolsandremoved_toolsonly update custom function declarations. MCP server tools are not supported for mid-conversation updates yet. -
Public preview on
v1betaInteractions API only. The feature is live across Gemini 4 models (gemini-4-hydrogen,gemini-4-neon,gemini-4-carbon) through the Interactions API onv1beta, notgenerateContent. Support for the Gemini Enterprise Agent Platform is listed as coming soon. -
One
system_inputstep per turn. It must sit directly beforeuser_inputin theinputlist. -
Prompts are not authorization. Removing a tool in
system_inputonly changes what the model tries to invoke. Your backend still needs to enforce permissions on every function execution, and you should never put untrusted user or external text insidesystem_input. -
The new step still bills at standard input rates. There is no extra fee for
system_input, and earlier turns stay eligible for cached-token rates, while the newly appendedsystem_inputtokens themselves are billed at standard input pricing.
If you are comparing Gemini 4 Neon and Carbon against other models while designing your agent loop, Toolbit tracks model specs and pricing in its models directory (I work at Toolbit, so take that link with that context).
Check your usage.total_cached_tokens logs after moving mid-session state changes into system_input. As long as your shared prefix reaches at least 4,096 tokens and your top-level tools array stays fixed, your cache hit rate should hold across mode and permission switches.
This article was created with the help of AI and reviewed by the author.

Top comments (0)