Persistence

class Persistence(persistenceStorageProvider: PersistenceStorageProvider<*>, clock: Clock = Clock.System)(source)

A feature that provides checkpoint functionality for AI agents.

This class allows saving and restoring the state of an agent at specific points during execution. Checkpoints capture the agent's message history, current node, and input data, enabling:

  • Resuming agent execution from a specific point

  • Rolling back to previous states

  • Persisting agent state across sessions

The feature can be configured to automatically create checkpoints after each node execution using the PersistenceFeatureConfig.enableAutomaticPersistence option.

Constructors

Link copied to clipboard
constructor(persistenceStorageProvider: PersistenceStorageProvider<*>, clock: Clock = Clock.System)

Types

Link copied to clipboard

Companion object implementing agent feature, handling Persistence creation and installation.

Properties

Link copied to clipboard

Determines the strategy to use during rollback operations for the agent's state.

Link copied to clipboard

A registry for managing rollback tools within the persistence system.

Functions

Link copied to clipboard
suspend fun createCheckpoint(agentContext: AIAgentContext, nodePath: String, lastInput: Any?, lastInputType: KType, version: Long, checkpointId: String? = null): AgentCheckpointData?

Creates a checkpoint of the agent's current state.

Link copied to clipboard
suspend fun createTombstoneCheckpoint(agentId: String, time: Instant, parentId: Long): AgentCheckpointData

Creates and saves a tombstone checkpoint for an agent's session.

Link copied to clipboard
suspend fun getCheckpointById(agentId: String, checkpointId: String): AgentCheckpointData?

Retrieves a specific checkpoint by ID for the specified agent.

Link copied to clipboard

Retrieves the latest checkpoint for the specified agent.

Link copied to clipboard
suspend fun rollbackToCheckpoint(checkpointId: String, agentContext: AIAgentContext): AgentCheckpointData?

Rolls back an agent's state to a specific checkpoint.

Link copied to clipboard

Rolls back an agent's state to the latest checkpoint.

Link copied to clipboard
suspend fun saveCheckpoint(agentId: String, checkpointData: AgentCheckpointData)

Saves a checkpoint using the configured storage provider.

Link copied to clipboard
fun setExecutionPoint(agentContext: AIAgentContext, nodePath: String, messageHistory: List<Message>, input: JsonElement)

Sets the execution point of an agent to a specific state.