> ## Documentation Index
> Fetch the complete documentation index at: https://docs.voxworks.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Sub-Flows

> Sub-Flows are modular conversation branches that can be invoked from any flow. They enable reusable, maintainable conversation designs.

## What are Sub-Flows?

A Sub-Flow is a self-contained conversation module that:

* Can be called from the Main Flow or other Sub-Flows
* Executes its own sequence of steps
* Returns control to the parent flow when complete

***

## Why Use Sub-Flows?

Sub-Flows help you:

| Benefit             | Description                                                 |
| ------------------- | ----------------------------------------------------------- |
| **Reusability**     | Use the same conversation module in multiple places         |
| **Maintainability** | Update one sub-flow instead of duplicating changes          |
| **Organization**    | Keep complex flows manageable by breaking them into modules |
| **Consistency**     | Ensure the same process is followed every time              |

***

## How Sub-Flows Work

When a Flow Step invokes a sub-flow:

1. **Context saved** — The parent flow's position is pushed to the flow stack
2. **Sub-flow starts** — Execution begins at step 0 of the sub-flow
3. **Sub-flow runs** — Steps execute until an end condition
4. **Return** — Control returns to the parent flow with a **success** or **failure** result
5. **Continue** — The parent flow evaluates the result and continues based on its conditions

```text theme={null}
Main Flow
   Step 0: Opening
   Step 1: Qualify
   Step 2: [Flow Step → Booking Sub-Flow]
              Booking Step 0: Check availability
              Booking Step 1: Confirm time
              Booking Step 2: Book appointment → Return
   Step 3: Confirm and close (continues after sub-flow returns)
```

***

## Sub-Flow Exit Conditions

Sub-Flows return to their parent with either a **success** or **failure** result:

| Exit Type   | Description                            | Parent Condition                                  |
| ----------- | -------------------------------------- | ------------------------------------------------- |
| **Success** | Sub-flow completes its objective       | Triggers the `Success (true)` condition in parent |
| **Failure** | Sub-flow cannot complete its objective | Triggers the `Otherwise` condition in parent      |

The parent Flow Step uses these conditions to route the conversation appropriately:

```text theme={null}
Flow Step: Enter Booking Sub-Flow
   Condition: true (success)
   → Next: confirmation_step
   → Script: "Great, you're all booked in!"

   Condition: false (failure)
   → Next: alternative_step
   → Script: "Sorry the booking system isn't working."
```

This pattern allows you to handle both outcomes gracefully in the parent flow.

***

## Common Sub-Flow Patterns

### Appointment Booking

```text theme={null}
Booking Sub-Flow
   Step 0: Check calendar availability (Tool)
   Step 1: "I have availability on [Calendar - Availability - Spoken]. Which works best?"
   Step 2: Confirm selection
   Step 3: Create booking (Tool)
   Step 4: Return with booking confirmation
```

### Information Collection

```text theme={null}
Contact Info Sub-Flow
   Step 0: "What's the best email to reach you?"
   Step 1: Validate email (Function)
   Step 2: "And your phone number?"
   Step 3: Validate phone (Function)
   Step 4: Return with collected data
```

### Objection Handling

```text theme={null}
Objection Sub-Flow
   Step 0: "I understand your concern. Can you tell me more?"
   Step 1: Address specific objection
   Step 2: "Does that help address your concern?"
   Step 3: Return based on user response
```

***

## Best Practices

1. **Keep sub-flows focused** — Each should do one thing well
2. **Name clearly** — Use descriptive names like "Booking Flow" or "Email Collection"
3. **Document inputs/outputs** — Make it clear what data is expected
4. **Handle failures gracefully** — Include conditions for unsuccessful outcomes
5. **Test independently** — Verify sub-flows work before integrating

***

## Next Steps

* [Flow Steps](/flows/steps-flow) — Learn how to invoke sub-flows
* [Variables](/flows/variables) — Learn about global variables
* [Main Flows](/flows/flows-main) — Design your primary conversation path
