For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Logo
DeveloperAcademyCommunityStatus
ReferenceGuides
ReferenceGuides
  • Agent Studio
    • Overview
    • Quickstart Guides
    • Core Concepts
    • Conversation Process
    • Actions
      • LLM Actions
      • Built-in Actions
      • HTTP Actions
      • Script Actions
      • Compound Actions
        • Action
        • Switch
        • For Loop
        • Parallel
        • Return
        • Try Catch and Raise Error
        • Notify
        • Input Arguments
        • Progress Updates
        • Compound Action Patterns
        • Compound Action Data Bank
        • Compound Action Examples
        • Troubleshooting Compound Actions
    • Connectors
    • System Triggers
    • Agent Architect
    • Cookbooks
    • Development and Testing
    • AI Agent Marketplace
    • Developer Tools
  • Agentic AI
    • LLM Fundamentals
    • The Agentic Reasoning Engine
    • Memory Constructs
    • Conversational Context
    • Guardrails
    • Grounding and Hallucinations
    • Continuous Learning
    • LLMs & SLMs
    • Steerability Tools
    • Multilingual Support
  • Core Platform
    • User Identity
    • Moveworks Agent (On-Prem)
    • Approvals Engine
    • Entity Catalog
    • Moveworks Data Objects
    • Security Information and Event Management (SIEM) Logs Overview
DeveloperAcademyCommunityStatus
On this page
  • Overview
  • Low-Code Editor
  • Syntax Reference
  • Schema
  • Fields
  • Practical Examples
  • Example 1: Actions in Batch
  • Compound Action
  • Expected Output
  • Example 2: Outage Ticket Processing
  • Sample input argument
  • Compound Action
  • Expected Output
Agent StudioActionsCompound Actions

For Loop

||View as Markdown|
Was this page helpful?
Edit this page
Previous

Parallel

Next
Built with

Overview

The for expression is a foreach loop that iterates over an iterable (array/list from the data bank), binding each item to an each & index variable. It executes steps sequentially per iteration, then aggregate outputs into the output_key as a list of dicts. It is Ideal for bulk actions like user notifications.

Output Aggregation Deep Dive

The for expression outputs a clean list of objects, where one object contains the results of an iteration. An example loop with two actions,incident_manager_profile and updated_manager_profile, expect:

1"for_expression_output_result": [
2 {
3 "incident_manager_profile": { "id": "12345", "status": "INACTIVE" },
4 "updated_manager_profile": { "id": "67890", "status": "ON_CALL" }
5 },
6 {
7 "incident_manager_profile": { "id": "1a2b3c", "status": "INACTIVE" },
8 "updated_manager_profile": { "id": "4d5e6f", "status": "ON_CALL" }
9 }
10]

You can access the variables the same way you access any others in the data bank; e.g., data.for_expression_output_result[0].incident_manager_profile.status will yield INACTIVE

Low-Code Editor

Add a For Loop Step, bind iterable, define loop variables, and add expressions inside.

You can only bind an iterable in in, you cannot create a list on the fly using DSL such as ["a", "b"], only data bank variables work.

You can create a precursor script action to output a list and pass it to in .

  1. Bind the Iterable (in): Only data bank variables work, inline lists like ["a","b"] will fail.
  2. Define each & index: Set each for item (e.g., user) and index (e.g., user_index), these are only scoped to the for loop.
  3. Add expression & Set output_key: Add expressions to each step. Make sure to add readable output keys.

Syntax Reference

Schema

1for:
2 each: ITEM_VAR_NAME* # str: Current item (e.g., 'user')-scoped to steps
3 index: INDEX_VAR_NAME # str: Optional position (e.g., 'user_index')—use for ordering
4 in: DATA_BANK_ITERABLE* # str: Ref to array var (e.g., 'data.users')—no inline literals!
5 output_key: RESULTS_VAR* # str: Aggregates as list[dict] of step outputs
6 steps: # list: Expressions per iteration (optional, but useful)
7 - EXPRESSION_1 # e.g., action with {{each.record_id}}
8 - EXPRESSION_2

Fields

FieldTypeMandatoryDescription
eachstringYesitem binder - accessed as var.prop within steps
indexstringNoIndex binder - provides position (e.g., idx). Useful for ordering or referencing iteration results.
instringYesData bank reference only (upstream outputs)
output_keylist[dict]YesList of per-iteration dicts: [ {step_key: val}, ... ]. Access: data.results[i].step_key.
stepslist[expr]NoLoop body; empty yields empty dicts

Practical Examples

Example 1: Actions in Batch

Run actions for each user in a list

Compound Action

1steps:
2 - action:
3 action_name: mw.batch_get_users_by_email
4 output_key: user_results
5 input_args:
6 user_emails:
7 - '"jdoe@example.com"'
8 - '"sdom@example.com"'
9 - '"jnde@example.com"'
10 - for:
11 each: user
12 index: user_index
13 in: data.user_results.user_records # From upstream fetch
14 output_key: requested_for_notifications
15 steps:
16 - action:
17 action_name: mw.send_plaintext_chat_notification
18 output_key: notification_output
19 input_args:
20 user_record_id: user.lookup_id
21 message: '''Hi, this is a batch message!'''

Expected Output

1requested_for_notifications: [
2 { "notification_output": { "status": "sent", "user": "user1" } },
3 { "notification_output": { "status": "sent", "user": "user2" } },
4 { "notification_output": { "status": "sent", "user": "user3" } }
5]

The compound actions fetches the records of the users and consequentially uses a for loop to send a message to each user.

Example 2: Outage Ticket Processing

Batch-update manager for open tickets

Sample input argument

outage_tickets: [ {"system_id": "OUT-123"}, {"system_id": "OUT-456"} ]

Compound Action

1for:
2 each: ticket
3 index: index
4 in: data.outage_tickets
5 output_key: outage_ticket_process_results
6 steps:
7 - action:
8 action_name: get_incident_manager_for_outage
9 input_args:
10 outage_id: ticket.system_id
11 output_key: incident_manager_profile
12 - action:
13 action_name: update_incident_manager_profile
14 input_args:
15 manager_id: data.incident_manager_profile.id
16 status: '''ON_CALL'''
17 output_key: updated_manager_profile

Expected Output

1outage_ticket_process_results: [
2 {
3 "incident_manager_profile": { "id": "7bd99d76-...", "status": "INACTIVE" },
4 "updated_manager_profile": { "id": "7bd99d76-...", "status": "ON_CALL" }
5 },
6 {
7 "incident_manager_profile": { "id": "839b82da-...", "status": "INACTIVE" },
8 "updated_manager_profile": { "id": "839b82da-...", "status": "ON_CALL" }
9 }
10]

The for loop iterates through each ticket, it finds the incident manager for the ticket and updates the status of the incident manager to ON_CALL