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
inner_workflow as its first step. The inner workflow’s output flows into the writing_phase step.
How It Works
- The outer workflow reaches a step with
workflow=inner_workflow - The inner workflow executes with
.run()or.arun()and receives the prepared input - The parent passes its session ID, user ID, and current session state into the nested run
- The inner workflow’s output is converted to a
StepOutputwithstep_type=StepType.WORKFLOW - 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 anested_depth field. Use this to distinguish inner vs. outer events.
Using
outer_workflow from the deep-nesting example:
Developer Resources
- Nested workflow example
- Auto-wrap example
- Event inspection example
- With Condition
- With Loop
- With Router
- Deep nesting (3 levels)