AI & data
ChatGeniee: Multi-Tenant AI Agent Platform with RAG
How we built a white-label chatbot platform: grounded answers from customer knowledge, real-time streaming, voice, and AI-driven bookings.
July 9, 2025·CloudGeniee·18 min read

The problem
Small businesses want a website assistant that answers from their own content, sounds like their brand, and hands off cleanly when a visitor wants a human or a meeting. Off-the-shelf chat widgets either hallucinate, look generic, or need an engineer to set up. We set out to build one platform that any business can configure in minutes and embed with a single script tag.
Requirements we designed against
- Strict multi-tenancy: one customer must never see another's bots, documents, chats or bookings
- Answers grounded in each bot's own knowledge (website pages, documents, FAQs), not the open internet
- Replies that stream token by token, so the widget feels instant
- A widget that drops into any site without clashing with its CSS or JavaScript
- Brand control: colours, avatar, launcher style and position per bot
- Predictable running cost on a small footprint, with per-plan limits
Architecture overview
The platform is three deployable pieces: an API, a customer dashboard, and an embeddable widget. They share one Postgres database and communicate over a small, versioned HTTP surface.
- API: a TypeScript service on Hono with Drizzle ORM, running on AWS EC2 behind nginx and managed by PM2
- Data: PostgreSQL with the pgvector extension for embeddings, S3 for uploaded files and avatars
- LLMs: Amazon Bedrock (Mistral and Amazon Nova models), chosen per plan for the best speed-to-quality trade-off
- Dashboard: a Next.js static export with Tailwind and TanStack Query, built and hosted on AWS Amplify
- Widget: a tiny injector script plus a Preact chat app served from a CDN inside an isolated iframe
- Voice: a self-hosted LiveKit server and a voice agent that uses Deepgram for speech and the same retrieval pipeline as text chat
Multi-tenancy and authentication
Every table that holds customer data carries a tenant id, and every query is scoped by the tenant taken from the verified session, never from the request body. We use our own JWT-based authentication with email and password plus Google Sign-In; accounts are linked by verified email so a person never ends up with two profiles. Plans (Free, Growth, Business) drive limits such as active bots, message volume and feature access, and are enforced server-side on every relevant route.
Retrieval-augmented generation
Each bot owns a knowledge base. When a customer adds a page, file or text, the API splits it into overlapping chunks, creates an embedding for each chunk, and stores the vector in Postgres next to the text. An HNSW index on the vector column keeps similarity search fast as the corpus grows.
At question time the pipeline embeds the visitor's message, retrieves the closest chunks for that bot only, and builds a prompt containing the bot's persona, its response style (concise, balanced or detailed), the retrieved context and the recent conversation. The system prompt instructs the model to answer from the supplied context and to say so when the answer is not there, which keeps responses honest and on-brand.
-- nearest chunks for one bot, cosine distance
SELECT content
FROM knowledge_chunks
WHERE bot_id = $1
ORDER BY embedding <=> $2
LIMIT 6;Streaming chat
Replies are sent to the widget as server-sent events. The API calls Bedrock's streaming interface and forwards each text delta as it arrives, so the visitor sees the answer being written within a fraction of a second. The widget renders markdown as it streams, shows typing state, and persists the conversation so a returning visitor picks up where they left off.
An embeddable widget that stays out of the way
Customers paste one script tag. The injector is a few kilobytes: it fetches the bot's public configuration, draws the launcher, and creates an iframe that loads the chat app from the CDN. Because the chat UI lives in an iframe, the host site's styles and scripts cannot break it and it cannot break them.
The injector also handles the awkward parts of living inside someone else's page: it fits the window to the available viewport so it never runs off a small laptop screen, goes full screen on phones, and supports a left, centre or right launcher with a configurable label and gradient.
Voice conversations
Visitors can switch from typing to talking. Audio travels over WebRTC through a self-hosted LiveKit server to a voice agent that transcribes speech with Deepgram, answers using the same retrieval pipeline and model as text chat, and speaks the reply back. Only text is stored, never audio, and links or long numbers are shown on screen instead of being read aloud.
AI-assisted bookings
The newest capability lets a bot book meetings. Businesses define appointment types, working hours and buffers; the assistant offers real slots, collects the visitor's details, verifies their email with a one-time code, and confirms the booking by email with an invite.
We learned quickly that you cannot leave a booking to the model's discretion. Language models will happily say 'you're booked' without doing it. So the critical steps are driven by the server: the availability engine is plain deterministic code, the model is forced to call specific tools at specific moments, a held slot only becomes a booking on an explicit confirmation, and a database exclusion constraint makes a double booking impossible even under concurrent requests. Reminders and emails run through a durable job queue with retries.
- Availability computed by a pure function from hours, existing bookings and buffers
- Postgres exclusion constraint on time ranges to prevent overlaps
- Forced tool choice for saving details, searching slots and confirming
- Email verification before a booking is confirmed or changed
- Bots only offer booking when it is enabled, on the plan, and fully configured
Choosing models
We benchmarked several Bedrock models on latency, tool-calling reliability and answer quality. Fast, inexpensive models handle most conversations well; larger ones are reserved for plans where depth matters. Because models are selected by configuration, switching one is a settings change rather than a rewrite, and each model has its own handling for tool-choice differences.
Operations and cost
- A single small EC2 instance runs the API, the voice agent and supporting services, with nginx terminating TLS
- Zero-downtime-friendly deploys: build, run idempotent migrations, restart processes
- Static dashboard and widget on Amplify and a CDN, so front-end traffic never touches the API box
- Secrets in AWS Secrets Manager and environment configuration, with least-privilege IAM roles
- Per-plan limits keep the cost of any single tenant bounded
Results
Figures describe the platform's design. Replace with your own measured results before publishing.
A business can sign up, add its website, style the assistant and embed it in minutes. Visitors get grounded answers that stream in instantly, can talk instead of type, and can book a meeting without leaving the chat. For us, the platform is a reusable foundation for AI agents with tenant isolation, retrieval, streaming and deterministic workflows already solved.
Lessons learned
- Ground every answer in retrieved context and let the bot say 'I don't know'
- Put anything that must be correct, such as bookings, in code, and use the model for the conversation around it
- Isolate the widget in an iframe and fit it to the viewport from day one
- Make models configuration, not architecture
- Scope every query by tenant at the data layer, not in the UI
Want an AI assistant or agent like this for your business? Get in touch and we will scope it with you.