agents · Level 3

Build your first chatbot

From model access to a tested, logged chatbot that behaves: system prompt, history, guardrails, a test set and cost awareness.

By Mickarle Wagstaff-Irons - Micky Irons

  • Level 3Building
  • 105 min
  • 6 chapters
  • Free PDF, no account
The Loopagents / 03

Start with the essentials

The short answer

A chatbot is a language model wrapped in a small program that adds a system prompt, keeps the conversation history, applies guardrails and logs what happens. To build one, choose model access (a hosted API or a local model), write a clear system prompt, manage history within the context limit, test it on sample conversations and watch the cost.

What you will learn

  • You will be able to name the parts of a chatbot and say what each one does.
  • You will be able to choose between hosted and local models, and between a no-code and a code path.
  • You will be able to write a system prompt that sets the role, tone, guardrails and refusal behaviour.
  • You will understand conversation history and context limits, and how to keep both under control.
  • You will have a test set of sample conversations and a simple way to score them.
  • You will be able to log conversations responsibly and reason about what a chatbot costs to run.

Who it is for

Anyone ready to build a real chatbot for a small business, a project or a team. The no-code path needs no programming. The code path uses a short Python example that you can read without being an expert.

Before you start

  • Comfort with prompts, tokens and context windows (the What is AI and Your first prompts workbooks cover them).

Keep learning

The complete workbook

This workbook takes you from an idea to a working, tested chatbot. You will choose between hosted and local models, write a system prompt that sets behaviour, tone and refusals, manage conversation history, build a test set and count the cost. You can follow a no-code path or a short code path, and both end with a bot you can trust to try in private.

  1. 01
    What a chatbot is made of

    A chatbot looks like magic in a chat window, but it is a few ordinary parts working together. Build them one at a time and each becomes easy to understand and to fix.

    In the workbook · 1 exercise
  2. 02
    Model access: hosted or local, no-code or code

    Two choices shape everything else: where the model runs, and whether you write code.

    In the workbook · Reading
  3. 03
    The system prompt: behaviour, tone and refusals

    The system prompt is the standing instruction sent with every request. It is the biggest single lever you have over how the bot behaves.

    In the workbook · 1 exercise
  4. 04
    Conversation history and context limits

    The model has no memory of your chat. The feeling of memory comes from your program sending the conversation again on every turn.

    In the workbook · Reading
  5. 05
    Test, measure, log and watch the cost

    A chatbot that seems fine in three tries can fail badly on the fourth. A test set turns hunches into evidence.

    In the workbook · 1 exercise
  6. 06
    Build it: two paths

    Now put the parts together. Choose one path, or start with no code and move to code once the prompt is right.

    In the workbook · 1 exercise

Also inside: a 9-point checklist, a glossary of 12 terms and 10 questions and answers to test yourself. 4 hands-on exercises, each with a worked answer at the back where the workbook gives one.

No login, no card, no account. Before the download we ask you to follow Mickai (two quick links). Free to download and use for personal learning, study groups and inside your own team. Please do not resell the workbooks or republish them as your own. Link people to trust-agent.ai instead.

Test yourself

Questions and answers

Do I need to code to build a chatbot?

No. Many hosted builders let you paste a system prompt, upload documents and share a link without any code. Coding gives more control over logging, testing, limits and connections to your own systems, and you can move a good prompt from one path to the other.

Should I use a hosted or a local model?

Hosted is quicker to start and reaches strong models, but conversations go to the provider. Local keeps data with you and avoids per-message fees, but you manage the hardware and models are often smaller. Sensitive data or offline use points to local.

What is a system prompt?

It is the standing instruction sent with every request. It sets the bot's role, rules, tone and what to do when unsure or asked something out of scope. It is your biggest lever, but it is a request to the model and not a lock.

Why does a chatbot seem to remember, when the model does not?

Your program resends the conversation on every turn. The model reads it fresh each time. Anything left out of what you send is forgotten, which is why you must trim, summarise or pin facts as chats grow.

How do I stop a chatbot inventing answers?

Tell it to answer only from information you supply, and that saying it does not know is a good answer. Give it a handover route. Then test with questions it cannot answer. For document-based answers, retrieval with citations helps further.

How many test conversations do I need?

Start with fifteen to twenty across everyday, missing-information, out-of-scope, rule-breaking, upset and sensitive types. Add a new test every time you find a bug. Re-run the whole set after every change to the prompt or model.

How do I keep costs under control?

You pay roughly for tokens sent and received on every call. Shorten the system prompt, trim history, cap reply length, limit messages per user per day and use a smaller model for simple questions. Check your provider's current prices.

Should I log conversations?

Logs are valuable for finding failures, but they hold personal data. Keep only what you need, never log secrets, tell users what you record, and delete it on a schedule. If you are unsure, log less.

Can I keep secrets in the system prompt?

No. Users can often coax a bot into revealing or ignoring its instructions. Keep passwords, keys and private data out of the prompt and enforce important limits in your own code.

How do I know the chatbot is ready to launch?

When it passes your test set consistently, refuses and hands over well, stays within its cost limits and has behaved well with a small group of trusted testers. Then launch to a few more people, not everyone at once.

When you have finished

Get your certificate of completion

Type your name and download a certificate for this workbook as a PDF, ready to print or to add to LinkedIn. It is made on your own device, so your name is never sent to us. It is a self-declared certificate, not an accredited qualification.

Learn the language

Key terms

Hosted model
A model that runs on a provider's computers and is reached through an API, usually paid for by use.
Local model
A model that runs on hardware you control, so conversations do not leave it.
API
A defined way for one program to send requests to another and receive replies.
API key
A secret code that identifies you to a hosted service. Anyone holding it can use your account.
System prompt
The standing instructions sent with every request that set the bot's role, rules and tone.
Conversation history
The earlier messages that your program resends so that the model can follow the thread of the chat.

6 of the workbook's 12 terms. The complete glossary is in the workbook.

Follow the evidence

Sources and checks

Facts last checked: .

These workbooks use AI assistance. See how the workbooks are made.

  1. Guidance on AI and data protectionInformation Commissioner's Office (ICO)
  2. OWASP Top 10 for LLM ApplicationsOWASP Gen AI Security Project

Created by Mickarle Wagstaff-Irons - Micky Irons with the Mickai team. Published by Mickai LTD. Last updated 25 September 2026.

NextKeep going

Where to go next