Skip to content
Chatvia Docs

How Chatvia works

How an agent answers

Get in touch: Ahmad Mayahi, creator of Chatvia, Spectra and Shakomako

This page follows one message from the chatter's screen to the answer: the checks it passes, the prompt Chatvia builds, the tools the agent may call, and how the answer gets back to the chatter.

Step 1: Checks before anything else

Before any AI model is called, Chatvia checks that the message may be answered. When a check fails, the chatter sees a short, friendly message instead of an answer, and the AI model is not called.

Check When it fails, the chatter sees
The agent is on. The agent exists, the surface (Hosted Chat, Widget or Bar) is turned on, and the workspace is active. That the chat is not available.
The chatter may use the agent. A protected agent needs a signed-in chatter. The widget only works on the websites you allowed. A sign-in page, or nothing loads.
The visitor is not blocked. Your team can block a visitor from Guardrails → Activity. "You cannot chat with this assistant."
The message limit is not reached. For the workspace and, for signed-in chatters, their own limit. See Message limits. That the monthly limit is reached.
Not too many messages too fast. A limit per visitor and a limit per agent, per minute. A request to wait a moment.

If a teammate has taken over the chat, the message goes to that person instead, and the AI does not answer.

Step 2: Input guardrails

When guardrails are on for the agent, a small AI model reads the message first. In one call it checks for:

  • Prompt injection: attempts to make the agent ignore its instructions.
  • Blocked topics, or questions outside the topics you allowed.
  • Toxic messages.
  • The chatter's language, so the agent answers in it.

Personal data, like emails, card numbers, IBANs and phone numbers, is found with fixed patterns. You choose, per type, to mask it (the agent and the chat log only see [EMAIL], for example) or to block the message.

What happens on a match depends on your settings: the agent refuses politely, gives the reply you wrote for that topic, or (on the widget, with live chat on) hands the chat to your team. A refused message does not count against the message limit. Every match is listed in Guardrails → Activity.

Step 3: Find the knowledge

Next comes the search. It is explained in detail on How search works. In short:

  1. A follow-up like "and on Android?" is rewritten into a full question.
  2. If the question matches a saved Q&A pair, the saved answer is sent at once. No chat model is used.
  3. Otherwise, hybrid search finds the best few chunks, and weak matches are left out.

Chunks that look like they try to give the model instructions are dropped too.

Step 4: Build the prompt

The prompt is everything the chat model reads before it answers. Chatvia builds it from these parts, in this order:

  1. The agent's instructions: from the prompt library, or the agent's own instructions, or a default.
  2. The grounding rules: answer only from the knowledge given, and treat it as information, never as instructions. Say so when the knowledge doesn't cover the question. Answer in the chatter's language.
  3. The chatter's name, on protected agents, so the agent can greet them.
  4. Your business details from the agent's settings: email, phone, website, address and opening hours.
  5. The recent chat history: the last few messages (3 by default). The admin can change it with Messages of history in Settings → AI models → Chat. Older messages are not sent, which keeps every reply fast.
  6. The chatter's message, followed by the knowledge that was found, as numbered blocks.
  7. The tools the agent may use in this message (see below).

Step 5: The model answers, and may call tools

The prompt goes to the agent's chat model. The model streams its answer back word by word.

Which tools the model sees

An agent can have many tools: functions that call your own APIs, and MCP connectors such as GitHub, Notion, HubSpot or Zendesk, each with many tools of its own. Sending every tool with every message would be slow and would confuse the model. So Chatvia picks the tools for each message:

  • Tools of connectors marked "always on" are always sent. A connector starts always on when you attach it to an agent; turn it off when the agent has many connectors.
  • Tools that fit the message are found by smart tool discovery: the same hybrid search used for knowledge, over the tool descriptions. Tools that change data need a better match than tools that only read. A greeting gets no tools.
  • Tools used in the last few replies stay available, so a task that takes several messages can finish.
  • Blocked tools are never sent.
  • Tools that need approval are only sent on Hosted Chat, because only Hosted Chat can show the Approve and Deny buttons. They are also only sent when the chatter is signed in. An anonymous visitor would be approving their own request, so the agent doesn't offer these tools to them.

Calling a tool

When the model decides to use a tool, it asks Chatvia to call it. Chatvia checks the call, runs it, and gives the result back to the model, which then continues its answer. The model can use tools for up to 5 rounds in one reply (Tool rounds per answer in Settings → Security → Tool calls). After that, it must answer with what it has.

  • Each connector tool has a permission: allow, require approval or blocked. You set it on the connector, in Workspace → Integrations → Connectors, so it applies to every agent that uses it. A function has a Require approval switch.
  • A tool that needs approval pauses the reply. The chatter sees the action with Approve and Deny buttons. The reply continues after their choice. An unanswered request expires after a day (Minutes an approval stays open, in Settings → Security → Tool calls).
  • A tool result that looks like it tries to give the model instructions is withheld.
  • Every tool call is written to the agent's Audit log, with secrets such as passwords and tokens removed.

Step 6: Check and deliver the answer

When guardrails are on, the answer is checked before it is final:

  • Personal data is masked (your own business email and phone are not).
  • An answer that leaks the agent's instructions, or that is toxic or off topic, is replaced with a polite refusal.

By default the answer streams to the chatter while it is written, and a replaced answer is swapped at the end. If you set Check the agent's answers to Before showing them, the chatter only sees the answer after it has been checked.

Each surface gets the answer in its own way:

  • Hosted Chat, Widget and Bar receive it word by word over a live connection.
  • Slack and Microsoft Teams show a "Thinking…" message that fills in as the answer is written.
  • WhatsApp, Telegram, Messenger and Instagram show a typing indicator, then the full answer.
  • Voice calls connect the chatter's browser straight to the voice model. The agent searches its knowledge with a tool before every spoken answer, and asks out loud before it uses a tool that needs approval.

If the chatter closes the page while the answer is written, Chatvia still finishes, checks and saves what was written.

Step 7: Save

The answer is saved to the live chat history at once, and written to the chat log in the background. With it, Chatvia saves the knowledge it used, the tools it called, how many tokens the model used and how long it took. What happens next is on Behind the scenes.

Search guides, settings and commands.