{"slug": "introducing-mid-conversation-instructions-in-the-gemini-api", "title": "Introducing mid-conversation instructions in the Gemini API", "summary": "Google made mid-conversation system instruction and tool changes available in preview in the Gemini API through the Interactions API, letting agents adopt new rules and tools mid-session without invalidating the prompt cache. Developers send a `system_input` step before `user_input` with the prior turn's `previous_interaction_id`, and the new instruction carries the same authority as the top-level system instruction while earlier turns stay cached; conflicting instructions resolve in favor of the most recent one. The change removes the two prior workarounds — sending instructions as a user message, which lacks system-level authority, or rewriting the system instruction, which forces the model to reprocess the entire conversation history and adds cost and latency.", "body_md": "# Introducing mid-conversation instructions in the Gemini API\n\nToday, 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.\n\nLong-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.\n\nDevelopers have commonly relied on two workarounds:\n\n- **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.\n- **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.\n\nThe 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.\n\n## How it works\n\nTo 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:\n\n``` python\nfrom google import genai\n\nclient = genai.Client(http_options={\"api_version\": \"v1beta\"})\nsystem_instruction = \"You are an infrastructure troubleshooting assistant.\"\n\nturn1 = client.interactions.create(\n  model=\"gemini-4-neon\",\n  system_instruction=system_instruction,\n  input=\"Latency just spiked on our service. What should I check first?\",\n)\n\nturn2 = client.interactions.create(\n  model=\"gemini-4-neon\",\n  previous_interaction_id=turn1.id,\n  system_instruction=system_instruction,\n  input=[\n    {\n      \"type\": \"system_input\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": (\n            \"A production deployment freeze is now active. \"\n            \"Recommend read-only diagnostics and do not allow further rollouts.\"\n          ),\n        }\n      ],\n    },\n    {\n      \"type\": \"user_input\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"Give me the command to deploy a new release.\",\n        }\n      ],\n    },\n  ],\n)\nprint(turn2.output_text)\n```\n\nEach `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.\n\nWhen 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:\n\n```\n{\n  \"steps\": [\n    {\n      \"type\": \"system_input\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"A production deployment freeze is now active. Recommend read-only diagnostics and do not allow further rollouts.\"\n        }\n      ]\n    },\n    {\n      \"type\": \"user_input\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"Give me the command to deploy a new release.\"\n        }\n      ]\n    },\n    {\n      \"type\": \"model_output\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": \"A production deployment freeze is active, so we can't release. Here are some checks you can run...\"\n        }\n      ]\n    }\n  ]\n}\n```\n\nBecause `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.\n\n## How mid-conversation tool updates work\n\nTool 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.\n\nIn 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:\n\n``` python\nfrom google import genai\nclient = genai.Client(http_options={\"api_version\": \"v1beta\"})\ntools = [\n  {\n    \"type\": \"function\",\n    \"name\": \"get_store_hours\",\n    \"description\": \"Look up opening hours for a store.\",\n    \"parameters\": {\n      \"type\": \"object\",\n      \"properties\": {\"store_id\": {\"type\": \"string\"}},\n      \"required\": [\"store_id\"],\n    },\n  },\n  {\n    \"type\": \"function\",\n    \"name\": \"issue_refund\",\n    \"description\": \"Refund an order.\",\n    \"parameters\": {\n      \"type\": \"object\",\n      \"properties\": {\"order_id\": {\"type\": \"string\"}},\n      \"required\": [\"order_id\"],\n    },\n  },\n]\nturn1 = client.interactions.create(\n  model=\"gemini-4-neon\",\n  input=\"Hi, I have a question about my order.\",\n  tools=tools,\n)\nturn2 = client.interactions.create(\n  model=\"gemini-4-neon\",\n  previous_interaction_id=turn1.id,\n  tools=tools,\n  input=[\n    {\n      \"type\": \"system_input\",\n      \"content\": [\n        {\n          \"type\": \"text\",\n          \"text\": (\n            \"This account is under billing review. Explain \"\n            \"that refunds are paused and offer to escalate.\"\n          ),\n        }\n      ],\n      \"removed_tools\": [{\"type\": \"function\", \"name\": \"issue_refund\"}],\n      \"added_tools\": [\n        {\n          \"type\": \"function\",\n          \"name\": \"create_escalation_ticket\",\n          \"description\": \"Escalate a billing review issue to support.\",\n          \"parameters\": {\n            \"type\": \"object\",\n            \"properties\": {\"order_id\": {\"type\": \"string\"}},\n            \"required\": [\"order_id\"],\n          },\n        }\n      ],\n    },\n    {\n      \"type\": \"user_input\",\n      \"content\": [{\"type\": \"text\", \"text\": \"Refund order 12345.\"}],\n    },\n  ],\n)\nprint(turn2.output_text)\n```\n\nTool 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.\n\nKeep 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`.\n\n## How you can use it\n\n**Session-dependent constraints:** Apply rules discovered partway through a conversation, such as workspace settings, account entitlements, or spending limits.\n\n**Long-horizon instruction reinforcement:** Re-emphasize key formatting, tone, or policy rules deep into multi-turn sessions as context grows.\n\n**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.\n\n**Live operational changes:** Disable a tool and update guidance mid-session when a downstream dependency goes offline, then restore it once service recovers.\n\n**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.\n\n## How pricing and supported models work\n\nMid-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.\n\nMid-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.\n\nGet 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/).", "url": "https://wpnews.pro/news/introducing-mid-conversation-instructions-in-the-gemini-api", "canonical_source": "https://blog.google/innovation-and-ai/models-and-research/gemini-models/gemini-api-mid-conversation-updates/", "published_at": "2026-12-03 18:00:00+00:00", "updated_at": "2026-12-03 18:16:14.565389+00:00", "lang": "en", "topics": ["artificial-intelligence", "large-language-models", "ai-agents", "developer-tools", "ai-products"], "entities": ["Google", "Gemini API", "Interactions API"], "also_reported_by": [], "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.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/introducing-mid-conversation-instructions-in-the-gemini-api", "markdown": "https://wpnews.pro/news/introducing-mid-conversation-instructions-in-the-gemini-api.md", "text": "https://wpnews.pro/news/introducing-mid-conversation-instructions-in-the-gemini-api.txt", "jsonld": "https://wpnews.pro/news/introducing-mid-conversation-instructions-in-the-gemini-api.jsonld"}}