Skip to content
ajan.io

Docs menu

On this page

Loop

Iterate over arrays and process multiple items with the same logic.

Overview

The Loop node processes arrays of data - iterate through lists of customers, orders, files, or any collection, applying the same logic to each item.

Configuration

Input Array: Select the array to loop over

handlebars
{{ trigger.output.customers }}
{{ api_response.output.items }}
{{ google_sheets.output.rows }}

Max Iterations: Safety limit (default: 200, max: 2000)

Advanced Options

Concurrency: Enable parallel processing of loop iterations

When enabled, all iterations run simultaneously instead of one after another. This significantly speeds up loops but requires that iterations don't depend on each other.

ConcurrencyBehaviorBest For
Off (default)Sequential - each iteration waits for the previous one to completeDependent operations, rate-limited APIs
OnParallel - all iterations run at the same timeIndependent operations, faster processing

Collect Outputs: Gather all iteration results into a single array

When enabled, the loop end node outputs an array containing results from every iteration. This is useful for aggregating data processed in the loop.

The collected output is also available to nodes that run later in the same workflow run, including nodes inside an enclosing outer loop.

handlebars
{{ loop_end.output.iterations }}            β†’ Array of all iteration data
{{ loop_end.output.iterations[0].item }}    β†’ First iteration's input item
{{ loop_end.output.iterations[0].executions }}  β†’ Nodes executed in first iteration
{{ loop_end.output.total }}                 β†’ Total number of iterations

Collected Output Structure:

json
{
  "iterations": [
    {
      "index": 0,
      "item": { "original": "data" },
      "executions": [
        {
          "nodeId": "abc123",
          "nodeSlug": "agent",
          "nodeType": "agent",
          "input": { ... },
          "output": { "result": "processed" }
        }
      ]
    }
  ],
  "total": 10
}

Inside the Loop

The loop node's slug becomes your variable name. Access the current item and iteration info:

handlebars
{{ customer.output.currentItem }}           // The full current item
{{ customer.output.currentItem.name }}      // Access item properties
{{ customer.output.currentItem.email }}
{{ customer.output.currentIndex }}          // Current iteration (0-based)
{{ customer.output.total }}                 // Total items in array

Example Use Cases

Process Customer List

text
Loop over {{ trigger.output.customers }}
  Loop node slug: customer

  β†’ Agent: Analyze {{ customer.output.currentItem.feedback }}
  β†’ Condition: Check {{ customer.output.currentItem.score }}
    β†’ High: Send thank you email
    β†’ Low: Create follow-up task

Batch Update Records

text
Loop over {{ api_response.output.records }}
  Loop node slug: record

  β†’ Code: Transform {{ record.output.currentItem.data }}
  β†’ HTTP Request: Update record {{ record.output.currentItem.id }}

Generate Individual Reports

text
Loop over {{ trigger.output.team_members }}
  Loop node slug: member

  β†’ HTTP Request: Fetch {{ member.output.currentItem.id }} data
  β†’ Agent: Generate report for {{ member.output.currentItem.name }}
  β†’ Action: Email report to {{ member.output.currentItem.email }}

Parallel Image Processing (Concurrency)

text
Loop over {{ trigger.output.images }}
  Loop node slug: image
  Parallel Execution: On

  β†’ Agent: Analyze {{ image.output.currentItem.url }}
  β†’ Code: Extract metadata

All images are analyzed simultaneously, completing much faster than sequential processing.

Aggregate Results (Collect Outputs)

text
Loop over {{ trigger.output.documents }}
  Loop node slug: doc
  Collect Outputs: On

  β†’ Agent: Summarize {{ doc.output.currentItem.content }}
  β†’ Code: Extract key points

β†’ Agent: Create master summary from {{ loop_end.output.iterations }}
β†’ Action: Send combined report

The final Agent receives all summaries at once to create a comprehensive report.

Best Practices

Prevent infinite loops and runaway costs. Set a reasonable maximum.

Instead of 100 individual agent calls, batch items into groups of 10.

Add a condition before the loop to check if array has items.

Loops with AI agents can be expensive. Calculate: cost per item Γ— number of items.

Cost Warning

Next Steps