


























在工作流执行中经常会有共享状态的处理,llama-agents 通过context 的storage 可以存储信息,默认是没有类型的,当然也可以添加状态
class MyWorkflow(Workflow):
@step
async def my_step(self, ctx: Context, ev: StartEvent) -> StopEvent:
current_count = await ctx.store.get("count", default=0)
current_count += 1
await ctx.store.set("count", current_count)
return StopEvent()
实际上就是对于context 的持久化处理
workflow = MyWorkflow()
ctx = Context(workflow)
handler = workflow.run(ctx=ctx)
result = await handler
# Optional: save the ctx somewhere and restore
# ctx_dict = ctx.to_dict()
# ctx = Context.from_dict(workflow, ctx_dict)
# continue with next run
handler = workflow.run(ctx=ctx)
result = await handler
状态参数对于workflow 的运行是比较重要的东西,使用好比较方便
https://developers.llamaindex.ai/python/llamaagents/workflows/managing_state/
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。