# Router

The Router piece allows you to create conditional branches in your workflow, directing the flow based on specific conditions.

### **How to Use the Router Piece in ZBrain Flow?** <a href="#how-to-use-the-router-piece-in-zbrain-flow" id="how-to-use-the-router-piece-in-zbrain-flow"></a>

**Step 1: Select Router as Your Connection**

* Click on the '+' button in the Flow and search for Router.
* Select Router.

**Step 2: Configure Execution Behavior**

After adding the Router piece to your workflow, you'll see it creates two default paths: "Branch 1" and "Otherwise." The Router will evaluate conditions and direct your flow accordingly.

Under the ‘Execute’ dropdown, choose how you want multiple conditions to be handled:

* **Only the first (left) matching branch**: This option creates an exclusive branching pattern. The Router evaluates branches from left to right, and as soon as it finds a branch with conditions that evaluate to true, it executes only that branch and stops checking further branches. This is similar to a switch statement in programming, where the first matching case is executed, and the rest are ignored unless explicitly configured otherwise.
* **All matching paths from left to right**: This option allows multiple branches to execute in parallel if their conditions are met. The Router evaluates all branches from left to right, and any branch whose conditions are evaluated to true will be executed. This behavior is more like having multiple independent "if" statements.

**Step 3: Set Up Branch Conditions**

Click on the ‘Branch’ option to configure its condition:

1. When configuring a branch, you'll see these condition options:

   1. In the ‘Execute If’ section:
      * **First value**: Enter the value or variable to evaluate
      * **Operator**: Select from dropdown options including:
        * Contains
        * (Text) Does not contain
        * (Text) Exactly matches
        * (Text) Does not exactly match
        * And many other comparison options
        * Exists
        * (List) Is empty
        * And many other comparison operators based on data type
      * **Second value**: Enter the comparison value (if applicable)
   2. For multiple conditions:
      * Use ‘And If’ section to add conditions
      * Each additional condition has its own set of:
        * First value field
        * Operator dropdown (like "(List) Is empty")
        * Second value field (when applicable)
   3. Condition management:
      * Click on ‘Remove’ button to delete a specific condition
      * Press the ‘+ And’ button to add another required condition
      * Use '+ Or' button to add an alternative condition

   This allows you to build complex conditional logic with multiple variables and operators to precisely control your workflow's branching behavior.

**Step 4: Add More Branches If Needed**

Click the '+' button to create additional conditional paths beyond the default two.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.zbrain.ai/zbrain-documentation/zbrain-builder/flows/flow-components/router.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
