# How AI answers are built

> Understand when the AI answers a customer, what it reads before it writes, and when it hands the chat to your team.

Source: https://docs.soosh.io/concepts/how-ai-answers-are-built/

When a customer writes, Soosh tries your own rules first: keyword replies and
bot flows. The AI answers only when none of them does. It writes from your
knowledge base, your instructions, the latest messages and what Soosh
remembers about the customer. When it can't help, it can hand the chat to
your team.

## Why it works this way

Rules you write give the same answer every time, so they go first. A delivery
question at Blue Lotus Fashion should always get the same delivery times. The
AI covers everything else, and you pay for it only when it runs.

## The order Soosh follows

For each message, Soosh goes down this list and stops at the first thing
that answers:

1. **The chat is with your team.** After a chat is handed over, or someone
   [assigns it to a person](https://docs.soosh.io/guides/inbox/assign-a-chat/), the bot and the AI
   stay quiet until someone resumes the bot.
2. **The bot is off.** The chat goes to the queue for your agents.
3. **You're closed.** Outside your business hours the customer gets your out
   of hours message. If **Allow automated responses outside hours** is on,
   Soosh carries on down the list. Your hours use the workspace
   [time zone](https://docs.soosh.io/guides/workspace/set-your-time-zone-and-date-format/), or UTC
   if none is set. A flow's **Business hours** step does too.
4. **A keyword reply that hands over.** Its message goes out and the chat is
   queued for your team.
5. **A bot flow.** A customer in the middle of a flow carries on with it.
   Otherwise, a message with one of a flow's trigger words starts that flow.
6. **The greeting.** The first message of a new bot chat gets your
   **Greeting message**, if you set one. A new bot chat starts when the
   customer writes after the **Chat timeout** has passed. Soosh then carries on down the list,
   so a keyword reply or the AI answers that message too.
7. **A keyword reply with an answer.**
8. **The AI**, if **AI replies** is on.
9. **The fallback message**, if nothing else could answer. A new bot chat
   that just got your greeting doesn't also get the fallback.

A customer who replies `STOP` is handled before this list: Soosh opts them
out of marketing and the bot doesn't answer. See
[Marketing opt-out](https://docs.soosh.io/concepts/marketing-opt-out/).

The bot reads text only. It reads a photo's caption, but not the photo, and
it doesn't answer voice notes or stickers.

## What the AI reads

Before it writes, the AI gets:

- **Your instructions** from **System prompt**, like the tone to use.
- **Soosh's own rules**: use WhatsApp formatting, and keep replies under 80
  words unless the customer asks for detail.
- **Your knowledge base.** Sources without trigger keywords are sent every
  time, highest priority first. Sources with keywords are sent only when one of
  the customer's last 3 messages mentions one as a whole word. If they sent
  more than 3 since your last reply, all of those count.
- **The latest messages** in the chat, so it can follow it.
- **What Soosh remembers** about the customer, if
  [customer memory](https://docs.soosh.io/concepts/customer-memory/) is on.

It doesn't look up your catalog or orders by itself. An **API fetch**
source can do that. Soosh asks your system each time the source applies, and
fills the customer's message into the address in a safe form, so it can't
change which record is asked for. All the **API fetch** sources are asked at
once. One that hasn't answered within 15 seconds is left out of that reply.

When a customer sends several messages in a row, the AI waits a moment and
answers them together. Keyword replies and flows still answer each message
at once.

## When it hands over

With **Hand over to a person** on, the AI helps the customer first: it
answers what it can, asks what they need and collects their details. It passes
the chat to your team only when they need a person. Your **When to hand over
(optional)** rules decide when that is. Without rules, it hands over when the
customer asks for a person again after it tried to help, needs your team to
do something (an order, a refund, a complaint), or it's urgent. It doesn't
hand over for a greeting, and when an agent hands a chat back to the bot, it
doesn't pass the same request over again. The customer is told someone will reply,
and the chat waits in the queue for a team or any available agent. Agents see
that the AI handed it over, with its summary.

If nobody who can take the chat is online, the customer gets your **If no
agent is online (optional)** message instead, and the chat still waits. Outside business
hours they get your out of hours message, and the chat isn't queued.

With **Hand over to a person** off, the AI can't pass a chat on. A keyword
reply set to **Transfer to agent** still can.

## What the AI can't do

- It only writes messages and hands chats over. It can't change an order,
  book anything or send a template.
- It only knows what you give it. If a fact isn't in your knowledge base, it
  may guess or say it doesn't know.
- It can be wrong. Read some of its chats now and then.

> **Cost:** AI answers use Soosh AI and are paid from your wallet. You pay only for
> answers that were sent or that handed a chat over.

If the wallet has no credit left for AI, or the month's AI charges reach your
monthly limit, AI answers pause. Customers get your fallback message instead.
See the charges and set the limit in [**Settings > AI usage**](https://app.soosh.io/settings/ai-usage). If
charging hasn't started for your workspace yet, that page says so.

## How to get better answers

- **Write sources the way you'd brief a new colleague.** Plain facts, one
  topic per source. Check **What the AI reads** to see what it gets.
- **Use trigger keywords for long, narrow topics**, like a size guide. Keep
  always-on sources short.
- **Use the System prompt for how to answer**, not for facts: tone, length,
  language.
- **Turn on hand-over**, so customers who need a person get one.

## Related

- [Turn on AI answers](https://docs.soosh.io/guides/chatbot/turn-on-ai-answers/)
- [Add to the knowledge base](https://docs.soosh.io/guides/chatbot/add-to-the-knowledge-base/)
- [Hand chats to agents](https://docs.soosh.io/guides/chatbot/hand-chats-to-agents/)
- [Set up keyword replies](https://docs.soosh.io/guides/chatbot/set-up-keyword-replies/)
- [Build a bot flow](https://docs.soosh.io/guides/chatbot/build-a-bot-flow/)
- [Set business hours and an away message](https://docs.soosh.io/guides/chatbot/set-business-hours-and-an-away-message/)
- [Track AI usage and cost](https://docs.soosh.io/guides/analytics/track-ai-usage-and-cost/)
- [Customer memory](https://docs.soosh.io/concepts/customer-memory/)
- [How billing works](https://docs.soosh.io/concepts/how-billing-works/)
