> ## AI Agent Context
> - Full documentation index: https://aistudio.google.com/llms.txt
> - Gemini Docs MCP server (consistent live info): https://gemini-api-docs-mcp.dev
> - Coding agent skills & setup guide: https://aistudio.google.com/docs/coding-agents.md

# Mid-conversation system instructions

{% callout type="note" %}
  Mid-conversation system instructions are in [preview](/docs/models#preview) and
  require the `v1beta` [API version](/api-reference/api-versions). The API surface
  may change before general availability.

{% /callout %}

In long conversations, rules and available tools often change after the first
turn. Editing your initial system instructions or tool list forces the model to
reprocess the full conversation history from scratch. On the
[Interactions API](/docs/interactions-overview), you can send a `system_input`
step to append new rules or tool updates while keeping earlier turns cached.

Use `system_input` when you need to:

*   Reinforce a rule late in a long multi-turn session.
*   Add a constraint learned mid-session, such as a budget cap or jurisdiction
    rule.
*   Enable or disable function tools with `added_tools` and `removed_tools`
    (for example, after a user completes OAuth or when a feature is paused).

## Send a system instruction  {% id="send" %}

To send an instruction mid-conversation, pass the previous turn's ID in
`previous_interaction_id` and place a `system_input` step directly before the
`user_input` step in the `input` array:

{% tabs %}
  

  {% tab filename="system_input.py" label="Python" %}
  ```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)
  ```

  {% /tab %}

  

  {% tab filename="system_input.js" label="JavaScript" %}
  ```javascript
  import { GoogleGenAI } from "@google/genai";
  
  const client = new GoogleGenAI({ httpOptions: { apiVersion: "v1beta" } });
  
  const first = await client.interactions.create({
    model: "gemini-4-hydrogen",
    input: "Hi, I'd like some help with my account.",
  });
  
  const interaction = await 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?" },
        ],
      },
    ],
  });
  
  console.log(interaction.output_text);
  ```

  {% /tab %}

  

  {% tab filename="system_input.sh" label="REST" %}
  ```bash
  FIRST_ID=$(curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
    -H "x-goog-api-key: $GEMINI_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
      "model": "gemini-4-hydrogen",
      "input": "Hi, I'"'"'d like some help with my account."
    }' | jq -r '.id')
  
  RESPONSE=$(curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
    -H "x-goog-api-key: $GEMINI_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
      "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?"}
          ]
        }
      ]
    }')
  
  INTERACTION_ID=$(echo "$RESPONSE" | jq -r '.id')
  echo "$RESPONSE" | jq -r '.steps[] | select(.type == "model_output") | .content[] | select(.type == "text") | .text'
  ```

  {% /tab %}

  

{% /tabs %}

### How multiple instructions combine  {% id="multiple" %}

The API adds each `system_input` to the conversation history as its own step.
It doesn't replace or delete earlier instructions:

*   Your top-level `system_instruction` and every earlier `system_input` stay in
    the model's context for the rest of the conversation.
*   A new `system_input` adds to them. Rules that don't conflict all keep
    applying.
*   If a new instruction conflicts with an earlier one, the model favors the
    most recent instruction. Because earlier instructions stay in context,
    state what changed (for example, "Refunds are available again. Ignore the
    earlier instruction that paused refunds.").

### Rules for sending `system_input` {% id="rules" %}

If a request breaks any of these rules, the API returns HTTP 400:

*   Send `system_input` directly before a `user_input` step.
*   Send at most one `system_input` per turn.
*   Don't send `system_input` on its own or during a function-calling loop (when
    returning a `function_result` step). Wait until the next `user_input` turn.
*   Send text only in `content`.
*   Include text in `content` unless the step adds or removes tools.

## Add or remove tools mid-conversation  {% id="tools" %}

Tool definitions sit at the start of the prompt, so if you change the `tools`
list between turns, you invalidate the prompt cache. Instead, send the same
`tools` list every turn and use `added_tools` and `removed_tools` on a
`system_input` step to change what the model can call.

Keep passing the original `tools` list on every turn. Doing so preserves the
prompt cache and is required when chaining turns with
`previous_interaction_id`. Pass `removed_tools` and `added_tools` on
`system_input` to swap active functions mid-session:

{% tabs %}
  

  {% tab filename="system_input_tools.py" label="Python" %}
  ```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)
  ```

  {% /tab %}

  

  {% tab filename="system_input_tools.js" label="JavaScript" %}
  ```javascript
  import { GoogleGenAI } from "@google/genai";
  
  const client = new GoogleGenAI({ httpOptions: { apiVersion: "v1beta" } });
  
  const 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"],
      },
    },
  ];
  
  const first = await client.interactions.create({
    model: "gemini-4-hydrogen",
    input: "Hi, I have a question about my order.",
    tools: tools,
  });
  
  const interaction = await 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." }],
      },
    ],
  });
  
  console.log(interaction.output_text);
  ```

  {% /tab %}

  

  {% tab filename="system_input_tools.sh" label="REST" %}
  ```bash
  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_ID=$(curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
    -H "x-goog-api-key: $GEMINI_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
      "model": "gemini-4-hydrogen",
      "input": "Hi, I have a question about my order.",
      "tools": '"$TOOLS"'
    }' | jq -r '.id')
  
  curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
    -H "x-goog-api-key: $GEMINI_API_KEY" \
    -H 'Content-Type: application/json' \
    -d '{
      "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."}]
        }
      ]
    }'
  ```

  {% /tab %}

  

{% /tabs %}

### Tool update rules  {% id="tool-rules" %}

Follow these rules when updating tools with `system_input`:

*   `added_tools` and `removed_tools` only support custom `function` tools. MCP
    servers and built-in tools (like Google Search or code execution) aren't
    currently supported.
*   `removed_tools` takes tool objects with `"type": "function"` and the
    `"name"` of an active function from `tools` or from an earlier `added_tools`
    (`[{"type": "function", "name": "issue_refund"}]`), not bare strings.
*   `added_tools` takes full function definitions, using the same schema as
    entries in `tools`.
*   Tool changes stay in effect until another `system_input` changes them. If a
    step includes both fields, the API processes `removed_tools` before
    `added_tools`.
*   Keep passing the original top-level `tools` list on every turn in a
    `previous_interaction_id` chain, including tools you removed with
    `removed_tools`. The API validates stored history against each request's
    `tools` list, so dropping a removed tool returns HTTP 400 on later turns.
*   Leave tools added via `added_tools` out of the top-level `tools` list on
    later turns. Re-declaring an active added tool in `tools` returns HTTP 400.

## Retrieve an interaction  {% id="retrieve" %}

When you retrieve an interaction, the `system_input` step appears in order with
the other steps, including any `added_tools` and `removed_tools`. Pass the
interaction ID from
[Send a system instruction](/docs/mid-conversation-instructions#send) to
inspect its steps:

{% tabs %}
  

  {% tab filename="get_interaction.py" label="Python" %}
  ```python
  retrieved = client.interactions.get(id=interaction.id)
  
  for step in retrieved.steps:
      print(step.type)
  ```

  {% /tab %}

  

  {% tab filename="get_interaction.js" label="JavaScript" %}
  ```javascript
  const retrieved = await client.interactions.get(interaction.id);
  
  for (const step of retrieved.steps) {
    console.log(step.type);
  }
  ```

  {% /tab %}

  

  {% tab filename="get_interaction.sh" label="REST" %}
  ```bash
  curl -X GET "https://generativelanguage.googleapis.com/v1beta/interactions/$INTERACTION_ID" \
    -H "x-goog-api-key: $GEMINI_API_KEY"
  ```

  {% /tab %}

  

{% /tabs %}

### Response  {% id="retrieve-response" %}

The response lists the `system_input` step first, followed by the user turn and
the model's reply:

```json
{
  "id": "INTERACTION_ID",
  "status": "completed",
  "steps": [
    {
      "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?"}
      ]
    },
    {
      "type": "model_output",
      "content": [
        {"type": "text", "text": "Before I share your stored addresses, please review our CCPA disclosure..."}
      ]
    }
  ]
}
```

## Supported models  {% id="supported-models" %}

`system_input` is supported on the following models (other models return an
HTTP `400` error):

*   [`gemini-4-carbon`](/docs/models/gemini-4-carbon)
*   [`gemini-4-neon`](/docs/models/gemini-4-neon)
*   [`gemini-4-hydrogen`](/docs/models/gemini-4-hydrogen)

## Best practices  {% id="best-practices" %}

*   Keep baseline behavior in `system_instruction` and reserve `system_input`
    for rules or tool changes that happen mid-session.
*   Include a short text note when removing a tool with `removed_tools` so the
    model can explain why the action is unavailable.
*   When reversing an earlier `system_input`, tell the model to ignore the
    earlier rule, since prior steps stay in context.

## Limitations  {% id="limitations" %}

*   Supported on the Interactions API only (`v1beta`). The
    [`generateContent`](/docs/text-generation?generate-content=true) method
    doesn't support `system_input`.
*   Supported on `model` interactions only. `agent` interactions aren't
    supported.
*   Each `system_input` step stays in context for the rest of the conversation
    and can't be removed.
*   [Function calling modes](/docs/function-calling#function_calling_modes)
    (`tool_choice`) only apply to tools in your initial `tools` list. The model
    can still call tools added mid-conversation with `added_tools`.

## What's next  {% id="whats-next" %}

*   Read the [Interactions API overview](/docs/interactions-overview) to learn
    about session and state management.
*   See [System instructions](/docs/text-generation#system-instructions) to set
    initial instructions for a conversation.
*   Explore [Function calling](/docs/function-calling) and
    [Context caching](/docs/caching).

