Skip to content

Migrate to Interactions API for stateful conversation history #1

Description

@zjshen14

Background

The Gemini Interactions API supports stateful sessions via previous_interaction_id. Instead of resending the full Message[] history on every turn, the server retains it and the client only sends the new message.

Measured savings (10-turn conversation):

  • ~79% reduction in input tokens
  • ~85% reduction in payload size
  • generateContent payload grows to 13× larger by turn 10

See docs/api-and-efficiency.md for the full analysis.

Why deferred

The Interactions API had structural breaking changes as recently as March 2026 (@google/genai v1.46.0). Migrating now risks instability. We revisit once it stabilises.

Scope

Migration is contained to two files:

  • src/model/gemini.ts — switch from generateContentStream to client.interactions.create()
  • src/model/schema.ts — verify if lowercase JSONSchema types are required (Interactions API uses lowercase vs our current uppercase)

The rest of the system communicates via StreamEvent and Message[] and requires no changes.

Requirements

  • @google/genai >= 1.33.0 (already satisfied)
  • Tools and system instruction must still be resent every turn (not retained server-side)
  • Maintain thoughtSignature handling for thinking models
  • Keep stateless fallback for compatibility

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions