Skip to main content
Pass a Workflow as a step inside another Workflow. The inner workflow runs as a single step in the outer workflow, with output chained to the next step.

Basic Example

nested_workflow.py
The outer workflow runs inner_workflow as its first step. The inner workflow’s output flows into the writing_phase step.

How It Works

  1. The outer workflow reaches a step with workflow=inner_workflow
  2. The inner workflow executes with .run() or .arun() and receives the prepared input
  3. The parent passes its session ID, user ID, and current session state into the nested run
  4. The inner workflow’s output is converted to a StepOutput with step_type=StepType.WORKFLOW
  5. Execution continues to the next step in the outer workflow

Two Ways to Declare

Using inner_workflow from the basic example:

Inner Workflows and Primitives

An inner workflow can use the same primitives and combinations as a top-level workflow: agents, teams, functions, Step, Steps, Condition, Loop, Router, Parallel, and other nested workflows. The basic example uses agent and executor steps inside the inner workflow. Deep nesting shows multiple levels with Parallel and sub-workflows.

Deep Nesting

Workflows can be nested to a maximum depth of 10. Nested runs keep their own workflow and run IDs while sharing the parent’s session context for the call.
deeply_nested.py

Streaming Events

When streaming, inner workflow events bubble up with a nested_depth field. Use this to distinguish inner vs. outer events. Using outer_workflow from the deep-nesting example:

Developer Resources

Reference

For complete API documentation, see Step Reference.