Skip to content

Interface: CheckpointStore

@providerprotocol/agents


@providerprotocol/agents / index / 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.).

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.

import { fileCheckpoints } from '@providerprotocol/agents/checkpoint';
import { AgentState } from '@providerprotocol/agents';
const store = fileCheckpoints({ dir: './checkpoints' });
// Save checkpoint after agent step
await store.save('session-123', state.toJSON());
// Resume from checkpoint on restart
const saved = await store.load('session-123');
if (saved) {
const restored = AgentState.fromJSON(saved);
// Continue execution from restored state
}
// Clean up when session is complete
await store.delete('session-123');

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.

string

The session identifier to delete.

Promise<void>

Promise that resolves when deletion is complete. Does not throw if the session doesn’t exist.

// Clean up after successful completion
await store.delete('completed-session');

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.

Promise<string[]>

Promise resolving to an array of session identifiers. Returns an empty array if no checkpoints exist.

const sessions = await store.list();
console.log(`Found ${sessions.length} saved sessions`);
// Clean up old sessions
for (const sessionId of sessions) {
const meta = await store.loadMetadata(sessionId);
if (isOlderThan(meta?.timestamp, '7d')) {
await store.delete(sessionId);
}
}

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().

string

The session identifier to load.

Promise<AgentStateJSON | null>

Promise resolving to the serialized state, or null if no checkpoint exists for this session.

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(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.

string

The session identifier to query.

Promise<CheckpointMetadata | null>

Promise resolving to checkpoint metadata, or null if no checkpoint exists for this session.

const meta = await store.loadMetadata('my-session');
if (meta) {
console.log(`Session at step ${meta.step}, saved at ${meta.timestamp}`);
}

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.

string

Unique identifier for the session. Used to organize and retrieve checkpoints. Should be consistent across restarts.

AgentStateJSON

The serialized agent state from AgentState.toJSON(). Contains complete execution history and context.

Promise<void>

Promise that resolves when the checkpoint is persisted.

await store.save('user-123-task-456', agentState.toJSON());