How does Koog handle persistence and migrations? W...
# koog-agentic-framework
a
How does Koog handle persistence and migrations? We can persist a long running session, but we might have topology changes in the graph.
a
Hi Arjan, persistence in koog's agent graph is designed to work for a fixed graph workflow. We did not consider the use case of changing the graph between persisted runs because it does not make sence for arbitrary updates in the graph. That said, you actually can change the graph in-between two runs: while we cannot give correctness guarantees in that case, it might work for your specific case. Specifically, if the last checkpoint saved by the previous run points to a node which is present in the new graph, the execution will continue from that point (otherwise, you'll get an error). So, in general I would not recommend changing the graph, but it could be viable in some very specific cases.
a
It does make sense because people don’t write perfect code. If you have a session spanning months it makes sense to have some idea of migrations. Besides that, business requirements change. But it is probably solvable with defensive programming in a way
v
@Arjan van Wieringen thanks for your question. Migration mechanisms and policies might vary drastically depending on your infrastructure. Hence, for now it’s much easier to just perform a proper DB migration (ex: with Flyway or with any other tool) and some sort of rolling (or graceful) update of your services. Koog allows you to set a specific PersistenceStorageProvider pointing to your database. For example, you can save checkpoints from the agents V1 to
agent_checkpoints_v1
postgres database, and then create a table
agent_checkpoints_v2
for the period of migration. You should then make sure that there’s a process in place that makes sure that until all checkpoints from
agent_checkpoints_v1
are “tombstone” (
nodeFinish
) — you are still migrating your service (first — finish all unfinished agents of V1 architecture, then — switch to V2). Though, if it’s possible to map tables (probably with losing some intermediate nodes or steps) — you are also free to do so with your DB migrations (remap nodes and checkpoints from
agent_checkpoints_v1
to
agent_checkpoints_v2
where possible — and just drop nodes that don’t have a clear mapping). Again, it will only work if your system doesn’t produce side-effects (if it does — you’ll have to first checkpoint back in time using
RollbackToolRegistry
to the latest node that has a clear mapping — and then perform the mapping). You can do it using a separate AWS lambda for migrations that finishes all unfinished agents, or you can do asyncronous rolling updates, you can perform mappings and continue agents from approximately where they stopped, or you can just drop the work completely. There are so many things that are more related to your infrastructure than they are to the agents themselves. That is why for now we don’t provide migrations out-of-the-box, as it’s something external that we can’t control within the framework.
first — finish all unfinished agents of V1 architecture, then — switch to V2
this would, of course, require having old version of agent strategy (V1) still available in your codebase so that you can still execute it.
a
Awesome! Thanks for the explanation
kodee loving 1