> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tryhamsa.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Router step

> Send each call down the right path with a Router step: write conditions on your variables, learn the operators, the order they're checked in and Else.

A Router step picks the next step by checking your variables against conditions. It doesn't speak and doesn't ask the model: it compares values and sends the call down the first path that matches, or down **Else** when none does.

## When to use it

* To branch on a value you already have: an amount from an API, a status, a language, an answer the caller gave earlier.
* To check that a value exists before you use it, for example to skip a lookup when you already know the caller.
* To branch right after a [Tool step](https://docs.tryhamsa.com/agents/flow/steps/api-request.md), on what the API returned.

To branch on what the caller says next, use a **Prompt** transition on a [Conversation step](https://docs.tryhamsa.com/agents/flow/steps/conversation.md) instead. The router has no **Prompt** transitions.

## Add a Router step

**1. Add the step**

On the canvas, click **Add node** and choose **Router** ("Logic splitting node with conditional routing"). The panel explains: "Router nodes are configured through their transitions."

![The Order status Router step panel with its explanation and the Transitions, Variables and Global sections](https://mintcdn.com/hamsa-452fa79a/Rl78D_qJIpinmg19/images/agents/flow/steps/router-step-light.webp?fit=max\&auto=format\&n=Rl78D_qJIpinmg19\&q=85\&s=4ae0bbed1cf99aa92c54fe45af950b75)

**2. Add a path**

Open **Transitions**, click **Add new transition** and choose **Equation** ("Rule-based condition").

**3. Write its conditions**

In **Conditions**, pick a variable, an operator and a value. Click **Add condition** for more, and choose **All** or **Any** "of the following conditions match". Click **Save**.

**4. Connect the paths**

On the canvas, connect each path to its next step. Connect **Else** too.

![The Conditions of a router path: All of the following conditions match, order\_status equals shipped, and days\_late greater than 0](https://mintcdn.com/hamsa-452fa79a/Rl78D_qJIpinmg19/images/agents/flow/steps/router-conditions-light.webp?fit=max\&auto=format\&n=Rl78D_qJIpinmg19\&q=85\&s=727acf660bb1907b79aa901e99170325)

## Conditions

Each condition compares a variable with a value. The value can be text, a number, or another variable written as `{{variable_name}}`.

| Operator | Matches when the variable | Example |
| - | - | - |
| **Equals (=)** | is exactly the value | `plan` equals `gold` |
| **Does not equal (≠)** | is anything other than the value | `status` does not equal `closed` |
| **Greater than (>)** | is a number above the value | `balance` greater than `0` |
| **Smaller than (\<)** | is a number below the value | `age` smaller than `18` |
| **Greater than or equal to (≥)** | is a number at or above the value | `score` greater than or equal to `80` |
| **Smaller than or equal to (≤)** | is a number at or below the value | `attempts` smaller than or equal to `3` |
| **Contains (∋)** | contains the value somewhere in it | `email` contains `@company.com` |
| **Does not contain (∌)** | doesn't contain the value | `notes` does not contain `urgent` |
| **Exists (∃)** | has a value that isn't empty | `customer_id` exists |
| **Does not exist (∄)** | is missing or empty | `customer_id` does not exist |
| **Matches regex (.\*)** | matches a regular expression anywhere in it | `postcode` matches `^[0-9]{5}$` |

How values are compared:

* **Equals**, **Does not equal**, **Contains** and **Does not contain** compare text, and capital letters count: `Gold` doesn't equal `gold`.
* A yes or no value that the agent extracted reads as `True` or `False`, with a capital letter. Compare with `True`, not `true`.
* **>**, **\<**, **≥** and **≤** compare numbers. If either side isn't a number, the condition doesn't match. With these four, the editor asks for a number or a variable: "Use a number or a variable here."
* **Matches regex** finds the pattern anywhere in the value. Add `^` and `$` to match the whole value. Click **Launch tester** to try your expression on sample text in the **Regex tester**. An invalid expression shows "This is not a valid regular expression."
* If the variable has no value yet, every operator except **Exists** and **Does not exist** doesn't match.

## The order paths are checked in

The router checks its paths in the order you added them: the first path you added is checked first, and the first path whose conditions match wins. **Else** is always checked last.

The step's panel and the card on the canvas list the paths in that order, top to bottom, with **Else** at the bottom. You can't reorder paths. If two paths could both match, make their conditions exclusive, or add them in the order you want them checked.

A path that isn't connected to a step is skipped.

## Else

Every router has an **Else** path. You can't delete it, and it always stays at the bottom. The call takes **Else** when no other path matches.

If nothing matches and **Else** isn't connected, the agent says "No router path" and ends the call. Always connect **Else**, even if only to a step that asks the caller again or transfers them.

## Other sections

* **Variables**: add a **Local variable** to set a value when the call reaches the router. Local variables are set before the conditions are checked, so a condition can read one.
* **Global**: includes **Confirm before proceeding**. See [Global steps](https://docs.tryhamsa.com/agents/flow/global-steps.md).

## How it works on a call

1. The router's local variables are set.
2. Each path's conditions are checked, in the order above. The first match sends the call to its step.
3. If nothing matches, the call takes **Else**.

The caller hears nothing from the router itself. The next step that speaks also answers anything the caller said in the meantime.

## Related

> [card] [Transitions](https://docs.tryhamsa.com/agents/flow/transitions.md)
>
> All transition types, including Skip if, which uses the same conditions.

> [card] [Variables](https://docs.tryhamsa.com/agents/variables/overview.md)
>
> Where the values you compare come from.

> [card] [Tool step](https://docs.tryhamsa.com/agents/flow/steps/api-request.md)
>
> Save values from an API, then route on them.

> [card] [Set local variables step](https://docs.tryhamsa.com/agents/flow/steps/set-variables.md)
>
> Set flags and counters to route on later.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.