Package com.google.genkit.ai.agent
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
snapshotIdisnullthe store mints a UUID. - The store preserves
sessionIdfrom the existing snapshot when available. - An empty
sessionIdis rejected withINVALID_ARGUMENT. - An empty
statusdefaults tocompleted. - The
SnapshotMutatormay be retried on transient conflicts; it must be pure.
-
Method Summary
Modifier and TypeMethodDescriptionsaveSnapshot(String snapshotId, SnapshotMutator<S> mutator, SessionStoreOptions options) Atomically reads the snapshot identified bysnapshotId(or creates a new one), appliesmutator, and persists the result.
-
Method Details
-
saveSnapshot
Atomically reads the snapshot identified bysnapshotId(or creates a new one), appliesmutator, and persists the result.- Parameters:
snapshotId- the ID of the snapshot to write; ifnullthe store mints a UUIDmutator- the pure read-modify-write function; receives the existing snapshot (ornull) and returns the snapshot to persist, ornullto declineoptions- store options- Returns:
- the snapshot ID that was written, or
nullif the mutator declined
-