Google's Gemini 4 Lets Developers Change AI Rules Mid-Conversation Without Flushing Cache
Gemini API now lets you inject new system rules and swap function tools mid-session without blowing up your prompt cache or reprocessing history.
Takeaways
- Gemini API adds mid-conversation system_input step to update rules and tools without breaking prompt cache.
- New step carries top-level system instruction authority and takes precedence over user messages.
- Tool swaps use added_tools and removed_tools fields; function tools only, no MCP server tools yet.
- No extra fee; system_input tokens billed at standard input rates, earlier turns stay cached.
- Available in public preview across all Gemini 4 models via Interactions API v1beta.
- See the official docs for implementation details and examples.
Google has added a system_input step to the Interactions API, allowing developers to change system instructions and active function tools midway through a conversation. The API can reuse the cached conversation prefix, reducing the latency and input-token cost of updating rules, permissions, or capabilities during long-running sessions.
System instructions carry higher priority than user messages, while tool declarations define the functions a model can call. Both traditionally sit at the beginning of a prompt. Editing either one changes the prefix used for caching, which can force the model to process the full conversation again.
Why mid-session changes flushed the cache
Developers previously relied on approaches with distinct costs:
- Put new rules in a user message. This preserved the cached prefix, but the instructions carried less authority and could be imitated by end users.
- Rebuild the system instruction or tool list. This preserved the instruction hierarchy, but changed the prompt prefix and invalidated its cache.
A permission change late in a support session could therefore trigger another pass over dozens of earlier turns. The repeated processing increased response time and input-token charges as transcripts grew.
A new turn type keeps the prefix stable
The Interactions API records system_input as a dedicated conversation step with the same authority as a top-level system instruction. It takes precedence over user messages, and the most recent system instruction governs when system-level rules conflict.
To append an update, pass the preceding turn’s ID through previous_interaction_id and place system_input immediately before the corresponding user_input. The top-level configuration remains stable, while the new instruction is added at the current turn boundary. Earlier tokens can therefore retain their cached status.
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 production deployment freeze is now active. "
"Recommend read-only diagnostics."
),
}],
},
{
"type": "user_input",
"content": [{
"type": "text",
"text": "Give me the command to deploy a new release.",
}],
},
],
)
Retrieved interactions show each system_input in sequence with user_input and model_output. That ordered trace exposes which rules applied to each response, supporting audits and debugging.
Tool access can follow session state
Function declarations can remain unchanged in the top-level tool list while added_tools and removed_tools adjust the callable set during the session. When both fields appear in one step, the API processes removals first, allowing an application to replace a function definition in place.
A support agent might begin with get_store_hours and issue_refund. If an account enters billing review, the application can remove issue_refund and add create_escalation_ticket without rebuilding the conversation prefix.
The preview limits these updates to function tools. MCP server tools are excluded from added_tools and removed_tools.
Applications must continue to authorize every function call on the backend. Google also advises keeping end-user and untrusted external content out of system_input, which belongs inside the application’s trusted orchestration boundary.
Five uses for turn-level controls
| Pattern | Mid-session update |
|---|---|
| Session constraints | Apply workspace settings, entitlements, or spending limits discovered during the conversation. |
| Instruction reinforcement | Restate formatting or policy rules as the context grows. |
| Dynamic permissions | Enable account-action tools after authentication and remove them when access returns to read-only mode. |
| Operational changes | Disable a function when its dependency fails and restore it after recovery. |
| Large tool catalogs | Load functions on demand, reducing declaration tokens and the number of tools the model must distinguish. |
Preview terms and token costs
Google charges no separate fee for mid-conversation system instructions. Tokens in system_input use the selected model’s standard input-token rate, while eligible earlier turns can continue receiving cached-token pricing.
The feature is available in public preview through the Interactions API’s v1beta endpoint for all Gemini 4 models. Support for Gemini Enterprise Agent Platform is planned.
Adopting the feature requires keeping top-level instructions and tool declarations stable, appending trusted changes through system_input, and enforcing permissions at execution time. For agents with long transcripts or frequently changing access, that structure reduces repeated processing without discarding the existing interaction chain.