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

# Execute Workflow

> Run another workflow inside your workflow to reuse logic and keep things organized.

The Execute Workflow task lets you run another workflow (called a sub-workflow) inside your main workflow. Use it to break complex automations into smaller, reusable pieces that are easier to build, test, and maintain.

## Key Capabilities

<CardGroup cols={2}>
  <Card title="Reusable Pieces" icon="diagram-project">
    Build once, use in multiple workflows.
  </Card>

  <Card title="Pass Data In and Out" icon="arrows-left-right">
    Send data to the sub-workflow and get results back.
  </Card>

  <Card title="Isolated Execution" icon="box">
    Sub-workflows run on their own, making them easier to test and debug.
  </Card>

  <Card title="Better Organization" icon="folder-tree">
    Keep complex workflows manageable by splitting them into parts.
  </Card>
</CardGroup>

## When to Use It

Use Execute Workflow when you want to:

* Reuse the same logic across multiple workflows
* Break a complex workflow into smaller, manageable pieces
* Let different team members work on different parts
* Test pieces of your automation independently

<Note>
  Execute Workflow is for running a separate workflow inside your workflow. For simple yes/no routing within a single workflow, use [Decision Agent](/tasks/agent/decision-agent) instead.
</Note>

## Requirements

Before you can use a workflow as a sub-workflow, it must meet these requirements:

| Requirement                        | Why                                                                                                                                  |
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| **Must be activated**              | Only active workflows can be called as sub-workflows                                                                                 |
| **Same workspace**                 | The sub-workflow must be in the same workspace as the parent                                                                         |
| **No human tasks**                 | Sub-workflows can't contain Human Review, Human Decision Agent, or Opus Human Task—they run automatically without waiting for people |
| **Has inputs and outputs defined** | The sub-workflow needs Workflow Input and Workflow Output tasks so data can flow in and out                                          |

## How to Add Execute Workflow

<Steps>
  <Step title="Create your sub-workflow first">
    Build the workflow you want to reuse:

    * Add a Workflow Input task with the data it needs
    * Add your processing logic
    * Add a Workflow Output task with the results to return
    * Make sure there are no human tasks
  </Step>

  <Step title="Activate the sub-workflow">
    Test it thoroughly in preview mode, then activate it. Sub-workflows must be active before they can be called.
  </Step>

  <Step title="Add Execute Workflow to your parent workflow">
    Drag an Execute Workflow task into your main workflow where you need to call the sub-workflow.
  </Step>

  <Step title="Select the sub-workflow">
    Choose the sub-workflow from the dropdown. Only **active** workflows in the **same workspace** that **don't contain human tasks** (Human Review, Human Decision Agent, or Opus Human Task) will appear.

    <Tip>
      **Need human reviews, tasks, or decisions?** Put them in the parent workflow, not the sub-workflow. Let the sub-workflow do its processing, then review the outputs after it finishes.
    </Tip>

    <Warning>
      **Avoid loops:** Make sure the sub-workflow doesn't call back to the parent workflow (directly or through other workflows). This creates an infinite loop that will never finish.

      Opus has built-in guardrails to detect and prevent this.
    </Warning>
  </Step>

  <Step title="Map the inputs">
    The sub-workflow's inputs are automatically shown. Connect variables from your parent workflow to each input.

    <Note>
      The inputs and outputs come from the sub-workflow itself. To change them, edit the sub-workflow directly.
    </Note>
  </Step>

  <Step title="Use the outputs">
    The sub-workflow's outputs become available in your parent workflow. Connect them to later tasks.
  </Step>

  <Step title="Test it">
    Run a preview to make sure data flows correctly between the parent and sub-workflow.
  </Step>
</Steps>

## Tips for Better Results

<AccordionGroup>
  <Accordion title="Keep sub-workflows focused">
    Each sub-workflow should do one thing well:

    * Easier to test and debug
    * More reusable across different workflows
    * Simpler to understand and maintain
  </Accordion>

  <Accordion title="Test sub-workflows on their own first">
    Before using a sub-workflow in a parent:

    * Run it with test data in preview mode
    * Check that outputs are correct
    * Make sure it handles edge cases
  </Accordion>

  <Accordion title="Don't nest too deep">
    Avoid sub-workflows that call sub-workflows that call sub-workflows:

    * Hard to debug when something goes wrong
    * Increases total run time
    * Keep it to 2-3 levels maximum
  </Accordion>

  <Accordion title="Handle errors gracefully">
    Design sub-workflows to return useful information when things go wrong:

    * Include a status output (success/failure)
    * Return error details so the parent can decide what to do
  </Accordion>
</AccordionGroup>

## Related

<CardGroup cols={2}>
  <Card title="Workflows" icon="diagram-project" href="/guides/workflows">
    Learn how workflows work.
  </Card>

  <Card title="Builder" icon="hammer" href="/guides/builder">
    Master the workflow design environment.
  </Card>

  <Card title="Decision Agent" icon="code-branch" href="/tasks/agent/decision-agent">
    Route your workflow based on conditions.
  </Card>

  <Card title="Opus Code" icon="code" href="/tasks/agent/opus-code">
    Write custom code for simple transformations.
  </Card>
</CardGroup>
