Hi there, just wondering if there's any documentat...
# koog-agentic-framework
s
Hi there, just wondering if there's any documentation on managing conversation history within nodes in a strategy graph using the
Persistency
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 appreciated
m
managing conversation history within nodes in a strategy graph using the
Persistency
feature
Hello! 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.
🙌 1
s
Sorry I don't think I phrased my question correctly. For example let's say I have
enableAutomaticPersistency = 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
Copy code
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
:
Copy 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) {
        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.
Hopefully that makes sense 😄
m
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?
Yeah, that’s considered a bug and I want to fix it in 0.5.0
s
Well, I don't know for sure if that's definitely what happens, it's just that's what would seem would happen. So I thought it best to reach out
m
if that’s definitely what happens
it is
s
I mean this doesn't even involve
enableAutomaticPersistency = true
, this code:
Copy 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 starts
but that's good then, I was getting very confused haha
is there an official bug report for this?