The Loop Node enables your agent to execute a sequence of connected nodes repeatedly until a specific exit condition is satisfied. This is essential for building iterative workflows, such as content refinement, retry mechanisms, and batch data processing.
Configuration & Stopping Conditions
The Loop Node allows you to define exactly when the cycle should stop using three different types of termination conditions:
1. Counter-Based (Fixed Repetitions)
- Parameter:
max_iterations(Default:5) - Description: The loop will execute up to a fixed number of times. This is ideal for straightforward retry limits or fixed-length loops.
2. Time-Based (Duration Limit)
- Parameter:
max_duration_sec(Default:30) - Description: Prevents infinite loops or excessive delay by forcing an exit if the total looping time exceeds the specified duration (in seconds).
3. Quality-Based (Variable Threshold)
- Parameters:
quality_field(Default:"score"),quality_threshold(Default:0.8) - Description: Monitors a specific field in the flow context (e.g.,
scoreorgrade). The loop exits as soon as this field's value meets or exceeds the defined threshold.
Port Connections (Handles)
The Loop Node uses distinct output handles to distinguish between the active loop and the final exit path:
- Input (
nodeInputConnect): Standard input on the left to start the loop sequence. - Loop Cycle (
loopBack): The exit handle at the bottom. This must connect back to the start of your looped sequence using an amber dashed edge, defining the cycle boundaries. - Loop Exit (
loopExit): The output handle on the right. When any of the stopping conditions are met (e.g., max iterations reached or quality threshold met), the agent successfully exits the loop and continues along this path (represented by an emerald solid edge).
Practical Use Cases
- Iterative Content Refinement: Connect a Text Generator to a Feedback Node, and loop back. Each cycle, the generator refines the text based on previous feedback until the evaluation score meets your
quality_threshold. - Volatile API Retries: Safely make external requests. If a request fails, loop back to try again up to
max_iterationsbefore continuing or routing to a fallback flow. - Data Batching: Iterate through chunks of data or multi-turn conversational responses, ensuring the agent systematically completes processing within a designated duration.
