# Smart Agent

> The step that talks, decides and acts

This article is the third in the Chatbot series. The first one, **[Chatbot](https://docs.audara.io/en/chatbots/)**, explains the module, the canvas and how an agent is published. The second, **[Chatbot: the steps in a flow](https://docs.audara.io/en/chatbot-pasos/)**, is the catalogue of every step. This one is about a single step, because it is worth an article of its own: the **Smart Agent** and the two steps that go with it.

## What a Smart Agent is

The other steps in a flow follow a script: the bot asks, the customer answers, the flow moves along whichever path fits. A Smart Agent does not. It is a stretch of open conversation with an artificial intelligence model: you tell it who it is and what it can do, and it decides what to answer and when to act.

What sets it apart from the **ChatGPT** step is exactly that last part. The ChatGPT step answers, and that is it. A Smart Agent also **runs things**: it can ask the customer for their ID number and store it in a variable, look up a balance against an outside system or pass the conversation to an adviser, because it has functions assigned to it and knows when to call them.

They are three steps that work together and always in the same order:

- **Smart Agent**: The one that holds the conversation. It carries the prompt, the examples, the tone and the list of functions it may use.
- **Smart Function**: The path the conversation takes when the agent decides to call a function. It hangs off the Smart Agent, one per function.
- **Smart Function Result**: It tells the agent how what the function did turned out, so it can answer accordingly. It is optional.

![The trio on the canvas: an agent, its functions and a result](https://docs.audara.io/smart-agent/imagenes/sa-flujo-ejemplo.jpg)

*The trio on the canvas: an agent, its functions and a result*

In the example, the **1.** Smart Agent serves the customer. It has two paths: the **2.** Smart Function that asks for the ID number, and the **3.** one that looks up the balance. Hanging off the second is a **4.** Result that hands the agent back the balance it found so it can say it in its own words.

The Smart Agent works the same in a **chatbot** and in a **[voicebot](https://docs.audara.io/en/voicebots/)**. The only place that will not take it is the survey flow.

## Before you start

A Smart Agent needs two things configured away from the canvas.

### The agent's Select LLM

The model that will hold the conversation is chosen once for the whole agent, from the cog button in the top bar, under **General settings**. While it is empty, the step tells you so and will not let you save.

![With no Select LLM, the step warns you and the Save button stays off](https://docs.audara.io/smart-agent/imagenes/sa-error-llm.jpg)

*With no Select LLM, the step warns you and the Save button stays off*

> **Important**
> Select LLM comes from the artificial intelligence integrations on your account. If the selector is empty, the integration has to be created first under **Setup > Integrations**.

### The functions

Functions are not created here. They live under **Setup > AI Agents > Functions** and are explained in the **[Smart Functions](https://docs.audara.io/en/funciones-inteligentes/)** article; the MCP ones, in the **[MCP Integrations](https://docs.audara.io/en/mcp/)** article. In the Smart Agent you only pick them.

> **Note**
> An **inactive** function is not offered to the agent. The step is still drawn on the canvas and the flow looks just as good, but the model will never call it because it does not know it exists.

## How the trio is put together

All three steps are in the same group of the canvas menu, **Add Smart Agent**.

![The **Add Smart Agent** group opened from the start step](https://docs.audara.io/smart-agent/imagenes/sa-submenu.jpg)

*The **Add Smart Agent** group opened from the start step*

- ****1.** Smart Agent**: It can hang off almost any step, so here it comes out available.
- ****2.** Smart function**: It comes out greyed because it can only hang off a Smart Agent, and this one is hanging off the start.
- ****3.** Smart Function Result**: It has no restriction on its parent, because it goes at the end of a path that may be long.

The order of work is: first you create the Smart Agent and assign it its functions, and then you hang one Smart Function off it per function. If you do it the other way round, the Smart Function selector will come out empty.

![From a Smart Agent the only thing available is **Smart function**](https://docs.audara.io/smart-agent/imagenes/sa-bajo-agente.jpg)

*From a Smart Agent the only thing available is **Smart function***

From a Smart Function, on the other hand, any step in the catalogue can hang: a message, an integration, a condition, an action or the Result.

![From a Smart Function the menu opens in full](https://docs.audara.io/smart-agent/imagenes/sa-bajo-funcion.jpg)

*From a Smart Function the menu opens in full*

> **Good practice**
> The Smart Agent is one of the few steps that split into several paths, so you can hang off it as many Smart Functions as you need and they end up as siblings. Mind you, the second one is drawn on top of the first and it looks as though nothing happened: use **Arrange > Vertical** from the flow menu and the tree sorts itself out.

## The Smart Agent step

It is the longest step to configure in the whole module, and the one that shows the most when it is well written.

![The settings of a Smart Agent, first half](https://docs.audara.io/smart-agent/imagenes/sa-agente-arriba.jpg)

*The settings of a Smart Agent, first half*

- ****1.** Title**: The name you see on the canvas. Give it the part it plays, like "Support assistant" or "Collections agent".
- ****2.** Functions**: The functions this agent can call. Type to filter and click to add them. They are the only ones you will be able to pick afterwards in the Smart Functions you hang off it.
- ****3.** Prompt**: Required. The agent's instructions: who it is, what it does, what it must not do and when to use each function. It takes up to 50,000 characters and chat variables. The names of the functions you already assigned are highlighted in the text, so you can see at a glance whether you are naming them properly.
- ****4.** Design prompt**: Asks the artificial intelligence to write the prompt for you. It is explained in the next section.
- ****5.** Few-Shot Learning**: Sample conversations, up to 20,000 characters. They are there to teach it the answering style with real cases instead of describing it. They are handed to it appended to the end of the prompt.

![The settings of a Smart Agent, second half](https://docs.audara.io/smart-agent/imagenes/sa-agente-guardrails.jpg)

*The settings of a Smart Agent, second half*

- ****1.** Guardrails**: The three fields that follow. On top of those, Audara applies to the agent a set of fixed rules that are not configured here and that are explained under [How the Smart Agent decides](https://docs.audara.io/en/smart-agent/#decide).
- ****2.** Max words per response**: An average, not a hard cap: the agent aims at that number and can go a little over if it needs to in order to finish the thought. If you leave it empty, it aims at 50. In a voicebot it is worth lowering, because a long answer read out loud goes on forever.
- ****3.** Temperature**: How varied the answers are, from 0 to 2. With low values it answers almost the same way every time, and with high values it improvises more. Leave it at 1 unless you have a reason not to: some of the models in the catalogue only work with their own default and ignore it.
- ****4.** Tone**: Normal, Formal, Empathetic, Friendly or Enthusiastic. It adds a style instruction to the agent with an example of each tone. It is the quickest adjustment for making a bot stop sounding stiff.

## Designing the prompt

Writing a good prompt from scratch is hard work. The **Design prompt** button lets you describe what you want in your own words and puts the whole prompt together for you.

![Describe what the agent should do, in plain language](https://docs.audara.io/smart-agent/imagenes/sa-disenar-prompt.jpg)

*Describe what the agent should do, in plain language*

Click **Generate prompt** and the answer writes itself out on screen. It comes out in sections, with the role, the tone and the instructions for each function, and with the function names highlighted.

![The generated prompt. **Use prompt** takes it to the field, **Return** lets you ask for another](https://docs.audara.io/smart-agent/imagenes/sa-prompt-generado.jpg)

*The generated prompt. **Use prompt** takes it to the field, **Return** lets you ask for another*

> **Note**
> Assign the functions **before** asking for the prompt. The window knows about them and writes the instructions for each one; if you open it with the list empty, it will hand you back a generic prompt. And watch out: **Use prompt** replaces whatever you had written in the field.

## The Smart Function step

A Smart Function is not the function. It is the **path in the flow** that gets walked when the agent decides to call it: here you say which function it is, what to do with whatever it brings back and what to tell the customer in the meantime.

![A Smart Function pointing at a **Capture** function](https://docs.audara.io/smart-agent/imagenes/sa-funcion-captura.jpg)

*A Smart Function pointing at a **Capture** function*

- ****1.** Title**: The name on the canvas. Make it read like the action: "Take the ID number", "Look up the balance".
- ****2.** Function**: The selector only shows the functions assigned to the Smart Agent this step hangs off. If one is missing, add it up there first.
- ****3.** Require confirmation**: Only appears on Capture functions. It makes the agent repeat the data it took back to the customer and wait for them to confirm it before running the function. Turn it on for anything that actually writes or moves something.
- ****4.** Dependencies**: Other functions of the same agent that have to have run successfully before this one. If the agent calls it too early, the call is refused and it is told to use the other one first. It is there for the obvious ordering: verify the customer before looking up their account.
- ****5.** What does this function do (prompt)**: Read only. It is the description you wrote on the function and it is exactly what the model reads to decide when to call it. If the agent calls it when it should not, or does not call it when it should, that is fixed there and not in the agent's prompt.
- ****6.** Data, Type and Variable**: Only on Capture functions. For each value the function captures, you write the name of the chat variable you want it stored in. The name is put into capitals by itself.
- ****7.** Message when triggering the function**: What the bot says while the function works, so the customer is not left in silence. It is sent once per question, even when the agent chains several lookups to answer it.

### When the function is an MCP one

An MCP function can bring in several tools from the same server. The step lists them read only, with their description and their parameters, so you can see what it is going to be able to run.

![An MCP Smart Function, with its dependency set and its tools listed](https://docs.audara.io/smart-agent/imagenes/sa-funcion-mcp.jpg)

*An MCP Smart Function, with its dependency set and its tools listed*

- ****3.** MCP tools**: Which tools the function brings and what parameters each one asks for. The **Required** ones are those the agent has to get hold of before calling it, no matter what, usually by asking the customer. That is configured on the function, not here.

> **Note**
> This step lets you save without picking a function. If you end up with a Smart Function in the flow that does nothing, check that the selector was not left blank.

## The Smart Function Result step

When the function finishes, the agent picks the conversation back up with whatever it brought. The **Smart Function Result** step is there to slip it a note on the way: to tell it whether what just happened went well or badly, and to give it context to answer with.

![A Result marking the successful path](https://docs.audara.io/smart-agent/imagenes/sa-resultado.jpg)

*A Result marking the successful path*

- ****1.** Title**: The name on the canvas.
- ****2.** Type**: Required. **Success** or **Failure**. It is what the agent is told, and it is also what counts for **Dependencies**: a function that ended in Failure does not unlock the ones that depend on it.
- ****3.** Detail**: Free text handed to the agent along with the result. It takes chat variables, so it is the place to give it what the lookup returned and tell it what to do with that.

> **Important**
> The Result **evaluates nothing**: it declares. If you put in a Result of type Success, the agent is going to be told it went well, whatever actually happened. To split the good case from the bad one, the branching is done by a **Condition** on the variable the lookup left behind, and you put a Result at the end of each branch.

### What happens next

This is the part that confuses people most, and there are two cases:

- **A Smart Function with nothing hanging off it**: Control goes back to the Smart Agent by itself, and it answers with what the function brought. It is the most common case and there is nothing to configure.
- **A Smart Function with steps hanging off it**: The flow walks those steps, the Result included if you put one in, and carries on with whatever hangs off the last one. If nothing hangs off it, the path ends there and the agent never takes the conversation back. To hand it back, hang an **Action** of type *Go to step* pointing at the Smart Agent.

## How the Smart Agent decides

The agent does not call functions at will. Audara puts a set of fixed rules on it that are not configurable and that explain nearly everything you see when testing a bot:

- **It does not act on the first message**: The agent cannot call a function before the customer has written. First it says hello, then it acts. The rule belongs to the conversation, not to the step: an agent taking over a conversation another one started can act straight away.
- **It does not repeat the same function**: It cannot call the same function twice without the customer having said something in between. When it tries to, it is nearly always because it is trying to answer through the function instead of using what it already has.
- **One at a time, with a cap per question**: It runs one function per turn, and can chain up to six to answer a single question. When it hits the cap it answers with whatever it has managed to get.
- **It honours the dependencies**: If it calls a function whose dependency has not been met, it is refused and told to use the other one first. It is not an error the customer sees.
- **It confirms before anything important**: On functions with **Require confirmation**, it has to have confirmed the data back to the customer in a separate message before running them.

> **Good practice**
> If the agent calls a function when it should not, or falls short and does not call it, the first thing to look at is not the agent's prompt but the **description of the function**. That description is the only thing the model reads in order to decide, and it weighs more than any instruction in the prompt.

## Several Smart Agents in one flow

A flow can have several Smart Agents, each specialised in one subject, passing the conversation between them. That is how the large agents are built: one takes the conversation and sorts it, and from there sends it to an information one, an account one, a cancellations one.

The handover is built like this: you give the agent that receives a function that detects the change of subject, and under that Smart Function you hang an **Action** of type *Go to step* pointing at the other Smart Agent. The flow jumps and from there the new one holds the conversation.

Each agent starts with its own context and its own functions, so it does not inherit the previous one's instructions. What Audara does know is that the conversation was already under way, which is why the agent that receives it can run a function on its first turn without asking the customer again for what they already said.

> **Good practice**
> One agent per subject, with few functions each, is worth more than a single agent with fifteen functions and a giant prompt. The more similar functions it has in front of it, the more often it picks the wrong one.

## Good practice

- **Give things names that read on their own**: Both the step and the function. The canvas shows the title, not the contents, and the name of the function is part of what the model uses to understand it.
- **Short prompt, examples separately**: The prompt for the rules, in the imperative and with no waffle. The sample conversations go in Few-Shot, which is what it is for.
- **Tell it what not to do**: The instruction not to make data up and to offer an adviser when it does not know something is the one that prevents the most trouble in production.
- **Always a path to a human**: Give it a function for handing the conversation to an adviser and tell it in the prompt when to use it. An agent with no way out leaves the customer going round in circles.
- **Test it before publishing**: The **Test** button runs the flow you are looking at, without publishing anything, and marks on the canvas which step the conversation is on. It is explained in the **Chatbot** article.
