-
For example, I have a step that produces event Because I always thought that whenever step is called, it always consumes event. Like Because in the docs there were examples on:
But all of those steps were fully consumed events. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Yes, multiple steps in a workflow can independently process the same event without conflict. The To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other |
Beta Was this translation helpful? Give feedback.
-
Yes, you can do this without problems. Here is an example: from typing import Optional
from llama_index.core.workflow import Context, Event, StartEvent, StopEvent, Workflow, step
import asyncio
from pprint import pprint
class ProcessEvent(Event):
start: StartEvent
class ResultA(Event):
process: ProcessEvent
class ResultB(Event):
process: ProcessEvent
class MyStopEvent(StopEvent):
a: ResultA
b: ResultB
class MyWorkflow(Workflow):
@step
async def start(self, ev: StartEvent) -> ProcessEvent:
return ProcessEvent(start=ev)
@step
async def make_result_a(self, ev: ProcessEvent) -> ResultA:
return ResultA(process=ev)
@step
async def make_result_b(self, ev: ProcessEvent) -> ResultB:
return ResultB(process=ev)
@step
async def finish(self, ctx: Context, ev: ResultA | ResultB) -> Optional[MyStopEvent]:
events = ctx.collect_events(ev, [ResultA, ResultB])
if not events:
return None
result_a, result_b = events
return MyStopEvent(a=result_a, b=result_b)
if __name__ == '__main__':
async def main():
workflow = MyWorkflow(verbose=True)
result = await workflow.run()
pprint(result)
asyncio.run(main()) This will produce output:
As you can see |
Beta Was this translation helpful? Give feedback.
Yes, you can do this without problems.
Here is an example: