Sam
09/10/2025, 9:55 AMPersistency feature? This includes when to save checkpoints, when to retrieve checkpoints, how to amend the prompt with the retrieval, etc
Also I need to understand how this ties in to the Prompt I need to create and provide to the AIAgentConfig object that I subsequently pass to the AIAgent instance before the agent runs. Should I be utilising my PersistencyStorageProvider to create this Prompt or should I be doing most of these operations in the strategy graph itself? @Vadim Briliantov
Any code examples would be greatly appreciatedMark Tkachenko
09/11/2025, 11:26 AMmanaging conversation history within nodes in a strategy graph using theHello! What exactly do you mean by this? Currently you can form and save any checkpoint you have. Checkpoint structure contains the message history list. Also I’m planning to implement more separate message history persistence API, because there is demand for it 😄 So, currenly it’s possible with saving and reading checkpoints, but more APIs to come soon.featurePersistency
Sam
09/11/2025, 12:15 PMenableAutomaticPersistency = true when I install the Persistency feature. This means, and correct me if I'm wrong, that a checkpoint is created and stored AFTER each node has finished executing:
From Persistency.kt
pipeline.interceptAfterNode(interceptContext) { eventCtx ->
if (config.enableAutomaticPersistency) {
createCheckpoint(
agentContext = eventCtx.context,
nodeId = eventCtx.node.id,
lastInput = eventCtx.input,
lastInputType = eventCtx.inputType,
)
}
}
Now, right before the agent starts, this code is called in Persistency.kt :
pipeline.interceptBeforeAgentStarted(interceptContext) { ctx ->
require(ctx.strategy.metadata.uniqueNames) {
"Checkpoint feature requires unique node names in the strategy metadata"
}
val checkpoint = ctx.feature.rollbackToLatestCheckpoint(ctx.context)
if (checkpoint != null) {
logger.info { "Restoring checkpoint: ${checkpoint.checkpointId} to node ${checkpoint.nodeId}" }
} else {
logger.info { "No checkpoint found, starting from the beginning" }
}
}
Now this code rolls the agent state back to the latest checkpoint created. Let's take the following loop into account so I can illustrate my confusion:
1. User sends message
2. Execute agent loop
3. Send result to user
Now, in the case of a user who has already gone through the agent loop at least once before, this means that the next time they send a message and we create a new instance of AIAgent with the Persistency feature installed, we're rolling back the agent state to the final node in the graph, because that was the last checkpoint that was created. That can't be right?
Unless I'm misunderstanding things here.
If there's any code examples of manually creating and retrieving checkpoints in a strategy graph as a means of managing the conversation history, it would be greatly appreciated, as this would increase my understanding of the process.Sam
09/11/2025, 12:20 PMMark Tkachenko
09/11/2025, 12:44 PMNow, in the case of a user who has already gone through the agent loop at least once before, this means that the next time they send a message and we create a new instance ofYeah, that’s considered a bug and I want to fix it in 0.5.0with theAIAgentfeature installed, we’re rolling back the agent state to the final node in the graph, because that was the last checkpoint that was created. That can’t be right?Persistency
Sam
09/11/2025, 12:54 PMMark Tkachenko
09/11/2025, 12:54 PMif that’s definitely what happensit is
Sam
09/11/2025, 12:55 PMenableAutomaticPersistency = true, this code:
pipeline.interceptBeforeAgentStarted(interceptContext) { ctx ->
require(ctx.strategy.metadata.uniqueNames) {
"Checkpoint feature requires unique node names in the strategy metadata"
}
val checkpoint = ctx.feature.rollbackToLatestCheckpoint(ctx.context)
if (checkpoint != null) {
<http://logger.info|logger.info> { "Restoring checkpoint: ${checkpoint.checkpointId} to node ${checkpoint.nodeId}" }
} else {
<http://logger.info|logger.info> { "No checkpoint found, starting from the beginning" }
}
}
runs every time the agent startsSam
09/11/2025, 12:55 PMSam
09/11/2025, 1:01 PM