Behavior
- Executes the referenced flow from start to end
- Inherits all dynamic variables and context from the parent flow
- Preserves the caller’s context (phone number, conversation metadata, etc.)
- Waits for the sub-flow to complete before continuing to the next node in the main flow
- Supports arbitrary nesting depth (sub-flows within sub-flows)
- Automatically flattens during flow initialization for seamless execution
When to use
Use Sub Flow nodes when you want to:- Reuse common sequences across multiple flows (e.g., authentication, IVR menu trees)
- Organize complex logic into manageable, testable units
- Simplify maintenance by updating shared flows in one place
- Compose flows dynamically without duplicating node configurations
- Share context between flows (e.g., pass user data, authentication results, or preferences)
Configuration
| Parameter | Type | Required | Description |
|---|---|---|---|
flowId | string | Yes | The ID of the published flow to execute as a sub-flow |
How it works
Flow Resolution
During conversation initialization, the system performs automatic flow resolution:- Discovery — Scans the main flow for all
Sub Flownode references - Fetching — Retrieves the referenced flows from the database (iteratively, handling nested sub-flows)
- Flattening — Merges all sub-flow nodes and edges directly into the main flow
- Execution — The XState actor runs one unified, flat flow with no sub-flow overhead
Node Prefixing
When a sub-flow is embedded, all of its internal nodes are prefixed with theSub Flow node’s ID to ensure uniqueness. This allows:
- The same sub-flow to be embedded multiple times without ID collisions
- Deep nesting (sub-flow-of-sub-flow) with clear node identity chains
- Proper state tracking for each embedded instance
Example Prefixing
Agent Hydration
If a sub-flow containsAgent nodes, they are automatically discovered and hydrated during flow initialization. This means:
- Agent configurations are loaded for all nested agent nodes
- Tools, LLM settings, and RAG configurations are applied before the flow runs
- The flow sees all agent nodes—regardless of nesting—as part of the unified graph
Output handles
| Handle | Description |
|---|---|
| Complete | Sub-flow executed successfully and reached an end node — main flow continues to the next node |
| Error | Sub-flow encountered an error or reached an error state |
Limitations and considerations
Circular references are detected
Circular references are detected
The system prevents cycles during flow initialization. If flow A references flow B and flow B references flow A, the conversation will fail at startup with a clear error message. Plan your flow hierarchy to avoid circular dependencies.
Sub-flow must have intermediate nodes
Sub-flow must have intermediate nodes
A sub-flow cannot contain only
Start and End nodes—it must have at least one executable node (e.g., TTS, Agent, API Call). This ensures the flattened graph remains valid.Performance scales linearly with nesting
Performance scales linearly with nesting
Flow flattening is performed once at initialization time. Arbitrarily deep nesting (A → B → C → D) is supported and has minimal runtime overhead after flattening completes.
Published flows only
Published flows only
Only flows that are saved and published can be referenced by a
Sub Flow node. Unsaved drafts cannot be used.Variables are inherited, not isolated
Variables are inherited, not isolated
Sub-flows share the same variable context as the parent flow. Any variables set by a sub-flow are visible to subsequent nodes in the main flow. There is no variable scope isolation.
Use cases
Reusable authentication flow
Reusable authentication flow
Create a dedicated flow (e.g.,
authenticate-customer) that collects PIN, verifies it, and sets an authenticated flag. Embed this flow at the start of multiple customer-facing flows to ensure consistent authentication logic.Flow structure:Multi-tier IVR menu system
Multi-tier IVR menu system
Contextual handoff with AI agent
Contextual handoff with AI agent
Create a
pre-agent-context flow that gathers caller information (order number, issue type) and formats it for the agent. Embed this before an Agent node to ensure agents always receive pre-qualified context.Flow structure:After-hours routing with fallback
After-hours routing with fallback
Create a dedicated
after-hours-routing flow that checks the time and routes to voicemail or an external service. Embed this at the end of your main flow to provide consistent off-hours behavior.Flow structure:Multi-language support
Multi-language support
Create language-specific flows (
flow-english, flow-spanish, flow-french) with the same structure but localized audio/text. Use a Switch node on caller.language to embed the appropriate flow.Flow structure:Technical details
Flow Flattening Algorithm
Sub-flows are resolved and flattened during conversation initialization (before the XState actor starts). The process:- Scope-bound fetch — Only flows referenced in the current conversation’s main flow are fetched; this prevents unnecessary database queries
- Recursive resolution — Nested sub-flows are discovered and fetched in an iterative process until no new flows are found
- Edge rewriting — Incoming and outgoing edges are re-routed to maintain flow continuity:
- Main flow edges targeting the sub-flow node now target the sub-flow’s first real node
- Sub-flow exit edges now target the main flow’s original target
- ID prefixing — All sub-flow nodes are prefixed to avoid collisions
- Flattened result — A single, unified
FlowSchemawith noSub Flownodes is passed to the XState actor
Error Handling
The system throws an error at initialization time if:- A referenced flow does not exist in the database
- A flow is missing its
flowIdconfiguration - A cycle is detected (A → B → A)
- A sub-flow is missing its
StartorEndnode - A sub-flow contains only
StartandEndwith no intermediate nodes