Grafy News
Try Grafy free

Gemini API introduces mid-conversation instruction updates

Google is enabling developers to update system instructions and tools during active sessions. Learn how this reduces latency and cost for AI agents.

Illustration for the news story: Gemini API introduces mid-conversation instruction updatesSource: Google AI Blog

Google is enabling developers to modify system instructions and toolsets in the middle of an active AI session without breaking the underlying prompt cache. This update, currently in preview via the Gemini API Interactions API, allows long-running AI agents to adapt to changing rules or new capabilities without the need to re-process the entire conversation history.

Introducing mid-conversation instructions in the Gemini API
Embedded audio from the source story.

Why can developers update instructions mid-session?

Until this update, developers faced a significant technical trade-off when managing long-running AI agents that might interact with users over dozens or hundreds of turns. According to the Google AI Blog, there were two primary workarounds for changing an agent's behavior during a session, both of which were inefficient.

One method involved placing new instructions within a standard user message. However, the Google AI Blog notes that these instructions do not carry the same authority as top-level system instructions and can be more easily bypassed or imitated by users. The second method involved rewriting the system instructions or the list of available tools entirely. This approach invalidated the prompt cache, forcing the model to re-read the whole conversation, which increased both latency and computational costs.

How does the Interactions API handle new instructions?

Through the new Interactions API, developers can send a system_input step at any point in the conversation. This step functions with the same level of authority as the initial system instructions and takes precedence over subsequent user messages.

To implement this, developers pass the ID of the previous turn using previous_interaction_id and insert a system_input step immediately before the user_input in the input array. Crucially, the top-level system instruction remains unchanged, which allows the preceding tokens to stay valid in the prompt cache. When multiple instructions are provided, the model follows the most recent system_input if a conflict arises with earlier rules.

Can tools be added or removed during a chat?

Yes, the update also facilitates dynamic tool management. To maintain the efficiency of the prompt cache, Google recommends keeping the top-level tools list identical across all turns. Instead of redefining the entire list, developers can use added_tools and removed_tools within a system_input step to update the model's functional capabilities as the session evolves.

For example, a support agent could start with a tool to check store hours and another to issue refunds. If a user's account undergoes a billing review, the developer can use a system_input to remove the issue_refund tool and add a create_escalation_ticket tool. The API processes removed_tools before added_tools, allowing for a seamless replacement of functions in a single step.

What are the practical benefits for AI agents?

According to Google, this capability opens several doors for more sophisticated agentic workflows:

  • Session-dependent constraints: Applying rules like spending limits or account entitlements that are only discovered mid-conversation.
  • Long-horizon reinforcement: Re-emphasizing specific formatting or tone requirements as the conversation grows longer and the model might drift.
  • Dynamic permissions: Enabling specific "write" tools only after a user has successfully authenticated or passed a certain stage of a workflow.
  • Live operational management: Disabling specific tools if a downstream service goes offline and restoring them once the service is stable.
  • Managing large tool catalogs: Starting with a minimal set of tools to save on initial processing and adding more only as the specific task requires them.

How does this affect costs and model support?

Updating instructions mid-conversation does not incur a separate fee. The tokens used within the system_input steps are billed at the standard input token rates for the specific model being used. Because the earlier parts of the conversation remain eligible for cached-token rates, the update helps maintain cost-efficiency for developers.

This feature is currently available in public preview across all Gemini 4 models via the v1beta endpoint in the Gemini API. Support for the Gemini Enterprise Agent Platform is expected to follow in the future.

How to explore evolving AI instructions in Grafy

While the Gemini API update is a developer-facing tool for building custom agents, the concept of interacting with various models and observing their behavior is central to the creator experience. Users can explore how different models handle complex instructions by using Grafy Chat, where multiple models can be tested side by side. For those interested in how instructions and history are managed in a more visual, non-linear way, Grafy Graph provides a branching view of prompts and outputs, which is useful for observing how different paths of a conversation evolve.

Frequently asked questions

Does updating instructions mid-conversation increase API costs?

Updating instructions mid-conversation does not introduce a separate fee. The tokens included in the system_input steps are billed at the standard input token rates for the model. Because the prompt cache remains intact, earlier turns continue to benefit from cached-token rates, helping to manage costs effectively.

Does a new system instruction replace the original one?

New instructions sent via system_input append to the conversation history and stay active for the rest of the session alongside the original top-level instruction. If a new instruction conflicts with a previous one, the model will prioritize the most recent instruction provided during the session.

Can I update tools without breaking the prompt cache?

Yes, you can update tools without breaking the cache by keeping the top-level tools list the same on every turn. Instead of redefining the entire list, you should use the added_tools and removed_tools parameters within a system_input step to modify the model's available functions dynamically.

Source: https://blog.google/innovation-and-ai/technology/developers-tools/gemini-api-mid-conversation-updates/


Source: Google AI Blog — Introducing mid-conversation instructions in the Gemini API