Interface SnapshotWriter<S>

Type Parameters:
S - the type of custom session state
All Known Subinterfaces:
SessionStore<S>
All Known Implementing Classes:
CosmosSessionStore, DynamoDbSessionStore, FileSessionStore, FirestoreSessionStore, InMemorySessionStore, MongoSessionStore, PostgresSessionStore

public interface SnapshotWriter<S>
Write side of a session store.

The single write primitive is saveSnapshot(java.lang.String, com.google.genkit.ai.agent.SnapshotMutator<S>, com.google.genkit.ai.agent.SessionStoreOptions), an atomic read-modify-write. Stores enforce the following rules (see individual implementations for details):

  • If snapshotId is null the store mints a UUID.
  • The store preserves sessionId from the existing snapshot when available.
  • An empty sessionId is rejected with INVALID_ARGUMENT.
  • An empty status defaults to completed.
  • The SnapshotMutator may be retried on transient conflicts; it must be pure.
  • Method Summary

    Modifier and Type
    Method
    Description
    saveSnapshot(String snapshotId, SnapshotMutator<S> mutator, SessionStoreOptions options)
    Atomically reads the snapshot identified by snapshotId (or creates a new one), applies mutator, and persists the result.
  • Method Details

    • saveSnapshot

      String saveSnapshot(String snapshotId, SnapshotMutator<S> mutator, SessionStoreOptions options)
      Atomically reads the snapshot identified by snapshotId (or creates a new one), applies mutator, and persists the result.
      Parameters:
      snapshotId - the ID of the snapshot to write; if null the store mints a UUID
      mutator - the pure read-modify-write function; receives the existing snapshot (or null) and returns the snapshot to persist, or null to decline
      options - store options
      Returns:
      the snapshot ID that was written, or null if the mutator declined