# Flows and agents

> When to script a conversation with a flow, when to let an agent improvise, and who answers each message.

Ñomongeta gives you two ways to answer people, and they work best together.

| | An agent | A flow |
| --- | --- | --- |
| How it answers | Improvises from its instructions and knowledge, in its own words. | Follows the steps you drew, word for word. |
| Good at | Open questions, conversation, explaining. | Menus, bookings, forms, checks, calling your systems, routing to people. |
| Predictable | Mostly. Guardrails help. | Fully: same input, same path. |
| Costs | Tokens on every reply. | Nothing for the steps; tokens only for AI steps. |

A common pattern: a flow greets people with a menu and takes care of the scripted parts (opening hours, a booking, a lead form), and an [AI step](https://nomongeta.zenhalab.com/www/nomongeta/en/docs/flow-builder/ai-agent) or the agent itself handles everything open-ended.

## Who answers a message

Every channel (the website widget, a WhatsApp number, an e-mail inbox) is answered by an **agent**, and may also have a **flow** that answers first. When a message arrives, Ñomongeta checks in this order:

1. **A run already waiting.** If a flow asked a question in this conversation and is waiting for the answer, the message is that answer. While a flow is waiting for a timer, a web request or a person, new messages are kept in the conversation without starting anything.
2. **A trigger.** Among the workspace's live flows, the first [trigger](https://nomongeta.zenhalab.com/www/nomongeta/en/docs/flow-builder/triggers) that matches starts its flow: keywords first, then "a new contact", then "messages on a channel", then "any message".
3. **The channel's flow.** The flow picked for the channel in **Channels** starts at its start step.
4. **The agent.** Nothing else took the message, so the channel's agent replies.

When a person from your team has the conversation, none of this happens: messages wait for them in the [inbox](https://nomongeta.zenhalab.com/www/nomongeta/en/docs/concepts/conversations-and-inbox).

> [!IMPORTANT]
> Triggers apply to **every channel** of the workspace. A flow with an "any message" trigger answers the widget, WhatsApp and e-mail alike. To keep a flow to some channels, use a "messages on a channel" trigger, or pick it as those channels' flow instead of giving it triggers.

## How a flow hands over to the agent

A flow's run ends at an **End** step, or wherever an output is left unconnected. From then on, the next message goes through the same order again: a trigger may start a flow, then the channel's flow starts over at its start step, and only on a channel without a live flow does the agent answer. So on a channel that has its own flow, the agent never replies by itself: put an [AI step](https://nomongeta.zenhalab.com/www/nomongeta/en/docs/flow-builder/ai-agent) wherever an agent should take over (on a [Buttons](https://nomongeta.zenhalab.com/www/nomongeta/en/docs/flow-builder/buttons) step's **Anything else** output, for example). Inside a flow, an [AI step](https://nomongeta.zenhalab.com/www/nomongeta/en/docs/flow-builder/ai-agent) lets an agent hold part of the conversation and then carry on with the flow.

## Choosing

- Start with **an agent only** if your customers mostly ask questions.
- Add **a flow** as soon as there is something you want done the same way every time, or something that needs your systems (a booking, an order lookup).
- Use **Hand to a person** in flows and the **request_human_handoff** tool in agents so people can always reach a person.
