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

# Branches and Conditions

> Buttons, branches the AI decides, rule conditions, and global intents

A flow branches in four places: on a **reply to buttons** (Send buttons, Send template), at a **Condition**, on a **Custom function**'s success or failure, and through **global intents** that apply anywhere.

## Replies to buttons

On a Send buttons step and on a Send template step, the user's reply is checked in this order — the first match wins:

**1. Buttons**

A tap on a button takes that button's branch. A typed reply with the same words does too.

Give a button an **Also when** and a typed reply that matches it goes the same way as a tap:

> **Yes** — Also when: *The user types anything positive: yes, ok, haan, sure, 👍*

**2. Branches the AI decides**

For replies that are not a tap. Each has a name (shown on the canvas with an **AI** tag) and a **When** in words:

> **Not interested** — When: *The user says no, or that they are not interested*

> **Asks the price** — When: *The user asks about prices, fees or packages*

These are never sent as buttons; the AI uses them to sort what the user typed.

**3. Anything else**

Everything that matched nothing. Connect it to a step, or leave it empty: the AI then answers the message briefly and sends the same step again.

So a template with a single **Yes** button can still handle "No, I'm not interested" and "how much is it?" — each typed reply goes to its own step.

On the canvas, a button that also has an **Also when**, and every branch the AI decides, carry a small **AI** tag; hover it to read the condition.

## Condition steps

A Condition has one or more branches, then **Otherwise**. Branches are checked top to bottom and the first true one wins.

### Rule (checked by code)

Compares a value with a fixed one:

| Left side | Operators | Right side |
| - | - | - |
| A contact attribute (or `phone_number`) | equals, does not equal, contains, is greater than, is less than, is empty, is not empty | A value (not needed for "is empty" / "is not empty") |
| A field of a function's result, by path (`data.status`, `slots`) | | |

Code checks a rule and tells the AI the result, so a rule is never guessed:

* **Contact rules** are checked at the start of every turn.
* **Function-result rules** are checked the moment the function returns, and the result is attached to what the AI reads from it.

Text compares ignore case. "Is greater than" and "is less than" compare numbers.

### AI judges (prompt)

A condition in words, for anything code cannot check: *"The user sounds ready to buy"*, *"The lead's latest message is in Hindi"*. The AI decides it from the conversation.

### A language router

A common pattern: three branches that pick a language-specific step.

| Branch | Condition |
| - | - |
| Hindi | *The conversation language for this turn is Hindi: the latest message is Hindi or Hinglish* |
| Tamil | *The conversation language for this turn is Tamil* |
| Otherwise | → the English step |

Put one before every step that has per-language variants (a template in three languages, for example).

## A function's success and failure

A **Custom function** step has two exits. **Failure** is taken when the function raised an error, timed out, or returned an error result (`{"status": "error", ...}`). Connect it — to a retry, an apology, or a call offer — rather than leaving the conversation stuck.

## Global intents

A **Global intent** applies at any point: when its trigger matches, the conversation detours to its branch.

| Trigger | Branch |
| - | - |
| The user asks to talk to a person | Send contact card → (unconnected) |
| The user says they want to stop (opt-out) | End: "You won't get any more messages." |
| Distress or self-harm | End: a care message with a helpline |

When the branch's last exit is unconnected, the AI goes back to the step the conversation was on. End the branch with an **End** step when the detour should close the conversation.

## What the AI weighs in a turn

The AI judges these together; written down, the plan reads:

1. Does a global intent apply to this message? Then take its detour.
2. Otherwise, the step the conversation is on: its buttons, then its AI branches, then anything else.
3. For a step that does not wait, carry on to the next step — conditions are evaluated on the way through.

Instructions and rebuttals in the [persona](/chat-agents/advanced/persona) shape every reply along the way, and side questions are answered before the AI steers back to the step.


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