Skip to main content

Using loop properties

This document describes how to use loops.

To meet more diverse orchestration needs, the flow orchestration feature has been fully upgraded to workflow applications and agent orchestration applications. The flow orchestration feature will be gradually unpublished. However, this change does not affect users who are already using the flow orchestration feature. You can continue to use the flow orchestration feature, or switch to workflow applications or agent orchestration applications for a better experience. For more information, see workflow applications and agent orchestration applications.

Overview

When you use large language models (LLMs), some scenarios require loops. For example, to generate multiple assessment data entries with an LLM, you can execute the current LLM node multiple times. This method avoids adding multiple nodes or making multiple application calls. The intermediate results of a loop are closely related to the implementation of your business logic. To help you easily control the number of iterations and the exit conditions, loops are available as a node property extension.

Loop properties

image
Loop properties take effect only after you enable the loop feature. You can configure the following five properties:
  1. Maximum Loop Count: The maximum number of iterations. If the Stop Condition is not met, the loop runs for the specified number of iterations. The default value is 2 and the maximum value is 10.
  2. Loop Collection Variable: When a node loops, each iteration produces a result. This variable stores the results of all iterations as a list.
  3. Current loop variable: The result of each loop iteration is stored in this variable. You can use this variable to retrieve the result of the final iteration or to set a termination condition. 4. Loop count variable: The total loop count is stored in this variable. You can use this variable to set a termination condition. For example, if this.loopCount == 2, the loop runs twice and then exits.
Loop Count Variable
  1. Set Stop Condition: In the Set Stop Condition section, you can configure condition groups to exit the loop. The matching logic is similar to that of a logic node. The difference is that this condition can reference the loop properties of the current node, such as this.loopCount for the current number of iterations, this.finalItem for the result of the current iteration, and this.list for the list of loop results. The loop exits when the stop condition is met.
As shown in the following figure:
image

Supported scope

Currently, only large model nodes support loop properties. Support for other nodes will be added in the future based on demand.

Example result

Loop debug results
image

Loop result display

{
  "finalResult": {
    "LLM_UItAJj": {
      "loopResult": {
        "stopReason": "Stop condition met", // Reason for exiting the loop. Two reasons are possible: stop condition met or maximum loop count reached.
        "testList": [
          {
            "params": {
              "modelId": "qwen-max", // qwen-max is used as an example. You can change the model name as needed. For a list of models, see https://help.aliyun.com/en/model-studio/models
              "prompt": "Output a famous quote from Lu Xun. Do not output the quotes mentioned below: ${svcVars.LLM_UItAJj.loopResult.testList.#response.text#}. Output only the quote itself."
            },
            "response": {
              "text": "Originally, there was no road on the ground. As more people walk on it, a road is made."
            }
          },
          {
            "params": {
              "modelId": "qwen-max",
              "prompt": "Output a famous quote from Lu Xun. Do not output the quotes mentioned below: ${svcVars.LLM_UItAJj.loopResult.testList.#response.text#}. Output only the quote itself."
            },
            "response": {
              "text": "Time is like water in a sponge. If you are willing to squeeze, there is always some."
            }
          },
          {
            "params": {
              "modelId": "qwen-max",
              "prompt": "Output a famous quote from Lu Xun. Do not output the quotes mentioned below: ${svcVars.LLM_UItAJj.loopResult.testList.#response.text#}. Output only the quote itself."
            },
            "response": {
              "text": "Erupt in silence, or perish in it."
            }
          }
        ],
        "loopCount": 3, // Number of completed iterations
        "isStop": true, // Indicates whether the loop has ended
        "testItem": "Erupt in silence, or perish in it." // Result of the last iteration
      },
      ...
    }
  }
}
Token Plan
Model Playground
Fine-tuning
Model Compression
Statistics and Monitoring
Support