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’s
.run()executes with the prepared input (chained from the previous step) - Session state is deep-copied into the inner workflow and merged back after execution
- 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
| Method | Syntax | When to use |
|---|---|---|
Explicit Step wrapper | Step(name="research", workflow=inner_workflow) | Custom step name, clarity |
| Auto-wrap | steps=[inner_workflow] | Concise shorthand (uses the workflow’s name as step name) |
auto_wrap.py
Inner workflows and primitives
An inner workflow can use the same primitives and combinations as any top-level workflow in Agno: agents, executors, nestedSteps, Condition, Loop, Router, and Parallel, mixed however your pipeline needs.
The basic example uses agent and executor steps inside the inner workflow. Deep nesting shows multiple levels with Parallel and sub-workflows.
| Primitive | Role |
|---|---|
Condition | Branch on a boolean evaluator |
Loop | Repeat steps until an end condition or max iterations |
Router | Choose a branch from a selector |
Parallel | Run branches concurrently |
Deep Nesting
Workflows can be nested multiple levels deep. Each level runs its own sub-workflows independently.deeply_nested.py
Streaming Events
When streaming, inner workflow events bubble up with anested_depth field. Use this to distinguish inner vs. outer events.
| Field | Description |
|---|---|
nested_depth | 0 for outer workflow, 1 for first-level inner, 2 for deeper nesting |
workflow_id | Unique ID of the workflow that emitted the event |
workflow_name | Name of the workflow that emitted the event |
event_inspection.py
Developer Resources
- Nested workflow example
- Auto-wrap example
- Event inspection example
- With Condition
- With Loop
- With Router
- Deep nesting (3 levels)