Prerequisites
Complete the Branch & Loop tutorial — the child workflow in this tutorial reuses that pattern.The child workflow
First, create a standalone implement-and-test workflow. This is a normal workflow that can run on its own or be invoked as a sub-workflow by a parent.implement-and-test.fabro
The parent workflow
Now create a parent workflow that delegates to the child:sub-workflow.fabro
The house node
Theimpl node has shape=house, which makes it a sub-workflow node. Instead of running an LLM or a script, it launches an entirely separate workflow engine to execute the child workflow file:
review node.
Sub-workflow attributes
| Attribute | Description |
|---|---|
stack.child_workflow | Path to the child workflow file (resolved relative to the parent). Preferred. |
stack.child_dotfile | Backward-compatible alias for stack.child_workflow. |
stack.child_dot_source | Inline child DOT source (alternative to child_workflow) |
manager.max_cycles | Safety limit on poll cycles before the child is cancelled (default: 1000) |
manager.poll_interval | How often to check for completion or stop conditions (default: 45s) |
manager.stop_condition | Condition expression that, when true, cancels the child early |
stack.child_workflow when you want to reuse the child workflow across multiple parents. Use stack.child_dot_source for one-off child workflows that are specific to the parent.
Context flow
Context flows bidirectionally between parent and child:- Parent → child: The child receives a clone of the parent’s context. In this example, the
plannode writesplan.mdto disk and the child’simplementnode reads it. - Child → parent: When the child finishes, any context values it added or changed are merged back into the parent. The
reviewnode sees the results of the child’s work.
Stop conditions
For long-running child workflows, you can set a stop condition that cancels the child early based on the parent’s context:manager.poll_interval (default 45 seconds). On each poll, it evaluates the stop condition against the current context. If the condition is true, the child is cancelled and the parent continues. This is useful when an external process (another branch, a webhook, a human gate) signals that the child’s work is no longer needed.
When to use sub-workflows
Sub-workflows are most valuable when:- Reusability — the same child workflow is used by multiple parents (e.g., a standard test-and-fix loop, a deploy pipeline, a review checklist)
- Encapsulation — the child runs its own engine with isolated logs and checkpoints, keeping the parent’s execution trace clean
- Supervisor patterns — the parent needs to monitor or cancel a complex child process based on external conditions
What you’ve learned
- Sub-workflow nodes (
shape=house) run a child workflow inside a parent stack.child_workflowreferences an external workflow file for reuse (stack.child_dotfileis also supported for backward compatibility)- Context flows from parent to child and back via diff merging
manager.max_cyclesprevents runaway child workflowsmanager.stop_conditioncancels the child when an external signal arrives