Skip to main content
In complex reasoning tasks, it is often necessary to decide whether the subsequent process should continue based on the model’s intermediate output or current state. For example, judging the content generated by the model:
  • If the model generates a new query, enter the next round of retrieval;
  • If the model has output the final answer, terminate the process.
To achieve the above capabilities, UltraRAG provides a Branch Structure for building controllable reasoning processes with conditional jump logic.
The Router Server is the partner of the branch structure. It is responsible for judging the current state and returning a state label to drive the process direction.
If you do not yet know how to implement a Router Tool, please refer to Router Server.

Usage Example

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

# MCP Client Pipeline
pipeline:
- benchmark.get_data
- retriever.retriever_init
- generation.generation_init
- retriever.retriever_search
- loop:
    times: 10
    steps:
    - prompt.check_passages
    - generation.generate
    - branch:
        router:
        - router.check_model_state
        branches:
          continue:
          - 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
          stop: []
- prompt.qa_rag_boxed
- generation.generate
- custom.output_extract_from_boxed
- evaluation.evaluate
In the branch structure, the Pipeline uses the following keywords to define the control logic of the dynamic process:
  • branch: Declares the starting point of a branch structure;
  • router: Specifies the Router Tool used for judging branch logic, which needs to return a state label (such as incomplete / complete);
  • branches: Defines the sequence of execution steps corresponding to each state. The key is the state label, which must be consistent with the state value returned by the Router Tool; the value is the list of steps to be executed under that state (can be empty, indicating process termination).