Find answers from the community

Updated 3 months ago

Are workflows meant to be created on each request or reused across requests

Hello, just started trying to implement workflows and have a quick question.

In the context of a web server, are workflows meant to be created on each request or are we supposed to create one instance of a workflow and call workflow.run(…) on each request?
L
g
2 comments
Up to you!

By default, workflows are stateless, unless you decide to persist the context between runs

Plain Text
from llama_index.core.workflow.context_serializers import JsonSerializer, JsonPicklerSerializer
from llama_index.core.workflow import Context

# stateless
result = await workflow.run()

# saving the state
handler = workflow.run()
result = await handler

ctx_data = handler.ctx.to_dict(serializer=JsonPicklerSerializer())

# reloading the state
ctx = Context.from_dict(workflow, ctx_data, serializer=JsonPicklerSerializer())
result = await workflow.run(ctx=ctx)
Great thanks, Logan. That clarifies it
Add a reply
Sign up and join the conversation on Discord