Loop
Learn about loop and how to implement it effectively.
Loop (Agentflow Node)
The Loop node in InnoSynth-Forjinn's Agentflow provides a mechanism to create iterative workflows by looping back to a previous node in the canvas. This is particularly useful for implementing retry mechanisms, continuous monitoring, or conversational loops where the AI needs to re-evaluate or re-engage based on certain conditions.
Purpose
The Loop node is designed for:
- Retry Mechanisms: Re-attempting a failed operation a specified number of times.
- Conversational Loops: Guiding a user through a series of questions or steps until a condition is met.
- Continuous Processing: Repeatedly executing a segment of the workflow.
- Error Handling: Looping back to a previous state if an error occurs, allowing for recovery attempts.
Appearance on Canvas
(Image: Placeholder for the Loop node icon/appearance on the canvas)
Configuration Parameters
The Loop node requires you to specify the target node to loop back to and a maximum iteration count.
1. Loop Back To (Required)
- Label: Loop Back To
- Type:
asyncOptions(loads previous nodes) - Description: Select the specific node in your current workflow that the execution should loop back to. This allows you to define the starting point of your iterative process.
- Hint: Make sure to have memory enabled in the LLM/agent node to retain the chat history if you are looping in a conversational context.
2. Max Loop Count (Required)
- Label: Max Loop Count
- Type:
number - Default:
5 - Description: The maximum number of times the loop will execute. This is a critical safeguard to prevent infinite loops and ensure your workflow eventually terminates.
Inputs & Outputs
- Input: The Loop node typically receives a trigger from a preceding node, indicating that the loop condition has been met or a retry is needed.
- Output: This node does not have a visible output port on the canvas, as its primary function is to redirect the workflow's execution flow back to a previous node. The
hideOutputproperty is set totrue.
How it Works During Execution
When the workflow reaches a Loop node:
- It identifies the
Loop Back Totarget node. - It checks the current loop count for the specific execution path.
- If the
Max Loop Counthas not been reached, the workflow's execution pointer is reset to theLoop Back Tonode, and the process within the loop restarts. - If the
Max Loop Counthas been reached, the loop terminates, and the workflow typically proceeds to any nodes connected after the loop block (if any, though often a loop is the end of a specific branch).
Example Usage: Retrying an API Call
Consider a scenario where an API call might occasionally fail, and you want to retry it a few times before giving up.
- Connect an
HTTPnode (making an API call) to aconditionnode. - Configure
condition: Check if theHTTPnode's output indicates an error (e.g.,{{http.status}}is larger equal400). - Connect
conditionOutput (Error Path): Connect the output for the error condition to aLoopnode. - Configure
Loop:- Loop Back To: Select the
HTTPnode. - Max Loop Count:
3
- Loop Back To: Select the
- Connect
conditionOutput (Success Path): Connect the output for the success condition to aChat Outputnode. - Connect
LoopOutput (Implicit Fallthrough): If the loop maxes out, the workflow would implicitly continue to a "Handle Error" node (not directly connected to the Loop node, but as a fallback in the overall flow design).
This setup will retry the HTTP call up to 3 times if it fails, providing resilience to your workflow.