Definition
In automation workflows, it is often necessary to repeatedly execute the same segment of business logic, such as processing a dataset item by item, reading text line by line for batch operations, or attempting certain steps multiple times within a specified iteration count.
To meet these needs, GoInsight.AI provides a "Iteration" node that can accommodate various business nodes within a visual "Sub-workflow." This node can execute repeatedly based on a specified iteration mode and ultimately merge the output results of each loop into a single list for downstream nodes to use.

Quick Start / How to Use
Node Configuration Details: In ChatInsight.AI, right-click and select "Add Node" to add an 'Iteration' node to the workflow.

1. Configure the Iteration Mode Parameter of the Iteration Node
- 1)Specify Count:
- Run the loop for a specified number of times. There is a "Number of iterations" input box to set the number of times the loop will execute. The range for loop iterations is 1 to 30.
- Execution logic: The loop body will repeat for the set number of times, and during each execution, it can operate using the configured variables.
- 2)Iterate Collection:
- Specify a collection and run the loop once on each element in the order of the collection. In the "Input Variables" area, there is an "(x) Set Variable" input box for setting variables used during the loop process.
- Execution logic: The loop body will sequentially process each element in the collection, assign the element to related variables for operations, and store the results in output variables.
- 3)Iterate Lines:
- Traverse the text line by line, treating each line of text as an element of the loop and running the loop once for each line.
- Execution logic: Similar to iterating through a collection, but with a focus on processing data line by line, suitable for tabular or other two-dimensional data structures.
- Collection Element Types:
- In the "Collection Element Types" area, there is a dropdown menu to select the element type. The options include "String," "Number," and "Bool."
- Choose the appropriate element type based on the data type to be processed. For instance, if processing string data, select the "String" type.
- Read Line by Line:
- In the "Read Line by Line" area, there is an "(x) Key for Quick Insertion" input box. You can also input the data to be read line by line in the input box based on your situation. For example, if reading data from a file, you can specify the file path or data source here.
2. Configure the Iteration Result Output Parameters of the Iteration Node
- Loop Result OutputUse the "Output Collection Variable Name [Arra...]" input box to set the name of the output variable that will store the results from the loop process.
- Use the "(x) Variables from the Loop Body" input box to specify the variables generated within the loop body, which may be used for subsequent operations or as loop result outputs.
- Use the "Delete" button to remove the configured output variables.
- Use the "+ Add" button to add more output variable configurations.
3. Configure the Remark Parameters of the Iteration Node
The "Remark" area allows you to enter descriptive information about this Iteration node, such as the purpose of the loop, the meaning of input and output variables, etc., for easier understanding and maintenance by yourself and others.
Typical Use Cases
- Data Processing
- In data processing scenarios, the Iteration node can be used to iterate through datasets. For example, when processing a batch of sales order data, the Iteration node can read order records one by one and perform operations such as calculating total prices and counting the number of items for each order.
- For a large number of data files, the Iteration node can sequentially open each file, read the data content, and perform cleansing, transformations, etc., ensuring the accuracy and usability of the data.
- Batch sending personalized emails: Suppose there is a user list (Array) that contains each user's name, email address, and personalized information. By iterating through the user list, the loop body can use this user information to assemble personalized email content, then call the email sending API to send the emails. After the loop ends, the results of the email sending (success or failure status, etc.) are summarized into a list for easy review and statistics on the email sending situation, such as calculating the success rate or analyzing reasons for failure.
- Task Execution
- In automated task scenarios, the Iteration node can repeatedly execute a certain task. For example, in system monitoring tasks, the Iteration node can check system resources (such as CPU usage, memory consumption, etc.) at regular intervals (e.g., every 5 minutes) and record data or issue alerts in case of anomalies.
- During software testing, the Iteration node can repeatedly execute test cases to trial the software multiple times, ensuring its stability and reliability.
- Batch translation of multiple lines of text: The user inputs a block of text containing multiple lines, and the Iteration node first splits this text by line. Then, in each iteration, each line of text is translated using an LLM. Once the translation is complete, the results from each iteration are aggregated into an array, which is then passed to the subsequent node. The subsequent node can further process these translation results, such as making formatting adjustments and proofreading.
- Numerical Calculation
- In the financial field, the Iteration node can be used to calculate compound interest. Through iterative loops, the final principal and interest amount can be gradually calculated based on the principal, interest rate, and period.
- Conditional Looping
- The Iteration node can be combined with conditional judgments to control the execution of the loop. For example, when processing user input, the Iteration node can continuously read the input until a specific exit command is entered, thus enabling an interactive program flow.
- During data validation, the Iteration node can repeatedly check if the data meets specific standards, exiting the loop only when the data fully complies with the requirements and then proceeding to the next step.
- Batch calling external APIs: Calls can be made a predetermined number of times (e.g., 10 times) or iterate through an ID list to repeatedly call external APIs. After each API call, the returned results are captured. At the end of the loop, all captured results are merged and outputted.
Practical Case Scenarios
- Weather Query Workflow DesignCall a weather query API, iterate through the city ID list to obtain the weather information for each city, and finally compile and organize all the weather information to generate a comprehensive weather report.
Notes
- Avoid infinite loops. Set termination conditions and timeout mechanisms to force exit, preventing loops from being uninterruptible.
- Try to avoid iterating over empty arrays or null values. Check if the values to be iterated are empty; if they are, prompt the user or exit.

