In complex reasoning tasks, we often need to decide whether to continue the process based on the model’s current output or intermediate state. For example:
  • If the model generates a query, proceed to the next round of retrieval;
  • If the model has generated the final answer, end the process.
To achieve this capability, UR-2.0 provides the branch structure (branch), which is used to build dynamic reasoning flows 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 status label to drive the flow direction.
If you have not yet learned how to implement the Router Tool, please refer to Router Server.

Example: Dynamically decide whether to enter the next round of retrieval

The following pipeline judges after each generation: whether the current content is a query or the final answer. If it is a query, proceed to the next round of retrieval and generation; otherwise, end the process.
servers:
  router: servers/router
  ...

pipeline:
  - benchmark.get_data
  - retriever.retriever_init

  - prompt.generate_query_or_answer
  - generation.generate

  - loop:
      times: 3         
      steps:
      - branch:
          router:
            - router.check_query_or_answer   # output e.g. status=is_query/is_answer
          branches:
            is_query:
              - retriever.retriever_search
              - prompt.generate_query_or_answer
              - generation.generate

            is_answer: []    # is_answer means terminate and output the answer

  - evaluation.evaluate
Explanation
  • branch: indicates the start of a branch structure.
  • router: specifies the Router Tool used to determine the branch logic (usually returns a status label such as is_query / is_answer).
  • branches: defines the sequence of steps to execute under each state, where the key is the state label and the value is the corresponding list of steps to execute (an empty list means termination).
  • The keys defined in branches must correspond to the state values returned by the Router tool.
With the branch structure, UR-2.0 not only supports flexible combinations of multi-round processes but also enables dynamic judgment and strategy control, allowing you to build truly controllable and reasoning-capable RAG systems.