Skip to main content
In tasks such as multi-turn reasoning, multi-hop Q&A, or multi-turn retrieval, a single execution process often fails to obtain an ideal final answer. In this case, a Loop Structure can be used to repeatedly execute specific modules, thereby achieving iterative information refinement and continuous result optimization.

Usage Example

https://mintcdn.com/ultrarag/T7GffHzZitf6TThi/images/yaml.svg?fit=max&auto=format&n=T7GffHzZitf6TThi&q=85&s=69b41e79144bc908039c2ee3abbb1c3bexamples/rag_loop.yaml
# MCP Server
servers:
  benchmark: servers/benchmark
  retriever: servers/retriever
  prompt: servers/prompt
  generation: servers/generation
  evaluation: servers/evaluation
  custom: servers/custom

# MCP Client Pipeline
pipeline:
- benchmark.get_data
- retriever.retriever_init
- generation.generation_init
- retriever.retriever_search
- loop:
    times: 3
    steps:
    - prompt.gen_subq
    - generation.generate:
        output:
          ans_ls: subq_ls
    - retriever.retriever_search:
        input:
          query_list: subq_ls
        output:
          ret_psg: temp_psg
    - custom.merge_passages
- prompt.qa_rag_boxed
- generation.generate
- custom.output_extract_from_boxed
- evaluation.evaluate
In the loop structure, the Pipeline uses the following keywords to define tool modules that need to be executed repeatedly:
  • loop: Declares a loop block, indicating that the steps inside it will be executed repeatedly;
  • times: Specifies the maximum number of iterations for the loop;
  • steps: Defines the sequence of tool calls to be executed in each round of the loop.
If you wish to dynamically control loop termination conditions, you can use it in conjunction with the Branch Structure (branch) and Router Server. See Branch Structure for details.