docs: loop (#629)

* docs: loop

* update: details

* update: titles

* update: pic alt.md

* Update Loop translation

---------

Co-authored-by: Hanqing Zhao <sherry9277@gmail.com>
This commit is contained in:
Jing Y.
2025-03-18 23:10:26 +08:00
committed by GitHub
parent 921fcc7072
commit 873e5ecf6c
10 changed files with 261 additions and 5 deletions
+1
View File
@@ -53,6 +53,7 @@
* [HTTP Request](guides/workflow/node/http-request.md)
* [Agent](guides/workflow/node/agent.md)
* [Tools](guides/workflow/node/tools.md)
* [Loop](guides/workflow/node/loop.md)
* [Shortcut Key](guides/workflow/shortcut-key.md)
* [Orchestrate Node](guides/workflow/orchestrate-node.md)
* [File Upload](guides/workflow/file-upload.md)
+1 -1
View File
@@ -4,4 +4,4 @@
### Core Nodes
<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><a href="start.md"><strong>Start</strong></a></td><td>Defines the initial parameters for starting a workflow process.</td><td></td></tr><tr><td><a href="end.md"><strong>End</strong></a></td><td>Defines the final output content for ending a workflow process.</td><td></td></tr><tr><td><a href="answer.md"><strong>Answer</strong></a></td><td>Defines the response content in a Chatflow process.</td><td></td></tr><tr><td><a href="llm.md"><strong>Large Language Model (LLM)</strong></a></td><td>Calls a large language model to answer questions or process natural language.</td><td></td></tr><tr><td><a href="knowledge_retrieval.md"><strong>Knowledge Retrieval</strong></a></td><td>Retrieves text content related to user questions from a knowledge base, which can serve as context for downstream LLM nodes.</td><td></td></tr><tr><td><a href="question-classifier.md"><strong>Question Classifier</strong></a></td><td>By defining classification descriptions, the LLM can select the matching classification based on user input.</td><td></td></tr><tr><td><a href="ifelse.md"><strong>IF/ELSE</strong></a></td><td>Allows you to split the workflow into two branches based on if/else conditions.</td><td></td></tr><tr><td><a href="code.md"><strong>Code Execution</strong></a></td><td>Runs Python/NodeJS code to execute custom logic such as data transformation within the workflow.</td><td></td></tr><tr><td><a href="template.md"><strong>Template</strong></a></td><td>Enables flexible data transformation and text processing using Jinja2, a Python templating language.</td><td></td></tr><tr><td><a href="variable-aggregator.md"><strong>Variable Aggregator</strong></a></td><td>Aggregates variables from multiple branches into one variable for unified configuration of downstream nodes.</td><td></td></tr><tr><td><a href="variable-assigner.md"><strong>Variable Assigner</strong></a></td><td>The variable assigner node is used to assign values to writable variables.</td><td></td></tr><tr><td><a href="parameter-extractor.md"><strong>Parameter Extractor</strong></a></td><td>Uses LLM to infer and extract structured parameters from natural language for subsequent tool calls or HTTP requests.</td><td></td></tr><tr><td><a href="iteration.md"><strong>Iteration</strong></a></td><td>Executes multiple steps on list objects until all results are output.</td><td></td></tr><tr><td><a href="http-request.md"><strong>HTTP Request</strong></a></td><td>Allows sending server requests via the HTTP protocol, suitable for retrieving external results, webhooks, generating images, and other scenarios.</td><td></td></tr><tr><td><a href="tools.md"><strong>Tools</strong></a></td><td>Enables calling built-in Dify tools, custom tools, sub-workflows, and more within the workflow.</td><td></td></tr></tbody></table>
<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><a href="start.md"><strong>Start</strong></a></td><td>Defines the initial parameters for starting a workflow process.</td><td></td></tr><tr><td><a href="end.md"><strong>End</strong></a></td><td>Defines the final output content for ending a workflow process.</td><td></td></tr><tr><td><a href="answer.md"><strong>Answer</strong></a></td><td>Defines the response content in a Chatflow process.</td><td></td></tr><tr><td><a href="llm.md"><strong>Large Language Model (LLM)</strong></a></td><td>Calls a large language model to answer questions or process natural language.</td><td></td></tr><tr><td><a href="knowledge_retrieval.md"><strong>Knowledge Retrieval</strong></a></td><td>Retrieves text content related to user questions from a knowledge base, which can serve as context for downstream LLM nodes.</td><td></td></tr><tr><td><a href="question-classifier.md"><strong>Question Classifier</strong></a></td><td>By defining classification descriptions, the LLM can select the matching classification based on user input.</td><td></td></tr><tr><td><a href="ifelse.md"><strong>IF/ELSE</strong></a></td><td>Allows you to split the workflow into two branches based on if/else conditions.</td><td></td></tr><tr><td><a href="code.md"><strong>Code Execution</strong></a></td><td>Runs Python/NodeJS code to execute custom logic such as data transformation within the workflow.</td><td></td></tr><tr><td><a href="template.md"><strong>Template</strong></a></td><td>Enables flexible data transformation and text processing using Jinja2, a Python templating language.</td><td></td></tr><tr><td><a href="variable-aggregator.md"><strong>Variable Aggregator</strong></a></td><td>Aggregates variables from multiple branches into one variable for unified configuration of downstream nodes.</td><td></td></tr><tr><td><a href="variable-assigner.md"><strong>Variable Assigner</strong></a></td><td>The variable assigner node is used to assign values to writable variables.</td><td></td></tr><tr><td><a href="parameter-extractor.md"><strong>Parameter Extractor</strong></a></td><td>Uses LLM to infer and extract structured parameters from natural language for subsequent tool calls or HTTP requests.</td><td></td></tr><tr><td><a href="iteration.md"><strong>Iteration</strong></a></td><td>Executes multiple steps on list objects until all results are output.</td><td></td></tr><tr><td><a href="http-request.md"><strong>HTTP Request</strong></a></td><td>Allows sending server requests via the HTTP protocol, suitable for retrieving external results, webhooks, generating images, and other scenarios.</td><td></td></tr><tr><td><a href="tools.md"><strong>Tools</strong></a></td><td>Enables calling built-in Dify tools, custom tools, sub-workflows, and more within the workflow.</td><tr><td><a href="loop.md"><strong>Loop</strong></a></td><td>A Loop node executes repetitive tasks that depend on previous iteration results until exit conditions are met or the maximum loop count is reached.</td><td></td></tr></tbody></table>
+83
View File
@@ -0,0 +1,83 @@
# Loop
## What is Loop Node?
A **Loop** node executes repetitive tasks that depend on previous iteration results until exit conditions are met or the maximum loop count is reached.
## Loop vs. Iteration
<table>
<thead>
<tr>
<th>Type</th>
<th>Dependencies</th>
<th>Use Cases</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Loop</strong></td>
<td>Each iteration depends on previous results</td>
<td>Recursive operations, optimization problems</td>
</tr>
<tr>
<td><strong>Iteration</strong></td>
<td>Iterations execute independently</td>
<td>Batch processing, parallel data handling</td>
</tr>
</tbody>
</table>
## Configuration
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>Loop Termination Condition</td>
<td>Expression that determines when to exit the loop</td>
<td><code>x < 50</code>, <code>error_rate < 0.01</code></td>
</tr>
<tr>
<td>Maximum Loop Count</td>
<td>Upper limit on iterations to prevent infinite loops</td>
<td>10, 100, 1000</td>
</tr>
</tbody>
</table>
![Configuration](https://assets-docs.dify.ai/2025/03/13853bfaaa068cdbdeba1b1f75d482f2.png)
## Usage Example
**Goal: Generate random numbers (1-100) until a value below 50 appears.**
**Steps**:
1. Use `node` to generate a random number between 1-100.
2. Use `if` to evaluate the number:
- If < 50: Output `done` and terminate loop.
- If ≥ 50: Continue loop and generate another random number.
3. Set the exit criterion to random_number < 50.
4. Loop ends when a number below 50 appears.
![Steps](https://assets-docs.dify.ai/2025/03/b1c277001fc3cb1fbb85fe7c22a6d0fc.png)
## Planned Enhancements
**Future releases will include:**
- Loop variables: Store and reference values across iterations for improved state management and conditional logic.
- `break` node: Terminate loops from within the execution path, enabling more sophisticated control flow patterns.
+2 -1
View File
@@ -48,10 +48,11 @@
* [リスト処理](guides/workflow/node/list-operator.md)
* [変数集約](guides/workflow/node/variable-aggregator.md)
* [変数代入](guides/workflow/node/variable-assigner.md)
* [イテレーション](guides/workflow/node/iteration.md)
* [反復処理(イテレーション](guides/workflow/node/iteration.md)
* [パラメータ抽出](guides/workflow/node/parameter-extractor.md)
* [HTTPリクエスト](guides/workflow/node/http-request.md)
* [ツール](guides/workflow/node/tools.md)
* [繰り返し処理(ループ)](guides/workflow/node/loop.md)
* [ショートカットキー](guides/workflow/shortcut-key.md)
* [オーケストレートノード](guides/workflow/orchestrate-node.md)
* [ファイルアップロード](guides/workflow/file-upload.md)
+1 -1
View File
@@ -4,4 +4,4 @@
### コアノード
<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><a href="start.md"><strong>開始(Start</strong></a></td><td>ワークフローの初期パラメータを定義。</td><td></td></tr><tr><td><a href="end.md"><strong>終了(End</strong></a></td><td>ワークフローの最終出力内容を定義。</td><td></td></tr><tr><td><a href="answer.md"><strong>返信(Answer</strong></a></td><td>チャットフロー内の回答内容を定義。</td><td></td></tr><tr><td><a href="llm.md"><strong>大規模言語モデル(LLM</strong></a></td><td>大規模言語モデルを呼び出して質問に答えたり、自然言語を処理したりします。</td><td></td></tr><tr><td><a href="knowledge-retrieval.md"><strong>ナレッジ検索(Knowledge Retrieval</strong></a></td><td>ユーザーの質問に関連するテキストをナレッジベースから検索し、下流のLLMノードのコンテキストとして使用します。</td><td></td></tr><tr><td><a href="question-classifier.md"><strong>質問分類器(Question Classifier</strong></a></td><td>分類の説明を定義することで、LLMがユーザーの入力に基づいて適切な分類を選択できるようにします。</td><td></td></tr><tr><td><a href="ifelse.md"><strong>IF/ELSE(条件分岐)</strong></a></td><td>if/elseの条件に基づいてワークフローを2つの分岐に分けることができます。</td><td></td></tr><tr><td><a href="code.md"><strong>コード実行(Code</strong></a></td><td>Python / NodeJSコードを実行してワークフロー内でデータ変換などのカスタムロジックを実行します。</td><td></td></tr><tr><td><a href="template.md"><strong>テンプレート(Template</strong></a></td><td>Jinja2のPythonテンプレート言語を利用して、データ変換やテキスト処理を柔軟に行うことができます。</td><td></td></tr><tr><td><a href="variable-assigner.md"><strong>変数集約(Variable Aggregator</strong></a></td><td>複数の分岐の変数を1つの変数に集約し、下流ノードの統一設定を実現します。</td><td></td></tr><tr><td><a href="parameter-extractor.md"><strong>パラメーター抽出器(Parameter Extractor</strong></a></td><td>LLMを利用して自然言語から構造化パラメーターを推論し、後続のツール呼び出しやHTTPリクエストに使用します。</td><td></td></tr><tr><td><a href="iteration.md"><strong>イテレーションIteration</strong></a></td><td>リストオブジェクトに対して複数回のステップを実行し、すべての結果を出力します。</td><td></td></tr><tr><td><a href="http-request.md"><strong>HTTPリクエスト(HTTP Request</strong></a></td><td>HTTPプロトコルを介してサーバーリクエストを送信し、外部検索結果の取得、webhook、画像生成などのシナリオに適用されます。</td><td></td></tr><tr><td><a href="tools.md"><strong>ツール(Tools</strong></a></td><td>Dify内蔵ツール、カスタムツール、サブワークフローなどをワークフロー内で呼び出すことができます。</td><td></td></tr><tr><td><a href="variable-assignment.md"><strong>変数代入(Variable Assigner</strong></a></td><td>変数代入ノードは変数(例えば、会話変数)に指定した値を代入するノードです。</td><tr><td><a href="list-operator.md"><strong>リスト操作(List Operator</strong></a></td><td>-</td><tr><td><a href="doc-extractor.md"><strong>テキスト抽出ツール(Document Extractor</strong></a></td><td>アップロードした文書を解析し、文書ファイルの情報を読み取り、テキストに変換して内容をLLMに送信する</td><td></td></tr></tbody></table>
<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><a href="start.md"><strong>開始(Start</strong></a></td><td>ワークフローの初期パラメータを定義。</td><td></td></tr><tr><td><a href="end.md"><strong>終了(End</strong></a></td><td>ワークフローの最終出力内容を定義。</td><td></td></tr><tr><td><a href="answer.md"><strong>返信(Answer</strong></a></td><td>チャットフロー内の回答内容を定義。</td><td></td></tr><tr><td><a href="llm.md"><strong>大規模言語モデル(LLM</strong></a></td><td>大規模言語モデルを呼び出して質問に答えたり、自然言語を処理したりします。</td><td></td></tr><tr><td><a href="knowledge-retrieval.md"><strong>ナレッジ検索(Knowledge Retrieval</strong></a></td><td>ユーザーの質問に関連するテキストをナレッジベースから検索し、下流のLLMノードのコンテキストとして使用します。</td><td></td></tr><tr><td><a href="question-classifier.md"><strong>質問分類器(Question Classifier</strong></a></td><td>分類の説明を定義することで、LLMがユーザーの入力に基づいて適切な分類を選択できるようにします。</td><td></td></tr><tr><td><a href="ifelse.md"><strong>IF/ELSE(条件分岐)</strong></a></td><td>if/elseの条件に基づいてワークフローを2つの分岐に分けることができます。</td><td></td></tr><tr><td><a href="code.md"><strong>コード実行(Code</strong></a></td><td>Python / NodeJSコードを実行してワークフロー内でデータ変換などのカスタムロジックを実行します。</td><td></td></tr><tr><td><a href="template.md"><strong>テンプレート(Template</strong></a></td><td>Jinja2のPythonテンプレート言語を利用して、データ変換やテキスト処理を柔軟に行うことができます。</td><td></td></tr><tr><td><a href="variable-assigner.md"><strong>変数集約(Variable Aggregator</strong></a></td><td>複数の分岐の変数を1つの変数に集約し、下流ノードの統一設定を実現します。</td><td></td></tr><tr><td><a href="parameter-extractor.md"><strong>パラメーター抽出器(Parameter Extractor</strong></a></td><td>LLMを利用して自然言語から構造化パラメーターを推論し、後続のツール呼び出しやHTTPリクエストに使用します。</td><td></td></tr><tr><td><a href="iteration.md"><strong>反復処理Iteration</strong></a></td><td>リストオブジェクトに対して複数回のステップを実行し、すべての結果を出力します。</td><td></td></tr><tr><td><a href="http-request.md"><strong>HTTPリクエスト(HTTP Request</strong></a></td><td>HTTPプロトコルを介してサーバーリクエストを送信し、外部検索結果の取得、webhook、画像生成などのシナリオに適用されます。</td><td></td></tr><tr><td><a href="tools.md"><strong>ツール(Tools</strong></a></td><td>Dify内蔵ツール、カスタムツール、サブワークフローなどをワークフロー内で呼び出すことができます。</td><td></td></tr><tr><td><a href="variable-assignment.md"><strong>変数代入(Variable Assigner</strong></a></td><td>変数代入ノードは変数(例えば、会話変数)に指定した値を代入するノードです。</td><tr><td><a href="list-operator.md"><strong>リスト操作(List Operator</strong></a></td><td>-</td><tr><td><a href="doc-extractor.md"><strong>テキスト抽出ツール(Document Extractor</strong></a></td><td>アップロードした文書を解析し、文書ファイルの情報を読み取り、テキストに変換して内容をLLMに送信する</td><tr><td><a href="loop.md"><strong>繰り返し処理(Loop</strong></a></td><td>前回の結果に依存する反復タスクを実行し、終了条件を満たすか最大繰り返し回数に達するまで継続します。</td><td></td></tr></tbody></table>
+1 -1
View File
@@ -1,4 +1,4 @@
# イテレーション
# 反復処理(イテレーション
### 定義
+81
View File
@@ -0,0 +1,81 @@
# 繰り返し処理(ループ)
## 概要
繰り返し処理(ループ)ノードは、前回の結果に依存する反復タスクを実行し、終了条件を満たすか最大繰り返し回数に達するまで継続します。
## 繰り返し処理ノードと反復処理ノードの違い
<table>
<thead>
<tr>
<th>タイプ</th>
<th>特徴</th>
<th>用途</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>繰り返し処理(ループ)</strong></td>
<td>各回の処理が前回の結果に依存する。</td>
<td>再帰処理や最適化問題など、前回の計算結果を必要とする処理に適している。</td>
</tr>
<tr>
<td><strong>反復処理(イテレーション)</strong></td>
<td>各回の処理は独立しており、前回の結果に依存しない。</td>
<td>データの一括処理など、各処理を独立して実行できるタスクに適している。</td>
</tr>
</tbody>
</table>
## 繰り返し処理(ループ)ノードの設定方法
<table>
<thead>
<tr>
<th>パラメータ</th>
<th>説明</th>
<th>例</th>
</tr>
</thead>
<tbody>
<tr>
<td>ループ終了条件</td>
<td>ループを終了するタイミングを決定する式</td>
<td><code>x < 50</code>、<code>error_rate < 0.01</code></td>
</tr>
<tr>
<td>最大繰り返し回数(Maximum Loop Count</td>
<td>無限ループを防ぐための繰り返し回数の上限</td>
<td>10、100、1000</td>
</tr>
</tbody>
</table>
![設定](https://assets-docs.dify.ai/2025/03/13853bfaaa068cdbdeba1b1f75d482f2.png)
## 使用例
**目標:50未満の値が出るまで、1から100までのランダムな数値を生成する。**
**実装手順**
1. `code`ノードを使用して1-100の間のランダムな数値を生成します。
2. `if`ノードを使用して数値を評価します:
- 50未満の場合:`done`を出力してループを終了します。
- 50以上の場合:ループを継続し、別のランダムな数値を生成します。
3. ループ終了条件を「ランダム数値 < 50」に設定します。
4. 50未満の数値が出現したらループは自動的に終了します。
![使用例](https://assets-docs.dify.ai/2025/03/b1c277001fc3cb1fbb85fe7c22a6d0fc.png)
## 今後の拡張
**今後のリリースには以下の機能が追加される予定です:**
- ループ変数:繰り返し間で値を保存・参照できるようにし、状態管理と条件付きロジックを強化します。
- `break`ノード:実行パス内からループを直接終了できるようにし、より高度な制御フローパターンを実現します。
+1
View File
@@ -53,6 +53,7 @@
* [工具](guides/workflow/node/tools.md)
* [结束](guides/workflow/node/end.md)
* [直接回复](guides/workflow/node/answer.md)
* [循环](guides/workflow/node/loop.md)
* [快捷键](guides/workflow/shortcut-key.md)
* [编排节点](guides/workflow/orchestrate-node.md)
* [文件上传](guides/workflow/file-upload.md)
+1 -1
View File
@@ -4,4 +4,4 @@
### 核心节点
<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><a href="start.md"><strong>开始(Start</strong></a></td><td>定义一个 workflow 流程启动的初始参数。</td><td></td></tr><tr><td><a href="end.md"><strong>结束(End</strong></a></td><td>定义一个 workflow 流程结束的最终输出内容。</td><td></td></tr><tr><td><a href="answer.md"><strong>回复(Answer</strong></a></td><td>定义一个 Chatflow 流程中的回复内容。</td><td></td></tr><tr><td><a href="llm.md"><strong>大语言模型(LLM</strong></a></td><td>调用大语言模型回答问题或者对自然语言进行处理。</td><td></td></tr><tr><td><a href="knowledge-retrieval.md"><strong>知识检索(Knowledge Retrieval</strong></a></td><td>从知识库中检索与用户问题相关的文本内容,可作为下游 LLM 节点的上下文。</td><td></td></tr><tr><td><a href="question-classifier.md"><strong>问题分类(Question Classifier</strong></a></td><td>通过定义分类描述,LLM 能够根据用户输入选择与之相匹配的分类。</td><td></td></tr><tr><td><a href="ifelse.md"><strong>条件分支(IF/ELSE</strong></a></td><td>允许你根据 if/else 条件将 workflow 拆分成两个分支。</td><td></td></tr><tr><td><a href="code.md"><strong>代码执行(Code</strong></a></td><td>运行 Python / NodeJS 代码以在工作流程中执行数据转换等自定义逻辑。</td><td></td></tr><tr><td><a href="template.md"><strong>模板转换(Template</strong></a></td><td>允许借助 Jinja2 的 Python 模板语言灵活地进行数据转换、文本处理等。</td><td></td></tr><tr><td><a href="variable-aggregator.md"><strong>变量聚合(Variable Aggregator</strong></a></td><td>将多路分支的变量聚合为一个变量,以实现下游节点统一配置。</td><td></td></tr><tr><td><a href="parameter-extractor.md"><strong>参数提取器(Parameter Extractor</strong></a></td><td>利用 LLM 从自然语言推理并提取结构化参数,用于后置的工具调用或 HTTP 请求。</td><td></td></tr><tr><td><a href="iteration.md"><strong>迭代(Iteration</strong></a></td><td>对列表对象执行多次步骤直至输出所有结果。</td><td></td></tr><tr><td><a href="http-request.md"><strong>HTTP 请求(HTTP Request</strong></a></td><td>允许通过 HTTP 协议发送服务器请求,适用于获取外部检索结果、webhook、生成图片等情景。</td><td></td></tr><tr><td><a href="tools.md"><strong>工具(Tools</strong></a></td><td>允许在工作流内调用 Dify 内置工具、自定义工具、子工作流等。</td><td></td></tr><tr><td><a href="variable-assigner.md"><strong>变量赋值(Variable Assigner</strong></a></td><td>变量赋值节点用于向可写入变量(例如会话变量)进行变量赋值。</td><td></td></tr></tbody></table>
<table data-view="cards"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td><a href="start.md"><strong>开始(Start</strong></a></td><td>定义一个 workflow 流程启动的初始参数。</td><td></td></tr><tr><td><a href="end.md"><strong>结束(End</strong></a></td><td>定义一个 workflow 流程结束的最终输出内容。</td><td></td></tr><tr><td><a href="answer.md"><strong>回复(Answer</strong></a></td><td>定义一个 Chatflow 流程中的回复内容。</td><td></td></tr><tr><td><a href="llm.md"><strong>大语言模型(LLM</strong></a></td><td>调用大语言模型回答问题或者对自然语言进行处理。</td><td></td></tr><tr><td><a href="knowledge-retrieval.md"><strong>知识检索(Knowledge Retrieval</strong></a></td><td>从知识库中检索与用户问题相关的文本内容,可作为下游 LLM 节点的上下文。</td><td></td></tr><tr><td><a href="question-classifier.md"><strong>问题分类(Question Classifier</strong></a></td><td>通过定义分类描述,LLM 能够根据用户输入选择与之相匹配的分类。</td><td></td></tr><tr><td><a href="ifelse.md"><strong>条件分支(IF/ELSE</strong></a></td><td>允许你根据 if/else 条件将 workflow 拆分成两个分支。</td><td></td></tr><tr><td><a href="code.md"><strong>代码执行(Code</strong></a></td><td>运行 Python / NodeJS 代码以在工作流程中执行数据转换等自定义逻辑。</td><td></td></tr><tr><td><a href="template.md"><strong>模板转换(Template</strong></a></td><td>允许借助 Jinja2 的 Python 模板语言灵活地进行数据转换、文本处理等。</td><td></td></tr><tr><td><a href="variable-aggregator.md"><strong>变量聚合(Variable Aggregator</strong></a></td><td>将多路分支的变量聚合为一个变量,以实现下游节点统一配置。</td><td></td></tr><tr><td><a href="parameter-extractor.md"><strong>参数提取器(Parameter Extractor</strong></a></td><td>利用 LLM 从自然语言推理并提取结构化参数,用于后置的工具调用或 HTTP 请求。</td><td></td></tr><tr><td><a href="iteration.md"><strong>迭代(Iteration</strong></a></td><td>对列表对象执行多次步骤直至输出所有结果。</td><td></td></tr><tr><td><a href="http-request.md"><strong>HTTP 请求(HTTP Request</strong></a></td><td>允许通过 HTTP 协议发送服务器请求,适用于获取外部检索结果、webhook、生成图片等情景。</td><td></td></tr><tr><td><a href="tools.md"><strong>工具(Tools</strong></a></td><td>允许在工作流内调用 Dify 内置工具、自定义工具、子工作流等。</td><td></td></tr><tr><td><a href="variable-assigner.md"><strong>变量赋值(Variable Assigner</strong></a></td><td>变量赋值节点用于向可写入变量(例如会话变量)进行变量赋值。</td><tr><td><a href="loop.md"><strong>循环(Loop</strong></a></td><td>循环节点用于执行依赖前一轮结果的重复任务,直到满足退出条件或达到最大循环次数。</td><td></td></tr></tbody></table>
+89
View File
@@ -0,0 +1,89 @@
# 循环
## 简介
循环(Loop)节点用于执行依赖前一轮结果的重复任务,直到满足退出条件或达到最大循环次数。
## 循环节点与迭代节点有什么区别?
循环节点和迭代节点在任务处理上的定位不同:
<table>
<thead>
<tr>
<th>类型</th>
<th>特点</th>
<th>适用场景</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>循环</strong>Loop</td>
<td>轮次之间存在依赖关系的优化型任务。即任务的每一轮执行都依赖上一轮的结果。</td>
<td>需要前一轮的计算结果,适用于递归、优化问题等。</td>
</tr>
<tr>
<td><strong>迭代</strong>Iteration</td>
<td>轮次之间无依赖关系的批处理任务。即每一轮任务可以独立运行,无需依赖前一轮。</td>
<td>每轮独立执行,可用于数据批量处理等。</td>
</tr>
</tbody>
</table>
## 如何配置循环节点?
循环节点包含以下两个关键配置项:
<table>
<thead>
<tr>
<th>配置项</th>
<th>作用</th>
<th>示例</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>循环退出条件</strong>Loop Termination Condition</td>
<td>设置循环何时停止</td>
<td>例:当变量 <code>x < 50</code> 时,停止循环。</td>
</tr>
<tr>
<td><strong>最大循环次数</strong>Maximum Loop Count</td>
<td>限制最多执行的轮次,避免无限循环</td>
<td>例:最多执行 10 轮,不管是否满足退出条件。</td>
</tr>
</tbody>
</table>
你可以在 **循环退出条件** 中使用循环体内的变量或会话中的全局变量,让循环按照你的需求停止。
![Configuration](https://assets-docs.dify.ai/2025/03/13853bfaaa068cdbdeba1b1f75d482f2.png)
## 示例:如何使用循环节点?
**需求:生成 1-100 的随机数,直到随机数小于 50 时停止。**
**实现步骤**
1. 使用 `code` 节点生成 `1-100` 的随机数。
2. 使用 `if` 节点判断随机数是否小于 `50`
- 如果小于 50,输出 `done` 并结束循环。
- 如果不小于 50,继续循环,生成新的随机数。
3. 设置循环退出标准:随机数 `< 50`
4. 循环将在随机数小于 `50` 时自动停止。
![Case steps](https://assets-docs.dify.ai/2025/03/b1c277001fc3cb1fbb85fe7c22a6d0fc.png)
## 未来扩展
**后续版本将提供:**
- 循环变量:支持在循环过程中存储和引用变量,增强逻辑控制能力。
- `break` 节点:允许在循环体内部直接终止循环,适用于更复杂的流程控制。