|
1 | 1 | --- |
2 | | -title: Flow Logic |
| 2 | +title: Orchestration Logic |
| 3 | +description: How to arrange, nest, or reuse nodes when building a Workflow or Chatflow |
3 | 4 | --- |
4 | 5 |
|
5 | | - |
6 | | -## Serial vs. Parallel execution |
| 6 | +## Serial and Parallel Execution |
7 | 7 |
|
8 | 8 | <Frame> |
9 | | -  |
| 9 | +  |
10 | 10 | </Frame> |
11 | 11 |
|
12 | | -Flows execute differently depending on how you connect the nodes. |
13 | | - |
14 | | -When you connect nodes one after another, they execute in sequence. Each node waits for the previous one to finish before starting. Each node may use variables from any node that ran before it in the chain. |
15 | | - |
16 | | -<Frame> |
17 | | -  |
18 | | -</Frame> |
19 | | - |
20 | | -When you connect multiple nodes to the same starting node, they all run at the same time. Nodes may not reference parallel node outputs. |
21 | | - |
22 | | -<Frame> |
23 | | -  |
24 | | -</Frame> |
| 12 | +When building a workflow, you can arrange nodes in series or in parallel: |
25 | 13 |
|
26 | | -<Note> |
27 | | -You can have a maximum of 10 parallel branches from one node, and up to 3 levels of nested parallel structures. |
28 | | -</Note> |
| 14 | +- **In series**, nodes run one after another. Each node can read variables from any node earlier in the chain. |
29 | 15 |
|
30 | | -## Variable access |
| 16 | +- **In parallel**, nodes run at the same time. They can't read each other's variables, but where parallel branches converge, the downstream node can read from all of them. |
31 | 17 |
|
32 | | -In serial flows, nodes can access variables from any previous node in the chain. |
| 18 | +<Info> |
| 19 | + A single execution path supports up to 50 nodes. Self-hosted deployments can change this limit with the `MAX_TREE_DEPTH` environment variable. |
| 20 | +</Info> |
33 | 21 |
|
34 | | -In parallel flows, nodes can access variables from nodes that ran before the parallel split, but they cannot access variables from other parallel nodes since they're running simultaneously. |
| 22 | +## Node Reuse |
35 | 23 |
|
36 | | -After parallel branches finish, downstream nodes can access variables from all the parallel outputs. |
| 24 | +All nodes except User Input can be copied and pasted within the same workflow, across workflows, or across Dify instances, though there might be compatibility issues between Dify versions. |
37 | 25 |
|
38 | | -## Answer node streaming |
| 26 | +When you paste a node, its configuration moves with it, but the availability of anything that depends on the surrounding environment is re-evaluated at the destination: |
39 | 27 |
|
40 | | -Answer nodes handle parallel outputs differently. When an Answer node references variables from multiple parallel branches, it streams content progressively: |
| 28 | +- **Workflow-specific resources**, such as variables |
| 29 | +- **Workspace-specific resources**, such as tools, plugins, and knowledge bases |
41 | 30 |
|
42 | | -- Content streams up to the first unresolved variable |
43 | | -- Once that variable's node completes, streaming continues to the next unresolved variable |
44 | | -- The order of variables in the Answer node determines the streaming sequence, not the node execution order |
| 31 | +## Iteration and Loop |
45 | 32 |
|
46 | | -For example, in a flow where `Node A -> Node B -> Answer` with the Answer containing `{{B}}` then `{{A}}`, the Answer will wait for Node B before streaming any content, even if Node A completes first. |
| 33 | +For nodes that should run multiple times (once per item in a list or until a condition is met), place them inside an [Iteration](/en/use-dify/nodes/iteration) or [Loop](/en/use-dify/nodes/loop) node. |
0 commit comments