Enhancing Conversations with Mid-Session Updates in the Gemini API

The Gemini API has introduced a groundbreaking feature that allows developers to make updates to system instructions and tools during an ongoing conversation. This enhancement is available through the Interactions API and is designed to streamline interactions without compromising the efficiency of the prompt cache.
Understanding Mid-Conversation Changes
Traditionally, developers faced challenges when needing to adjust system instructions or update tools in the middle of a session. This limitation often required them to re-read the entire conversation or risk incurring additional costs. However, with the new capabilities of the Interactions API, such adjustments can be made seamlessly.
How It Works
- System Input Step: Developers can now send a system_input step at any point in the conversation. This step carries the same weight as the top-level system instruction and takes precedence over user messages.
- Maintaining Cache Integrity: By keeping the top-level system_instruction unchanged across turns, the prompt cache remains valid. This means that the conversation history can grow without losing the context established in previous turns.
- Conflict Management: In cases where a new system_input conflicts with an earlier instruction, the model prioritizes the most recent instruction, ensuring that the latest directives are always in effect.
Practical Implementation
To implement mid-conversation updates, developers simply need to reference the previous turn’s ID using previous_interaction_id and place the new system_input step just before the user_input in the input array. This method allows for dynamic adjustments while maintaining a clear audit trail.
Tool Updates and Management
Tool management is also simplified with the introduction of system_input. Developers are encouraged to keep the top-level tools list consistent across turns. Instead of altering the entire list, they can now utilize added_tools and removed_tools to manage which functions the model can access as the session progresses.
- Example Scenario: A support agent might begin with functions like get_store_hours and issue_refund. If the need arises to remove issue_refund and add create_escalation_ticket, the top-level tools list remains unchanged, ensuring continuity in the prompt cache.
- Contextual Updates: Adding a brief note when removing a tool can provide the model with context, helping explain to users why a certain action is no longer available.
Session Management and Constraints
The Gemini API also facilitates session-dependent constraints, allowing developers to apply rules discovered during the conversation. This can include adjusting workspace settings, account entitlements, or spending limits based on user interactions.
Dynamic Features and Real-Time Adjustments
One of the most significant advantages of this new system is the ability to reinforce instructions and permissions dynamically. For instance, developers can enable write or account-action tools after user authentication, and subsequently disable them when reverting to a read-only mode. This flexibility is crucial for maintaining operational efficiency and user experience.
Moreover, if a tool becomes unavailable during a session due to external factors, developers can quickly disable it and update the guidance provided to users. Once the service is restored, the tool can be re-enabled without disrupting the flow of conversation.
Overall, the introduction of mid-conversation updates in the Gemini API represents a significant leap forward for developers looking to create more responsive and adaptable conversational agents. By leveraging these new capabilities, businesses can enhance user interactions and streamline their operational workflows.
Source for the original facts: Original source.



