Find answers from the community

Updated 4 months ago

Enabling Context Persistence Across Multiple Workflow Runs

At a glance

The community member posted a question about how to enable Context to persist over multiple runs of the same workflow. In the comments, another community member provided a solution involving serializing the context using the JsonSerializer or JsonPickleSerializer, and then resuming the workflow at a later point by deserializing the context. There is no explicitly marked answer, but the provided code snippet demonstrates how to persist the context across multiple workflow runs.

Hey all, how do we enable Context to persist over multiple runs of the same workflow?
L
D
2 comments
Plain Text
handler = workflow.run(...)
result = await handler

handler = workflow.run(ctx=handler.ctx, ....)
result = await handler


You can also serialize the context (the pickling-serializer is opt in, in case you are storing non-json serializable objects in the context)

Plain Text
from llama_index.core.workflow.context_serializers import JsonSerializer, JsonPickleSerializer

# serialize
serialized_context = handler.ctx.to_dict(serializer=JsonSerializer())

# resume at a later point
ctx = Context.from_dict(serialized_context, serializer=JsonSerializer())
Add a reply
Sign up and join the conversation on Discord