|
1 | 1 | --- |
2 | | -title: Workflow |
| 2 | +title: Workflow Block |
| 3 | +description: Run another workflow inside the current flow |
3 | 4 | --- |
4 | 5 |
|
5 | 6 | import { Callout } from 'fumadocs-ui/components/callout' |
6 | | -import { Step, Steps } from 'fumadocs-ui/components/steps' |
7 | | -import { Tab, Tabs } from 'fumadocs-ui/components/tabs' |
8 | 7 | import { Image } from '@/components/ui/image' |
9 | 8 |
|
10 | | -The Workflow block allows you to execute other workflows as reusable components within your current workflow. This enables modular design, code reuse, and the creation of complex nested workflows that can be composed from smaller, focused workflows. |
| 9 | +## What It Does |
11 | 10 |
|
12 | | -<div className="flex justify-center"> |
| 11 | +<div className='flex justify-center my-6'> |
13 | 12 | <Image |
14 | | - src="/static/blocks/workflow.png" |
15 | | - alt="Workflow Block" |
16 | | - width={500} |
17 | | - height={350} |
18 | | - className="my-6" |
| 13 | + src='/static/blocks/workflow.png' |
| 14 | + alt='Workflow block configuration' |
| 15 | + width={400} |
| 16 | + height={280} |
| 17 | + className='rounded-xl border border-border shadow-sm' |
19 | 18 | /> |
20 | 19 | </div> |
21 | 20 |
|
22 | | -<Callout type="info"> |
23 | | - Workflow blocks enable modular design by allowing you to compose complex workflows from smaller, reusable components. |
24 | | -</Callout> |
25 | | - |
26 | | -## Overview |
27 | | - |
28 | | -The Workflow block serves as a bridge between workflows, enabling you to: |
29 | | - |
30 | | -<Steps> |
31 | | - <Step> |
32 | | - <strong>Reuse existing workflows</strong>: Execute previously created workflows as components within new workflows |
33 | | - </Step> |
34 | | - <Step> |
35 | | - <strong>Create modular designs</strong>: Break down complex processes into smaller, manageable workflows |
36 | | - </Step> |
37 | | - <Step> |
38 | | - <strong>Maintain separation of concerns</strong>: Keep different business logic isolated in separate workflows |
39 | | - </Step> |
40 | | - <Step> |
41 | | - <strong>Enable team collaboration</strong>: Share and reuse workflows across different projects and team members |
42 | | - </Step> |
43 | | -</Steps> |
44 | | - |
45 | | -## How It Works |
46 | | - |
47 | | -The Workflow block: |
48 | | - |
49 | | -1. Takes a reference to another workflow in your workspace |
50 | | -2. Passes input data from the current workflow to the child workflow (available via start.input) |
51 | | -3. Executes the child workflow in an isolated context |
52 | | -4. Returns the result back to the parent workflow for further processing |
| 21 | +Drop a Workflow block when you want to call a child workflow as part of a larger flow. The block runs the latest deployed version of that workflow, waits for it to finish, and then continues with the parent. |
53 | 22 |
|
54 | | -## Configuration Options |
| 23 | +## Configure It |
55 | 24 |
|
56 | | -### Workflow Selection |
| 25 | +1. **Pick a workflow** from the dropdown (self-references are blocked to prevent loops). |
| 26 | +2. **Map inputs**: If the child workflow has an Input Form trigger, you’ll see each field and can connect parent variables. The mapped values are what the child receives. |
| 27 | +3. **Outputs**: After the child finishes, the block exposes: |
| 28 | + - `result` – the child workflow’s final response |
| 29 | + - `success` – whether it ran without errors |
| 30 | + - `error` – message when the run fails |
57 | 31 |
|
58 | | -Choose which workflow to execute from a dropdown list of available workflows in your workspace. The list includes: |
| 32 | +## Execution Notes |
59 | 33 |
|
60 | | -- All workflows you have access to in the current workspace |
61 | | -- Workflows shared with you by other team members |
62 | | -- Both enabled and disabled workflows (though only enabled workflows can be executed) |
| 34 | +- Child workflows run in the same workspace context, so environment variables and tools carry over. |
| 35 | +- The block uses deployment versioning: any API, schedule, webhook, manual, or chat execution calls the deployed snapshot. Redeploy the child when you change it. |
| 36 | +- If the child fails, the block raises an error unless you handle it downstream. |
63 | 37 |
|
64 | | - |
65 | | -### Execution Context |
66 | | - |
67 | | -The child workflow executes with: |
68 | | - |
69 | | -- Its own isolated execution context |
70 | | -- Access to the same workspace resources (API keys, environment variables) |
71 | | -- Proper workspace membership and permission checks |
72 | | -- Nested tracespan in the execution log |
73 | | - |
74 | | -<Callout type="warning"> |
75 | | - **Cycle Detection**: The system automatically detects and prevents circular dependencies between workflows to avoid infinite loops. |
| 38 | +<Callout> |
| 39 | +Keep child workflows focused. Small, reusable flows make it easier to combine them without creating deep nesting. |
76 | 40 | </Callout> |
77 | | - |
78 | | -## Inputs and Outputs |
79 | | - |
80 | | -<Tabs items={['Configuration', 'Variables', 'Results']}> |
81 | | - <Tab> |
82 | | - <ul className="list-disc space-y-2 pl-6"> |
83 | | - <li> |
84 | | - <strong>Workflow Selection</strong>: Choose which workflow to execute |
85 | | - </li> |
86 | | - <li> |
87 | | - <strong>Input Data</strong>: Variable or block reference to pass to child workflow |
88 | | - </li> |
89 | | - <li> |
90 | | - <strong>Execution Context</strong>: Isolated environment with workspace resources |
91 | | - </li> |
92 | | - </ul> |
93 | | - </Tab> |
94 | | - <Tab> |
95 | | - <ul className="list-disc space-y-2 pl-6"> |
96 | | - <li> |
97 | | - <strong>workflow.success</strong>: Boolean indicating completion status |
98 | | - </li> |
99 | | - <li> |
100 | | - <strong>workflow.childWorkflowName</strong>: Name of executed child workflow |
101 | | - </li> |
102 | | - <li> |
103 | | - <strong>workflow.result</strong>: Result returned by the child workflow |
104 | | - </li> |
105 | | - <li> |
106 | | - <strong>workflow.error</strong>: Error details if workflow failed |
107 | | - </li> |
108 | | - </ul> |
109 | | - </Tab> |
110 | | - <Tab> |
111 | | - <ul className="list-disc space-y-2 pl-6"> |
112 | | - <li> |
113 | | - <strong>Workflow Response</strong>: Primary output from child workflow |
114 | | - </li> |
115 | | - <li> |
116 | | - <strong>Execution Status</strong>: Success status and error information |
117 | | - </li> |
118 | | - <li> |
119 | | - <strong>Access</strong>: Available in blocks after the workflow |
120 | | - </li> |
121 | | - </ul> |
122 | | - </Tab> |
123 | | -</Tabs> |
124 | | - |
125 | | -## Example Use Cases |
126 | | - |
127 | | -### Modular Customer Onboarding |
128 | | - |
129 | | -<div className="mb-4 rounded-md border p-4"> |
130 | | - <h4 className="font-medium">Scenario: Break down complex onboarding into reusable components</h4> |
131 | | - <ol className="list-decimal pl-5 text-sm"> |
132 | | - <li>Main workflow receives customer data</li> |
133 | | - <li>Workflow block executes validation workflow</li> |
134 | | - <li>Workflow block executes account setup workflow</li> |
135 | | - <li>Workflow block executes welcome email workflow</li> |
136 | | - </ol> |
137 | | -</div> |
138 | | - |
139 | | -### Microservice Architecture |
140 | | - |
141 | | -<div className="mb-4 rounded-md border p-4"> |
142 | | - <h4 className="font-medium">Scenario: Create independent service workflows</h4> |
143 | | - <ol className="list-decimal pl-5 text-sm"> |
144 | | - <li>Payment processing workflow handles transactions</li> |
145 | | - <li>Inventory management workflow updates stock</li> |
146 | | - <li>Notification workflow sends confirmations</li> |
147 | | - <li>Main workflow orchestrates all services</li> |
148 | | - </ol> |
149 | | -</div> |
150 | | - |
151 | | -### Conditional Processing |
152 | | - |
153 | | -<div className="mb-4 rounded-md border p-4"> |
154 | | - <h4 className="font-medium">Scenario: Execute different workflows based on conditions</h4> |
155 | | - <ol className="list-decimal pl-5 text-sm"> |
156 | | - <li>Condition block evaluates user type</li> |
157 | | - <li>Enterprise users → Complex approval workflow</li> |
158 | | - <li>Standard users → Simple approval workflow</li> |
159 | | - <li>Free users → Basic processing workflow</li> |
160 | | - </ol> |
161 | | -</div> |
162 | | - |
163 | | -## Best Practices |
164 | | - |
165 | | -- **Keep workflows focused**: Design child workflows to handle specific, well-defined tasks with clear inputs and outputs |
166 | | -- **Minimize nesting depth**: Avoid deeply nested workflow hierarchies for better maintainability and performance |
167 | | -- **Handle errors gracefully**: Implement proper error handling for child workflow failures and provide fallback mechanisms |
168 | | -- **Test independently**: Ensure child workflows can be tested and validated independently from parent workflows |
169 | | -- **Use semantic naming**: Give workflows descriptive names that clearly indicate their purpose and functionality |
0 commit comments