Interface: CheckpointStore
@providerprotocol/agents / index / CheckpointStore
Interface: CheckpointStore
Section titled “Interface: CheckpointStore”Defined in: src/checkpoint/types.ts:54
Interface for checkpoint storage implementations.
Implementations handle persistence of agent state at step boundaries for crash recovery and session resume. Each implementation can use different storage backends (filesystem, database, cloud storage, etc.).
Remarks
Section titled “Remarks”The checkpoint store is called by the agent after each successful step. Implementations should be atomic - either the entire checkpoint is saved successfully, or nothing is changed. This ensures consistent state recovery even if a crash occurs during the save operation.
Example
Section titled “Example”import { fileCheckpoints } from '@providerprotocol/agents/checkpoint';import { AgentState } from '@providerprotocol/agents';
const store = fileCheckpoints({ dir: './checkpoints' });
// Save checkpoint after agent stepawait store.save('session-123', state.toJSON());
// Resume from checkpoint on restartconst saved = await store.load('session-123');if (saved) { const restored = AgentState.fromJSON(saved); // Continue execution from restored state}
// Clean up when session is completeawait store.delete('session-123');Methods
Section titled “Methods”delete()
Section titled “delete()”delete(
sessionId):Promise<void>
Defined in: src/checkpoint/types.ts:136
Deletes all checkpoints for a session.
Removes the checkpoint data and metadata for the specified session. This should be called when a session is complete and no longer needs recovery capability.
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”string
The session identifier to delete.
Returns
Section titled “Returns”Promise<void>
Promise that resolves when deletion is complete. Does not throw if the session doesn’t exist.
Example
Section titled “Example”// Clean up after successful completionawait store.delete('completed-session');list()
Section titled “list()”list():
Promise<string[]>
Defined in: src/checkpoint/types.ts:161
Lists all session IDs that have checkpoints.
Returns identifiers for all sessions with saved checkpoints. Useful for implementing session management UI or cleanup routines.
Returns
Section titled “Returns”Promise<string[]>
Promise resolving to an array of session identifiers. Returns an empty array if no checkpoints exist.
Example
Section titled “Example”const sessions = await store.list();console.log(`Found ${sessions.length} saved sessions`);
// Clean up old sessionsfor (const sessionId of sessions) { const meta = await store.loadMetadata(sessionId); if (isOlderThan(meta?.timestamp, '7d')) { await store.delete(sessionId); }}load()
Section titled “load()”load(
sessionId):Promise<AgentStateJSON|null>
Defined in: src/checkpoint/types.ts:97
Loads the most recent checkpoint for a session.
Retrieves the previously saved state, which can be used to create
an AgentState instance via AgentState.fromJSON().
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”string
The session identifier to load.
Returns
Section titled “Returns”Promise<AgentStateJSON | null>
Promise resolving to the serialized state, or null if
no checkpoint exists for this session.
Example
Section titled “Example”const saved = await store.load('my-session');if (saved) { const state = AgentState.fromJSON(saved); // Resume execution with restored state} else { // Start fresh with initial state const state = AgentState.initial();}loadMetadata()
Section titled “loadMetadata()”loadMetadata(
sessionId):Promise<CheckpointMetadata|null>
Defined in: src/checkpoint/types.ts:117
Loads checkpoint metadata without loading the full state.
Useful for displaying session information (timestamp, step count) without the overhead of deserializing the complete state.
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”string
The session identifier to query.
Returns
Section titled “Returns”Promise<CheckpointMetadata | null>
Promise resolving to checkpoint metadata, or null if
no checkpoint exists for this session.
Example
Section titled “Example”const meta = await store.loadMetadata('my-session');if (meta) { console.log(`Session at step ${meta.step}, saved at ${meta.timestamp}`);}save()
Section titled “save()”save(
sessionId,state):Promise<void>
Defined in: src/checkpoint/types.ts:73
Saves a checkpoint of the current agent state.
Persists the serialized agent state, overwriting any existing checkpoint for the same session. The save operation should be atomic to prevent corruption.
Parameters
Section titled “Parameters”sessionId
Section titled “sessionId”string
Unique identifier for the session. Used to organize and retrieve checkpoints. Should be consistent across restarts.
The serialized agent state from AgentState.toJSON().
Contains complete execution history and context.
Returns
Section titled “Returns”Promise<void>
Promise that resolves when the checkpoint is persisted.
Example
Section titled “Example”await store.save('user-123-task-456', agentState.toJSON());