Table of Contents

Flow logic: how your agent decides what comes next

Desirée M Updated by Desirée M

Flow logic is how a Landbot agent decides which block comes next: it checks what the visitor said or did and sends them down the path that fits. Most decisions use a few logic blocks, mainly the Conditions block to check a saved answer and the Formulas block to calculate or change a value.

What do you need to know before you add flow logic?

Before you add flow logic, make sure you know three basics, which How to build an agent in Landbot explains step by step:

● Outputs: every conversation starts at the Starting Point and moves to the next block through outputs. A block that branches has one output per path, such as one per button in a Buttons block. See How do blocks connect to the next step?

● Fields: question blocks save the visitor's answers in Fields, so later blocks can check them. See How do Fields keep the visitor's answers? and Managing Data in Your Agent: A Guide to Using Fields.

● Any of the above: one output for all the buttons that lead to the same next step. See the Any of the above Output article.

Fields can also get a value without asking the visitor: Landbot System Fields are filled in for you, a Set a Field block gives a Field the value you choose, and Hidden Fields take values from the page URL.

How to split the conversation based on a saved answer

To split the conversation based on a saved answer, add a Conditions block: it checks a Field and sends the visitor down its green output when the condition is true, or its red output when it's false. Use it when the next step depends on something the visitor said earlier. A choice the visitor just made with a button doesn't need one, because each button already has its own output.

In this example, a plant shop agent, Leafy Corner, asks how many hours of direct sun the visitor's spot gets with an Ask for a number block and saves the answer in @sun_hours. A Conditions block then checks whether @sun_hours is GREATER THAN 4:

● Green output (true), more than 4 hours of sun: "Plenty of light! ☀️ An Aloe vera will love that spot."

● Red output (false), 4 hours or fewer: "A shadier spot, then. 🌱 A Snake plant is happy with little light."

Conditions block checking if sun_hours is greater than 4, with the green output to the Aloe vera reply and the red to the Snake plant reply

Both replies lead to an "Anything else?" question in the Leafy Corner agent, and its Back to menu button connects to the first block again. A connection back to an earlier block lets visitors go round as often as they like, without you building the menu twice.

Leafy Corner flow with a menu, a sun-hours question, a Conditions block with two replies, a care tip and an Anything else menu

Besides GREATER THAN, a Conditions block can check whether a Field is EQUAL TO, CONTAINS or IS SET, and combine several checks so that all of them, or just one, must be true. Conditions block: check Fields and split the conversation shows each operator with an example. To check dates, the visitor's device or country, or whether a team member is online, see Conditions block: check dates, visitors and team members online.

How to calculate or change a value with Formulas

To calculate or change a value, use the Formulas block: it works a value out with a function and saves the result in a Field. Reach for it when a Conditions block can't do the job on its own, such as adding up a score, cleaning up text before you compare it or comparing two Fields.

Pick a formula by the kind of value it works on. To write your first one, follow Get started with the Formulas block.

● Logical formulas: combine checks or choose between two values.

● Comparison formulas: compare values, including two Fields.

● Math formulas: calculate with numbers.

● String formulas: change and clean up text.

● Date formulas: work with dates and times.

● Array formulas: work with lists.

● Object formulas: read values from structured data, such as an API response.

● Regex formulas: find or check text that follows a pattern.

Which block do you need?

The block you need depends on what your agent should decide or do next:

● Give each answer its own path: Buttons block

● Save a value without asking the visitor: Set a Field block

● Decide based on a saved answer: Conditions block: check Fields and split the conversation

● Decide based on the date, the visitor or team members online: Conditions block: check dates, visitors and team members online

● Calculate or transform a value: Get started with the Formulas block

● Take a different path when you're closed: Business Hours block

● Score leads based on their answers: Lead Scoring block

● Split visitors at random to compare two versions: How to split bot traffic with the A/B Test block

● Jump to another part of the flow or another agent: Jump To block

● Send visitors down a path based on the words they type: Keyword Jump

● Let visitors jump to a part of the flow from anywhere by typing a word: Global Keywords

● Keep a menu of options open during the whole conversation: Persistent Menu

● Organize a large flow into groups of blocks: Organize your flow with Bricks

● Reuse a Brick in your other agents: Brick Templates

Every logic block, with its setup, is in the Logic & Technical blocks library.

For WhatsApp

● Let visitors type a keyword instead of tapping a button: Keyword Options, also on Facebook Messenger

● Show returning visitors a different flow: WhatsApp: Show a Different Flow on Return Visits

● Repeat a part of the flow a set number of times: Creating a Loop in WhatsApp

● Get a visitor out of a question they keep failing: WhatsApp - Get user out of error message loop

How to avoid common flow logic mistakes

Most flow logic mistakes leave a visitor stuck or send them down the wrong path. Three habits prevent them:

● Leave no dead ends. Connect both outputs of every Conditions block, and an output for every button. A visitor who reaches an unconnected output ends the conversation there, usually without meaning to.

● Give a Field a value before a Conditions block checks it. When a Conditions block compares an empty Field with GREATER THAN or LESS THAN, the conversation stops at that block and takes neither output. An empty Field also goes down the green output of DOES NOT EQUAL TO and the red output of EQUAL TO. Ask for the value earlier in the flow, or give the Field a starting value with a Set a Field block.

● Compare text in lowercase. EQUAL TO in a Conditions block is an exact match, capitals included, so Aloe vera and aloe vera don't match. Turn the visitor's answer into lowercase with the Lower() formula from String formulas before you check it. To catch a mismatch like this, show the Field's value in a message right before the Conditions block, as How to find out why a Conditions block takes the wrong path explains.

How to keep a large flow easy to manage

To keep a large flow easy to manage, build it from small parts that each do one job, so you can read, test and fix each part on its own.

● Use several small Formulas blocks instead of one long formula. A formula with functions nested inside each other is hard to read, and when it fails you can't tell which function went wrong.

● Split a crowded Conditions block. When one Conditions block checks many things at once, use several blocks in a row, each with one clear question.

● Reuse a part of the flow instead of copying it. Group the blocks into a Brick and send visitors to it with a Jump To block, or connect back to it, as the Leafy Corner agent's Back to menu button does.

How to test your flow logic

To test your flow logic, take every path at least once and try values on both sides of each condition, such as 6 and 4 hours of sun for the Leafy Corner agent. Test your changes in Preview before you publish, then the live agent with its share link, as How to Test Your Bot explains.

When a path goes somewhere you didn't expect, show the Field it depends on in a message right before the block that decides. How to debug your agent's flow without code walks through it step by step.

Was this article helpful?

Organize your flow with Bricks

How to test your agent