Enabling Loop

To enable looping for a step:

  1. Click the step’s options menu (⋮)
  2. Click Add Loop
  3. Enter a loop expression that determines how the step iterates

Loop Expression

  • A JavaScript expression that returns the next item to process
  • Returns null, undefined, or false to terminate the loop
  • Has access to special variables:
    • index: Current iteration number (starts at 0)
    • item: Current value being processed

Loop Output

  • When loop is enabled, the step’s output becomes an array
  • Each array element contains the output from one iteration
  • Output array maintains the order of processing

Loop Expression Rules

  • Return one item at a time from the array: return items[index];
  • Never return the full array (causes infinite loop)

Accessing Output

When a step has looping enabled, its output becomes an array containing results from each iteration:

const results = modelStep.output.map((item) => item.message);

When accessing the output of a looped step in code steps, you must use array methods like map() to access individual iteration results.

Loop Termination

Loop stops when the expression returns null, undefined, or false.

Array bounds automatically handle termination:

return items[index]; // Returns undefined when index >= length

Examples

Here are some practical examples demonstrating how to use loops in your workflows:

Parallel API Requests

Process multiple API endpoints simultaneously:

File Batch Processing

Process multiple files with consistent logic:

This eliminates the need for separate model steps for each file.

Remove Loop

To remove a loop from a step:

  1. Click the step’s options menu (⋮)
  2. Click Remove Loop