Node Function
The loop supports repeatedly executing a series of tasks until the conditions are met. Loop Node belongs to Basic Node, allowing users to cyclically execute a specific workflow by configuring input variables, loop body (workflow), and loop method.
Directions
Input Variables
Input variables take effect only within the same node and cannot be used cross-node. Support up to 50 input variables to meet scene requirements. Click "Add" to configure input variables as follows.
|
Variable Name | The variable name can only contain letters, digits, or underscores, must start with a letter or underscore. Required. |
Description | Description of this variable. Optional |
Data source | The data source of this variable supports two options: "refer" and "input". "Refer" allows selecting output variables from all preceding nodes, while "input" supports manually filling in a fixed value. Required |
Type | The data type of this variable cannot be selected and defaults to the variable type of "refer" or the string type of "input". |
Note:
The input variable of the loop node supports users to manually specify the loop array. The loop node performs a loop on the elements of the loop array during runtime. Input.Item represents the element content of the current loop array Input.
Loop Body
Represents a workflow for cyclic execution, supporting selection of workflows in "To be released" and "Released" statuses. After selecting a workflow, the page automatically displays its input variables, allowing users to set variables imported each time via the variable introduction method.
Method 1. Introduce the array Input.Item as the input variable of the workflow
During each execution run, a new element in the array will be used as the input variable of the workflow.
Method 2. Introduce another variable (such as input variable) as the input variable of the workflow
Each run uses the same variable as the input variable of the workflow.
Loop Method
The loop node supports two loop methods: "Traverse all elements" and "Loop according to conditions". You can select the loop method based on business scenario. Among them:
Traverse all element: means traversing all elements in the loop array variable to execute the loop body. For example: if the loop array variable contains 10 articles and the loop body workflow is used to summarize the articles, then in "Traverse all element" mode, the loop node will summarize each article, finally generating 10 summary results.
Loop according to conditions: means running the loop body normally and exiting under specific circumstances. For example: if the loop array variable contains 10 articles and the loop body workflow is used to summarize the articles, the loop body will exit when the number of loops reaches 5 or an error occurs, as shown in the figure below.
Note:
The Loop variable of the loop node is a built-in variable specific to that node, including:
Loop.Index: indicates the current number of times the loop body is executed.
Loop.Output: indicates the output result after executing the loop body.
Loop.ErrorCode: indicates the error case when executing the loop body. 0 means normal, 1 indicates abnormality.
Loop.Log: indicates the log of the currently executed loop body.
Output Variable
The loop node will output the following variables for use by subsequent nodes. Manually adding variables is not supported.
|
Results | Dynamic variable, the internal field named the output variable of the referenced sub-workflow. Results return all execution results of the loop body, with the data type array<object>. |
LoopCount | Number of execution of the loop body, with the data type int |
Error | Error information at runtime. This field is empty during normal operation, with the data type object. |
Exception handling can be enabled manually (off by default), supporting exception retry and exception handling method configuration. The configuration content is as follows:
|
Max Retry Attempts | Maximum number of times to rerun when the node is running exceptionally. If retries exceed the set number of times, consider that node call failed and execute the exception handling method below. Default is 3 times. |
Retry Interval | Interval between each rerun, default is 1 second. |
Handling Method | Support three types: "Output Specific Content", "Execution Exception Flow", and "Interrupt Flow". |
Output Variable | Select the exception handling method as "Output specific content". The output variable returned when retries exceed the maximum number. |
Select the exception handling method as "Output Specific Content". When an exception occurs, the workflow will not be interrupted. After node retry, it will return directly the output variable and variable value set by the user in the output content.
Select the exception handling method as "Execution Exception Flow". When an exception occurs, the workflow will not be interrupted. After node retry, it will execute the exception handling process customized by users.
Select the exception handling method as "Interrupt Flow". There are no more settings. When an exception occurs, the workflow execution is interrupted.
Usage Scenario Recommendation
Loop nodes play a crucial role in the following task scenes:
Dependency relationships exist between tasks
The output result of the preceding task will directly affect the follow-up task execution process, for example: write content paragraph by paragraph according to the chapter sequence in the article outline.
Control the loop process based on results
Based on the outcome of a single or multiple tasks, determine whether to terminate the loop early, for example: process user feedback one by one and abort the task when specific conditions are reached.
Strictly serially executed task flow
Suitable for scenarios where procedure steps must follow a fixed sequence, such as streaming data processing with fixed process.
Application Example
Based on the user input article topic and style, draft an outline for each chapter, then perform paragraph writing by looping calls to the article generation workflow.
Among them, the loop body configuration for drafting articles is as follows:
FAQs
1. How to input text content as a loop array?
The loop body node only supports arrays of type [obj] as loop array input. You can use a code node to convert text content into a type [obj] array and then import it into the loop body.
2. How to set up an infinite loop and terminate by condition?
The loop node does not support infinite loops.