# AI step

> Let an AI agent hold part of the conversation until a goal is met, pull values into variables, and carry on with the flow.

Hands a stretch of the conversation to an AI agent. The agent talks with the contact, as many replies as it takes, until the **goal** you describe is met; it then fills in the values you asked for and the flow carries on. It's how a scripted flow handles the open-ended parts: "tell me about your event", "what went wrong?", "which plan suits me?".



## Who answers

Under **Who answers**:

- **One of your agents**: pick an **Agent**. The step uses that agent's instructions, guardrails, model, skills, tools and knowledge, exactly as in a normal conversation.
- **Instructions here**: write **Instructions** for this step alone, and choose a **Model** (by default, the model of the agent answering the channel), whether it may search the knowledge base (**Use the knowledge base**) and which **Tools** it may use. The workspace's guardrails still apply.

## Goal and results

| Setting | What it does |
| --- | --- |
| Goal | What the step is for, in plain words: "Find out the date, the number of guests and any dietary needs, then summarise the request." The agent finishes the step as soon as this is done. |
| Save from the conversation | Values the agent fills in when it finishes, each with a variable, a description of what to extract ("The number of guests") and a type. They're converted to the variable's type. |
| Most replies | The most replies the agent may send in this step (10 by default, up to 50). |

## How the step runs

1. The agent replies to the conversation so far (it sees the recent messages, including those before the step).
2. The contact answers; the agent replies again; and so on.
3. The step ends when the agent:
   - decides the goal is met: it saves the results and the run leaves by **Done**;
   - decides a person should take over: the run leaves by **Handed off**;
   - can't go on: the run leaves by **Fallback**.

## Outputs

| Output | When |
| --- | --- |
| Done | The goal was met. The values you asked for are in their variables. |
| Handed off | The agent asked for a person (the contact wants one, is upset, or asks for something it can't do). Connect it to a [Hand to a person](https://nomongeta.zenhalab.com/www/nomongeta/en/docs/flow-builder/handoff) step, or leave it open: the conversation then goes straight to the inbox, and when your team hands it back the AI step picks the conversation up again. |
| Fallback | Something stopped the agent: it reached **Most replies**, the contact didn't answer in time, AI isn't set up, its agent is paused, its token budget is spent, the model failed or took too long. |

Always connect **Fallback** to something sensible, such as a message and a handoff: it's what your customers get when the AI can't help.

## Costs and limits

- Every reply uses tokens, counted against the agent of the channel's conversation, and against the step's own agent when it's another one: their token budgets and rate limits apply.
- By default the agent sees the last 30 messages, has 60 seconds per reply, and one incoming message can lead to at most 3 AI replies across the flow.
- Without an AI model set up on the platform, AI steps always leave by **Fallback**; test mode shows "AI isn't set up".

## Tips

- Write the goal as a checklist of what must be known, and what to do with it.
- Ask for few, precise values. Pick types that fit (a number for guests, a date for the day), so a [Condition](https://nomongeta.zenhalab.com/www/nomongeta/en/docs/flow-builder/condition) can use them.
- Keep scripted, must-be-exact steps (prices, legal text) out of the AI step: send them with a [Message](https://nomongeta.zenhalab.com/www/nomongeta/en/docs/flow-builder/message).
