How to build an AI support agent
Engineering12 min read
A working prototype takes an afternoon. A support agent you would put in front of customers takes considerably longer, and the gap between the two is almost entirely in the parts that handle being wrong.
This is the build order we would follow again, drawn from building AskBrew. It assumes you are comfortable with a database and an HTTP API, and it is deliberately opinionated about sequence — several of these steps are painful to retrofit.
1. Storage, with tenancy from the first migration
Start with the schema, and put the tenant identifier on every row that will ever hold customer content — even if you are building for a single customer today. Retrofitting multi-tenancy into a system where the isolation boundary was assumed is one of the least pleasant refactors available.
If you are on Postgres, pgvector keeps embeddings alongside the relational data, which means tenant filters and citation joins happen in one query. Store the embedding model name on every chunk: changing models invalidates every vector, and you want that detectable rather than mysterious.
Minimum viable chunk table
create extension if not exists vector;
create table chunks (
id uuid primary key default gen_random_uuid(),
workspace_id uuid not null references workspaces(id) on delete cascade,
source_id uuid not null references knowledge_sources(id) on delete cascade,
content text not null,
embedding vector(1536),
embedding_model text not null,
metadata jsonb not null default '{}',
created_at timestamptz not null default now()
);
create index chunks_workspace_idx on chunks(workspace_id);
create index chunks_embedding_idx on chunks
using hnsw (embedding vector_cosine_ops);2. Ingestion as a background job
Parsing a large PDF, chunking it, and embedding every chunk will exceed a serverless request timeout on any corpus worth having. Make indexing a background job with visible progress from the start.
Chunk on document structure rather than a fixed character count wherever the structure exists, and carry the heading into the chunk body so the embedding reflects the topic. Batch the embedding calls; providers cap batch size, and a hundred at a time is a safe unit.
Track each run as a row — status, total chunks, embedded chunks, error — so the interface can show progress and a failure is diagnosable after the fact rather than a spinner that stopped.
3. Retrieval that cannot cross tenants
Put the search in a database function that takes the tenant ID as a required argument. This is a small thing that eliminates an entire category of catastrophic bug: there is no code path that can search without scoping, because the function will not run without it.
Return the similarity score alongside the content. You need it for the answer gate, and you need it in the trace when someone asks why a particular answer came out.
4. The answer gate — the part that matters
This is where a prototype becomes a product. Before generating, decide whether you should. If the best match is weak and nothing else could help, return a fallback without paying for a model call.
When you do generate, constrain the prompt to the retrieved context, delimit that context explicitly, and require structured output that includes the model's own assessment of how well the context covered the question. Blend that with the retrieval score to decide whether the answer is good enough to send.
Record the outcome on every answer: answered or not, the confidence, the chunk IDs and their scores, the model, the token counts. You will want all of it the first time someone reports a bad answer, and it is nearly impossible to reconstruct later.
5. Handle the messages that are not questions
"Hi", "thanks", "are you a bot" — these are a meaningful share of real traffic and they should not touch retrieval. Running the pipeline on a greeting produces "I couldn't find information about that", which is wrong, and in our case also triggered an offer to connect the customer to a human, which then hijacked the next real question into a handover flow.
A short classifier before the pipeline fixes it. This is a small feature that noticeably changes how the assistant feels.
6. Tools, once the content path is solid
Content questions are only half the inbox. "Where is my order?" needs a live lookup, and that means function calling plus a way to know who is asking. Build it after the retrieval path works, not alongside it.
The identity requirement is not optional. A tool that reads customer data must only be offered to a visitor whose identity your customer's server has cryptographically vouched for. Withhold the tool entirely from unverified visitors rather than checking permissions after the model has decided to call it.
7. The operational pieces
These are not features anyone asks for in a demo, and every one of them will be needed in the first month of real traffic.
- Rate limits per visitor and per tenant, failing closed in production
- An origin allowlist, so a public widget key cannot be used from anywhere
- Input caps on message length and conversation history
- A queue of unanswered questions, which is your content roadmap
- Encrypted storage for any credentials a tool needs
- A replay view showing the trace behind any past answer
Build or buy
All of the above is a few weeks for someone who has done it before, and considerably more for someone who has not — most of the time going to the answer gate, the tenancy boundary, and the operational list rather than the interesting parts.
Worth building if the assistant is your product, your data model is unusual, or you have requirements no tool fits. Worth buying if support is a cost centre you want smaller, in which case the differentiated work is your content, not your retrieval pipeline. AskBrew is our answer to the second case, and it has a free plan.
Build in this order and the hard parts arrive when you have something to test them against. Build the tool-calling before the answer gate and you will have an agent that can do a great deal, confidently, without knowing when it is wrong.
Try it on your own content
Free to start — live in minutes.
Keep reading
Engineering
API-based AI support: integrating an assistant into your own product
When a hosted widget does not fit — custom interfaces, mobile apps, existing helpdesks — and what an integration needs to get right.
Comparison
AskBrew vs Chatbase: which fits your support team?
Both build a chatbot from your own content. They differ in what happens when the assistant is unsure, and in whether it can answer questions about a specific customer's account.
Buyer's guide
Chatbase alternatives: how to actually choose one
A buyer's guide to the AI support chatbot category — the four questions that separate these tools, and which type of alternative fits which situation.
Buyer's guide
Best AI customer support software: a buyer's guide for 2026
What AI support tools actually do, the three categories they fall into, and how to evaluate them without relying on vendor feature tables.
Engineering
Multi-tenant RAG: keeping one customer's data out of another's answers
Vector search across shared infrastructure has a failure mode worse than a bad answer. How to make tenant isolation a property of the database rather than a discipline.
Engineering
Function calling for support bots
Letting an assistant look up a customer's order turns a content bot into something useful — and introduces an authorisation problem that must be solved outside the model.
Engineering
Preventing hallucinations in customer support bots
Grounding reduces fabrication but does not eliminate it. The techniques that actually work, and why an assistant that refuses is more valuable than one that always answers.
Engineering
pgvector vs Pinecone: choosing a vector store
A dedicated vector database and a Postgres extension solve the same problem differently. The deciding factor is usually not search performance.
Engineering
RAG architecture explained, for people shipping it
The components of a retrieval-augmented generation system, the decisions that actually affect answer quality, and where production implementations diverge from tutorials.
Engineering
How AI customer support actually works
What happens between a customer typing a question and an answer appearing: retrieval, grounding, confidence, and the decision to answer or hand over.