workflows-py icon indicating copy to clipboard operation
workflows-py copied to clipboard

[Feature Request] Improve how state is shared between workflows

Open logan-markewich opened this issue 4 months ago • 0 comments

Today, each workflow is completely decoupled from another. And furthermore, the Context ensures each .run() is also isolated.

If you run a workflow inside another workflow, you end up with

  • two context objects
  • two states
  • two event streams

I think it'd be useful to explore a UX where we actually share information from an outer workflow to an inner workflow.

For example, here's a scenario

@step
async def run_some_step(self, ctx: Context[SomeState], ev: SomeEvent) -> OtherEvent:
  some_val = await ctx.store.get("some_val")
  inner_workflow = InnerWorkflow()
  
  handler = inner_workflow.run(some_val=some_val)
  async for inner_ev in handler.stream_events():
    ctx.write_event_to_stream(inner_ev)

  result = await handler
  await ctx.store.set("some_other_value", result)
  return OtherEvent()

Notice that

  1. Need to propagate events through outer context
  2. Need to pass any state from the outer state to the inner workflow
  3. Need to propagate any state changes from inner workflow to outer state

This gets infinitely more complicated (or even impossible?) if the inner workflow involves human-in-the-loop.

However, its also an option that maybe we don't share state, but if we don't, we should be principled and outline proper development practices.

logan-markewich avatar Jul 29 '25 22:07 logan-markewich