Playbook
Building a chatbot with AI agents is genuinely a great project, and it's also where people wildly misjudge what's hard. The part everyone worries about — making the model talk — is the part agents nail in an afternoon. The parts that decide whether your bot is usable or embarrassing — memory, streaming, and guardrails — are the parts you have to design, and no agent will design them for you unless you tell it to. This playbook is the build order that gets you a chatbot people actually keep using, and a clear line between what agents do well and what you own.
The stack — four parts, not one
A real chatbot is four components, and skipping any of them is why so many demos never become products:
- A model + provider. The LLM behind an API. Bring your own key and pick by job — you don't need the biggest model to answer support questions.
- Streaming. Tokens appear as they're generated. This isn't polish; a chatbot that sits blank for eight seconds and then dumps a wall of text feels broken even when it's working.
- Memory. The conversation history the model sees each turn, plus any longer-term facts you persist. Without it, every message is amnesia.
- Guardrails. Input and output checks — what the bot refuses, what it must never leak, how it behaves when someone tries to jailbreak it.
The build order
Order matters because each layer is easier to get right on top of a working one below it.
- Bare request/response first. One endpoint: message in, model reply out, no streaming, no memory. Get a single turn working end to end before anything else. This is the "does my key and my plumbing work" step, and it's an agent's easiest task.
- Add streaming. Switch to the streaming API and pipe tokens to the client as they arrive. Server-sent events are the boring, correct default. Test it under a slow response so you know the UX holds.
- Add conversation memory. Keep the message history and send it back each turn, trimmed to a token budget so long chats don't overflow the context window. Decide your trimming rule now (keep the system prompt + last N turns is a fine start).
- Add persistence. Store conversations so they survive a refresh. A single table keyed by conversation id is enough — resist building a memory palace before you have users.
- Add guardrails. The system prompt that sets behavior, refusal rules, and an output check for anything you must never emit. This is where you decide what your bot won't do, which is as important as what it will.
What agents nail vs what you design
| Agents handle well | You must design | Effort |
|---|---|---|
| The API call, streaming plumbing, SSE wiring | The system prompt and persona | Low vs high |
| Conversation table and history trimming code | What to remember and for how long | Low vs high |
| A clean chat UI | Guardrails and refusal behavior | Low vs high |
The pattern is consistent: agents build the mechanism fast, and every judgment call — tone, boundaries, what "helpful" means for your use case — is yours. Spend your time there.
The guardrails you can't skip
A chatbot is a text box that runs a language model on user input, which makes it an attack surface. Before it's public:
- Never trust the system prompt to hold secrets. Assume users will try to extract it. Keep real secrets and keys server-side, never in the prompt.
- Treat model output as untrusted. If the bot's reply is rendered as HTML or used to trigger an action, sanitize it — prompt injection can turn a reply into an attack.
- Rate-limit and cap tokens. An open chat endpoint with your API key behind it is a way to spend your money fast. Cap per-user request rate and max tokens per reply.
- Log for review, but mind privacy. You need transcripts to improve the bot and to catch abuse; be deliberate about what you store and for how long.
Run the full AI coding security checklist before you ship — a chatbot touches more of it than most projects.
Picking models by job
You don't need one model for everything. For the conversational bot itself, a fast value model keeps latency low and costs sane — Gemini Flash's speed makes replies feel instant, and Sonnet 5 or GPT-5.3 Codex are strong, affordable defaults. Reserve a top model (Opus 4.8, or Fable 5 on our benchmarks) for the hard reasoning turns if your bot needs them, or for the agents building the app. Match the model to the turn, not the whole app.
Ship a v1, then grow it
Resist bolting on retrieval, tools, and multi-agent routing before you have a working single-turn bot people use. Get the four layers solid, ship, watch real conversations, and let those tell you what to add. When you do add tools or turn the bot into an agent that acts, the discipline scales: write tests that actually catch bugs around the guardrails, and get a cross-model pass through the AI code review workflow before anything that touches user data goes live. If you want the fuller path from idea to shipped product, shipping your first product with AI agents walks it end to end. A multi-agent harness like The Vibe Father lets a Builder wire the streaming while a Reviewer checks the guardrails in parallel — but a chatbot this size ships fine from a single terminal.