In tasks such as multi-turn reasoning, multi-hop question answering, and multi-turn retrieval, a single execution process is often insufficient to obtain the final answer. In such cases, a loop structure is needed to repeatedly execute certain modules, gradually iterating information and enhancing the generated results.

Example: Multi-turn Subquestion Generation and Retrieval Process

Below is a typical multi-turn RAG reasoning process, where each turn includes:
  1. Performing retrieval based on the current question or context;
  2. Generating new subquestions based on the retrieval results;
  3. Calling a large model for generation.
We set this process to execute up to 3 turns, and then generate the final answer.
pipeline:
  - benchmark.get_data
  - retriever.retriever_init
  - loop:
      times: 3  # Maximum number of loop executions       
      steps: # Define the pipeline within a single loop iteration
        - retriever.retriever_search
        - prompt.generate_subquery
        - generation.generate
        
  - prompt.generate_final_answer
  - generation.generate

Explanation

  • loop: Declares a loop block, indicating that the subsequent steps will be executed repeatedly;
  • times: Sets the maximum number of loop iterations (3 times in the example above);
  • steps: Defines the sequence of tool calls to be executed in each iteration, written in the same way as a serial structure.
The current loop exit logic is based on a fixed number of iterations (i.e., exit after executing times times). If you want to dynamically control whether to exit the loop based on the model’s generated results, you can use it together with the branch structure (branch) and Router Server, as detailed in the next section.