Skip to content

[Feature Request] Improve how state is shared between workflows #37

@logan-markewich

Description

@logan-markewich

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions