# Introducing mid-conversation instructions in the Gemini API

> Source: <https://blog.google/innovation-and-ai/models-and-research/gemini-models/gemini-api-mid-conversation-updates/>
> Published: 2026-12-03 18:00:00+00:00

**Key takeaway:** Send a `system_input` step before `user_input` with `previous_interaction_id` to change system instructions or tools mid-session while keeping the prompt prefix cached, instead of rewriting the top-level system instruction.

# Introducing mid-conversation instructions in the Gemini API

Today, mid-conversation system instruction and tool changes are available in preview in the [Gemini API](https://aistudio.google.com/docs/mid-conversation-instructions) through the [Interactions API](https://aistudio.google.com/docs/interactions-overview). This lets agents adapt to new rules and tools mid-session without re-reading the entire conversation or driving up costs.

Long-running agents often work across dozens, if not hundreds, of turns. Along the way, rules, permissions and available tools change. Until now, you couldn't give the model a new system instruction or update tools without invalidating the cache.

Developers have commonly relied on two workarounds:

- **Putting instructions in a user message:** To preserve the cache, you could send new system instructions as a user message. These don’t carry the same weight as your top-level system instructions and allow users to try and imitate them.
- **Rewriting system instruction or tools:** Rewriting the system instruction or changing tools invalidates the prompt cache. The model reprocesses the entire conversation history, adding cost and latency.

The Interactions API now allows you to send a `system_input` step at any turn with system instruction or tool changes. It carries the same authority as your top-level system instruction and takes precedence over user messages, while earlier turns stay cached.

## How it works

To send an instruction mid-conversation, pass the previous turn's ID in `previous_interaction_id` and place a `system_input` step directly before `user_input` in the input array. Keep your top-level `system_instruction` unchanged across turns so the prompt prefix stays valid in the cache:

``` python
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,
  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` appends to the conversation history as its own step and stays active for the rest of the session alongside the top-level `system_instruction`. Rules that cover different topics remain in effect together. When a newer `system_input` conflicts with an earlier instruction, the model favors the most recent instruction.

When you retrieve an interaction with `client.interactions.get(id=turn2.id)`, each `system_input` step appears in order alongside `user_input` and `model_output`, making multi-turn agent traces straightforward to audit and debug:

```
{
  "steps": [
    {
      "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."
        }
      ]
    },
    {
      "type": "model_output",
      "content": [
        {
          "type": "text",
          "text": "A production deployment freeze is active, so we can't release. Here are some checks you can run..."
        }
      ]
    }
  ]
}
```

Because `system_input` appends at the current turn boundary, all preceding tokens remain identical from turn to turn and reuse the prompt cache. You can send one `system_input` step per turn directly before `user_input`, containing text content, tool updates, or both.

## How mid-conversation tool updates work

Tool declarations sit at the start of the prompt, so changing the top-level tools list between turns breaks the prompt cache. With `system_input`, we recommend you leave the same top-level tools list on every turn and use `added_tools` and `removed_tools` to update which functions the model can call as the session evolves. Only updating function tools via `added_tools` and `removed_tools` is currently supported and not MCP server tools.

In this example, a support agent starts with `get_store_hours` and `issue_refund`. On the next turn, the app removes `issue_refund` and adds `create_escalation_ticket` while keeping the top-level `tools` list identical:

``` 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"],
    },
  },
]
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)
```

Tool updates stay in effect until a later `system_input` changes them. When a single step includes both fields, the API processes `removed_tools` before `added_tools`, letting you replace a tool definition in place. Adding a short text note when removing a tool also gives the model context to explain why an action is unavailable.

Keep in mind that `system_input`, `added_tools`, and `removed_tools` steer model behavior and serve as orchestration controls. Your application should still authorize every function call on the backend before executing it and keep untrusted external or end-user content out of `system_input`.

## How you can use it

**Session-dependent constraints:** Apply rules discovered partway through a conversation, such as workspace settings, account entitlements, or spending limits.

**Long-horizon instruction reinforcement:** Re-emphasize key formatting, tone, or policy rules deep into multi-turn sessions as context grows.

**Dynamic permissions and mode switches:** Enable write or account-action tools after authentication or plan approval, and remove them when returning to read-only review.

**Live operational changes:** Disable a tool and update guidance mid-session when a downstream dependency goes offline, then restore it once service recovers.

**Large tool catalogs**: Start with a small set of tools and add more as the task needs them, without declaring every tool up front or breaking the cache.

## How pricing and supported models work

Mid-conversation system instructions carry no separate fee. Tokens in system_input steps are billed at the standard input token rates for the model you call. Earlier turns remain eligible for cached-token rates when rules or tools change.

Mid-conversation system instructions are available in public preview across [all Gemini 4 models](https://aistudio.google.com/docs/latest-model) in the Interactions API (through [v1beta endpoint](https://aistudio.google.com/api-reference/api-versions)), in the [Gemini API](https://aistudio.google.com/docs/mid-conversation-instructions). Support for [Gemini Enterprise Agent Platform](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/capabilities/interactions) to come soon.

Get started today by reading the [documentation](https://aistudio.google.com/docs/mid-conversation-instructions), [comparing Gemini models](https://aistudio.google.com/docs/choosing-a-model) to find the right Gemini 4 model for your workload, and [join the discussion on the AI Developer Forum](https://discuss.ai.google.dev/).
