# Branching

> How the agent decides which path to take — and the mistakes that send it down the wrong one.

Source: https://docs.cleartalk.ai/docs/pathways/branching

Branching is where pathways earn their keep, and where most of them go wrong. The mechanics are simple; the discipline is in the wording.

<Summary
  items={[
  "The label on a line is the condition — never leave one blank.",
  "Write labels as opposites, so no answer fits both.",
  "Always build the unhappy path: not found, none available, lookup failed.",
  "Make sure the agent already knows what a branch depends on.",
]}
/>

## The line is the condition

When you connect two steps, the **label on that line** is what tells the agent when to take it. The agent reads your labels and picks the one that matches what just happened.

<Screenshot
  src="/img/pathway-branches.png"
  alt="Two labelled lines leaving a greeting step on the pathway canvas, one reading “Wants work done” and the other “Just has a question”."
  caption="One step, two ways out. The labels are what the agent reads to choose between them."
  pins={[
  { x: 75, y: 30.7, from: "bottom", label: "Caller wants information — this path answers and stops." },
  { x: 56.4, y: 29.6, from: "left", at: 45, label: "Caller wants us on site — this path qualifies and books." },
]}
  redactions={[{ x: 3.4, y: 93.6, w: 11.6, h: 5.2, reason: "Account name and email hidden" }]}
/>

Click a line to edit its label:

<Screenshot
  src="/img/pathway-edge-settings.png"
  alt="The Edit edge panel open beside the canvas, with a Label field containing “Wants work done” and help text saying the agent reads it to decide whether to follow the edge, and a Description field below it marked as a note for your team."
  caption="Click a line to edit its label. The label is the whole condition."
  pins={[
  { x: 20.9, y: 33.5, from: "left", at: -2, label: "Be specific. This sentence is the entire instruction the agent gets." },
  { x: 20.9, y: 51.3, from: "left", at: -2, label: "Description is for your team. The agent never reads it." },
]}
  redactions={[{ x: 3.4, y: 93.6, w: 11.6, h: 5.2, reason: "Account name and email hidden" }]}
/>

Under the label, **Description** holds a note for your team — why this path exists, what it's waiting on. The agent doesn't read it, so it never changes how the conversation routes.

The label is different: it's an instruction, not decoration.

<DoDont
  goodTitle="Labels the agent can act on"
  badTitle="Labels that make it guess"
  good={[
  "“Caller wants to book an appointment”",
  "“Caller has a question about pricing”",
  "“Caller is an existing customer”",
  "“Caller says it's a bad time”",
]}
  bad={["“yes”", "“other”", "“path 2”", "(left blank)"]}
/>

Two rules follow from this:

1. **Never leave a line unlabelled** when a step has more than one way out. The agent is guessing.
2. **Make labels mutually exclusive.** If two labels could both plausibly describe the same answer, you've built a coin flip. "Caller is interested" and "Caller wants more information" overlap badly — merge them, or sharpen the distinction until a reader could sort answers into one or the other without hesitating.

### Opposites make the best labels

There's a reliable way to get rule 2 right: &#x2A;*write the pair as opposites.** If one label is the negation of the other, no answer can fit both, and there's no gap between them for an answer to fall into.

<DoDont
  goodTitle="Pairs that can't overlap"
  badTitle="Pairs that leave the agent to judge"
  good={[
  "“Wants work done” / “Just has a question”",
  "“In our area” / “Outside our area”",
  "“Existing customer” / “New customer”",
  "“Ready to book” / “Not booking today”",
]}
  bad={[
  "“Interested” / “Wants more information”",
  "“Urgent” / “Important”",
  "“Qualified” / “Other”",
  "“Positive response” / “Neutral response”",
]}
/>

When a step has three or more ways out, the same test still applies to every pair: take any two labels and ask whether one answer could reasonably be filed under both. If it could, you've found the branch that will misfire.

Drawn out, a well-labelled fork looks like this — each way out says what the caller did, not which option it is:

<PathwayBranches
  from="Are you an existing customer?"
  fromType="Route"
  caption="Three ways out, each label a description of the caller's answer."
  paths={[
  { label: "Existing customer", to: "Look up their account", toType: "Custom Tool" },
  { label: "New customer", to: "Collect their details", toType: "Default" },
  { label: "Caller isn't sure", to: "Check by phone number", toType: "Custom Tool" },
]}
/>

## When to use a Route step instead

Hanging labelled lines off a Default step works well for two or three ways out. When branching is the actual purpose of the moment — sorting callers by department, by product, by eligibility — use a **Route** step. It keeps the decision in one obvious place, and it takes a **fallback** path for anything that matches nothing.

Always set the fallback. It's the difference between "I'm not sure I follow — let me get someone who can help" and a conversation that dead-ends.

## Branching on what came back

Steps that reach outside the conversation — Custom Tool, Webhook — can branch on their result. This is how you handle the real world:

* Order found → confirm the details. Not found → offer to take a message.
* Slots available → offer them. None → route to the waitlist.
* Lookup failed → apologise and transfer, rather than pretending.

Always build the unhappy path. Systems are down sometimes, and a caller hearing dead air while the agent waits for a response that never comes is the worst outcome in the product.

## Capture before you branch

If a branch depends on knowing something — an account number, whether they're a current customer, which location they mean — make sure an earlier step actually asked. Pathways commonly fail because the decision point arrives before the information does. Reading yours top to bottom and asking "does the agent know this yet?" at each branch catches nearly all of these.

When the information is genuinely required, don't rely on the caller volunteering it — put a **loop condition** on the step that collects it, so the agent won't move on without it. See [Inside a step](/docs/pathways/writing-steps).

## Don't branch for things that happen everywhere

A question that could come up at any moment — pricing, hours, "can I speak to someone?" — should not be a branch off every step. That's what [global steps](/docs/pathways/global-nodes) are for: one step, reachable from anywhere, that answers and hands the conversation back. Building those as ordinary branches is the most common cause of an unreadable canvas.

## Common mistakes

* **Too many branches too early.** Sort callers into two or three groups first, then refine inside each. A step with nine ways out is unreadable and unreliable.
* **Branching on things that don't change the conversation.** If both paths say the same thing, you don't need a branch.
* **No way back.** A caller who takes a wrong turn should be able to get where they meant to go. Add a path back to the main line rather than a dead end.
* **Assuming a clean answer.** People reply "yeah I guess so" and "well, sort of". Labels written as full descriptions of intent handle that far better than "yes" and "no".
* **Labels that point somewhere else.** "The second option listed above" or "matches the department the caller picked" gives the agent nothing to match against — it reads each label on its own, with none of the surrounding context. Write the condition out in full on the label.
* **Branching where a prompt would do.** If a fork exists only because two things get asked, it doesn't need to be a fork. [How many steps do you need?](/docs/pathways/pathway-shape) is the fuller version of this.

## Prove it

Branching is exactly what automated tests are for — a simulated caller who gives an ambiguous answer will find your overlapping labels immediately, and much more cheaply than a real customer will. Write one test per branch: [Testing your pathway](/docs/pathways/testing).
