Overview

For Loops allow your agent to repeat actions for each item in a list or a specific number of times. This saves you from having to create multiple copies of the same steps and makes your workflow more efficient.

Use Cases

  • Process Multiple Items: Apply the same steps to each item in a list

  • Repeat Actions: Perform the same task multiple times

  • Build Cumulative Results: Gather information across multiple iterations

  • Process User Lists: Handle user-provided lists of items or requests

How For Loops Work

A For Loop repeats the same actions for each item in your list. Think of it like an assembly line:

  1. The loop takes one item from your list

  2. It puts that item in a variable you can use

  3. It performs all the actions you’ve added to the loop

  4. Then it takes the next item and repeats the process until it’s gone through every item

Creating a For Loop

Step 1. Add the For Loop Action

  1. In the Actions tab, click “Add action”

  2. Select “For Loop” from the Run Process tab

Step 2. Configuration Fields

  1. List to loop over

    • Description: Enter a list to loop over or a fixed number of iterations.

    • Example: 

      1. A variable containing a list (like {{topics_list}})

      2. A number of times to repeat (like 3)

      3. A JSON array (like [“item1”, “item2”, “item3”])

    • Required: Yes

  2. Loop Index Variable Name

    • Description: Name the variable that will count your loops (this counter starts at 0 and increases by 1 each time through the loop)

    • Example: loop_index

      1. If you’re looping 3 times, this variable will be 0 during the first loop, 1 during the second loop, and 2 during the third loop
    • Validation: Only letters, numbers, and underscores (_) are allowed.

    • Required: Yes

Step 3. Add Actions Inside the Loop

After your For Loop action, add the steps you want to repeat for each item. 

Step 4: End the Loop

After all the actions you want to repeat, add an “End If/Else/For Statement” action to mark where your loop ends.

Example: For Loop Example Agent

See this simple example agent which uses a For Loop:

  1. Gets a list of 3 topics from the user

  2. Loops through each topic, one by one

  3. For each topic:

    • Uses AI to generate an explanation

    • Adds the explanation to a cumulative output

  4. Displays all topic explanations to the user when complete