Hello Logan, i'm not trying to stop in the middle of a step.
Following the docs, i have broken the user interaction in 2 steps: the first one emits the input request event, the second one receives the response event.
This is my workflow:
class ChecklistWorkflow(Workflow):
@step
async def start(self, ctx: Context, ev: StartEvent) -> Step2TriggerEvent:
await ctx.set("form_data", ev.form_data)
await ctx.set("client_name", ev.client_name)
return Step2Event()
@step
async def step_2(
self, ctx: Context, ev: Step2TriggerEvent | Step2ResumeEvent
) -> Union[UserInputRequestEvent, TaskCompletedEvent]:
form_data = await ctx.get("form_data")
client_name = await ctx.get("client_name")
result = do_something()
if result["action"] == "USER_CLARIFICATION":
return UserInputRequestEvent(prefix="", questions=result["questions"])
elif result["action"] == "FINAL_ANSWER":
return TaskCompletedEvent()
@step
async def step_3(
self, ctx: Context, ev: UserInputResponseEvent | TaskCompletedEvent
) -> Step2ResumeEvent | StopEvent:
"""Either process human response or end of workflow"""
if isinstance(ev, UserInputResponseEvent):
print(f"Resuming from user input: {ev.response}")
await ctx.set("user_response", ev.response)
return Step2ResumeEvent() # Back to step 2 to continue the task
elif isinstance(ev, TaskCompletedEvent):
print(f"Checklist completed: {ev.checklist}")
return StopEvent(result=ev.checklist) # Task completed, finishing workflow
This is working fine. Then i'm intercepting the HITL event as suggested in the docs:
handler = wflow_ckptr.run(form_data=form_data, client_name="RecargaPay")
async for event in handler.stream_events():
if isinstance(event, UserClarificationRequestEvent):
break