Chatbot from Scratch · Chapter 5

A character

Ask our bot who it is and it says "a large language model". This chapter gives it a job and a name: Volt, the assistant of a small electronics shop. A few lines of plain text, in their own file, change how every answer sounds.

One sitting~10 min read, ~40 min to build along (the agent works for about twenty of them)
You needthe project from Chapter 4, Antigravity, your own key in .env
You builda system prompt in its own file, a Character tick, three versions you can switch and edit
Chapter 5after Chapter 4 · memory

Prefer to watch? This chapter goes with Episode 5 (7:04). Open it on YouTube.

Subscribe on YouTube

Goes with Episode 5"How do I give my chatbot a character?". Watch it just above, or build along here at your own pace.
Before you startThe project from Chapter 4, with its two memories and its .venv. Antigravity, signed in: install Antigravity on Windows. And your own Gemini key in .env.
The code, ready to runDownload this chapter's code (zip). Every chapter's code is on GitHub. Add your own .env with GEMINI_API_KEY; the README shows the setup.

Who are you?

Chapter 4 gave our window a short-term and a long-term memory. It ended on a question the bot could not answer about itself.

Our project after Chapter 4: you, ui.py the window with its Settings menu, bot.py with ask() and usage(), the key in .env, short-term and long-term memory going to bot.py, and Gemini 3.1 Flash Lite in Google's cloud.
Where Chapter 4 left us.

Run python ui.py and ask Who are you? The reply: "I am a large language model, trained by Google." Ask Do you sell USB-C cables? and it says no: it is an AI, with no shop at all. It knows nothing about who it works for, because nobody told it.

No character yet, sped up. Watch this step in the video.
The question for this chapter

How do I give my chatbot a character?

AI Studio has a box for it

In Google AI Studio, on the same model, the Run settings panel has a card called System instructions. Open it and type two lines: You are Volt, the assistant of Volt Electronics, a small electronics shop. Answer in at most 3 sentences. Then ask Who are you? The answer comes back as Volt, "your helpful assistant here at Volt Electronics". Our window has no such box yet.

Two lines in AI Studio, sped up. Watch this step in the video.

What a system prompt is

That box holds a system prompt: instructions that go with every call. It is not one of your messages. It travels on its own, as the call's system instruction, and it sits above everything else the call carries.

What one call sends, top to bottom: 1, the system prompt, who the bot is, every call, as the system instruction; then in the contents: 2, the summary of the older chat; 3, the last exchanges, word for word; 4, the new question.
One call: the system prompt on its own, then the memory and your question.

The character prompt

We keep the character in a file of its own, so you can read it and change it like any other text. Make a new file, prompts/05-character.txt.

prompts/05-character.txt
Task : Give the bot a character: a system prompt that makes it the assistant of our electronics shop

Context :
- Use the virtual environment .venv in this folder. Don't create a new one.
- Today the bot has no instructions of its own, so when I ask who it is, it says it is a large language model.
- Add a system prompt: instructions sent with every call, before the summary and the history.
- Send it as the system instruction of the call, not as a chat message.
- Keep the system prompt in a file, prompts/system/shop-assistant.txt, so I can read and change it.
- Write that file for me: the bot is Volt, the assistant of Volt Electronics, a small electronics shop.
- Volt is friendly and brief, answers in at most 3 sentences, and helps with our products, prices, orders and returns.
- Volt politely declines questions that have nothing to do with the shop, and says what it can help with instead.
- Volt never makes up a price or a product it does not know; it says it will check with the shop.
- Add Settings > Character: a tick I can select or unselect. It starts selected.
- When it is unselected, send no system prompt, as before.
- The grey status line also shows the character, for example: Character: Volt (shop assistant).
- The system prompt is sent with every call, so count its tokens in the tokens in, as before.
- Keep the memory, the settings, the token counter and everything else as it is.
- Keep ask() working for the terminal chat, with the character on.

Folder arch :
- ui.py : the window (frontend)
- bot.py : the chatbot (backend), now with the system prompt
- prompts/ : our prompts
- prompts/system/ : the system prompts

Volt never invents a price: when it does not know, it says it will check with the shop. The tick lets you compare the bot with and without its character.

Type into the agent panel
Review and implement prompts/05-character.txt

When it is done, the agent has changed 4 files and written prompts/system/shop-assistant.txt.

Volt, live

The file the agent wrote is five short lines:

prompts/system/shop-assistant.txt
You are Volt, the friendly assistant of Volt Electronics, a small electronics shop.
Always be friendly and brief, answering in at most 3 sentences.
You help customers with our products, prices, orders, and returns.
If asked about a price or a product you do not know, never make it up; say that you will check with the shop.
If asked questions that have nothing to do with the shop, politely decline and say what you can help with instead.
Type in the terminal
python ui.py

The grey line under the menu bar now ends with Character: Volt (shop assistant). Ask Who are you? and it introduces itself as Volt, the friendly assistant of Volt Electronics. Look at the grey line under that reply: 104 in. Three words of question, about a hundred tokens of character, sent along every time.

Ask about USB-C cables: it says yes, the shop carries them, and offers to check the price instead of inventing one. Ask for a poem about rain: it politely declines and says it only helps with the shop.

Now Settings › Character to untick it, then Settings › New chat, and ask again: "I am a large language model, trained by Google", with only 5 in.

Why the counter in the corner still shows 500-plus after New chatThat number is the total for the whole session, every call since the window opened. New chat clears the memory, not that running total. The grey line under each reply (5 in) is what that one call cost.
Volt in character, sped up. Watch this step in the video.

Three ways to write it

The same character can be written more than one way: only the role; the role plus the steps to follow for every answer; or the role plus a few sample questions with the exact answers you want. Each one tells the model a little more about the shape of a good reply.

The versions prompt

A second file, prompts/05-styles.txt, asks for those three versions side by side, a menu to switch between them, and a small editor.

prompts/05-styles.txt
Task : Let me switch between three versions of the shop assistant's system prompt, and edit them in the window

Context :
- Use the virtual environment .venv in this folder. Don't create a new one.
- Today there is one system prompt, prompts/system/shop-assistant.txt.
- Add two more versions of the same assistant, each in its own file in prompts/system/:
- role.txt : only the role, in 2 lines: who Volt is and what it helps with.
- step-by-step.txt : the role, then the steps Volt follows for every answer: understand the question, check it is about the shop, answer in at most 3 sentences, offer one next step.
- examples.txt : the role, then 3 short example questions with the exact answers Volt should give, one of them a polite refusal.
- Rename shop-assistant.txt to step-by-step.txt if it already holds steps; otherwise keep it as a fourth version.
- Add Settings > Character version: a choice of the versions found in prompts/system/.
- Add Settings > Edit character...: a small window with the current version's text, a Save button and a Cancel button.
- Save writes the file and uses the new text from the next question on.
- Settings > New chat keeps the chosen version.
- The grey status line shows the version, for example: Character: Volt (examples).
- Keep everything else as it is.

Folder arch :
- ui.py : the window (frontend)
- bot.py : the chatbot (backend), with the system prompt versions
- prompts/ : our prompts
- prompts/system/ : the system prompt versions
Type into the agent panel
Review and implement prompts/05-styles.txt

This time 6 files changed: click Accept all. prompts/system/ now holds four files: role.txt, step-by-step.txt, examples.txt and the first shop-assistant.txt.

Here are the three new versions. examples.txt is shown as it is after the live edit below.

prompts/system/role.txt
You are Volt, the friendly assistant of Volt Electronics, a small electronics shop.
You help customers with our products, prices, orders, and returns.
prompts/system/step-by-step.txt
You are Volt, the friendly assistant of Volt Electronics, a small electronics shop. You help customers with our products, prices, orders, and returns.

For every answer, follow these steps:
1. Understand the question.
2. Check that it is about the shop. If not, politely decline and say what you can help with instead.
3. Answer in at most 3 sentences. Never make up a price or product you do not know; say you will check with the shop.
4. Offer one next step.
prompts/system/examples.txt
You are Volt, the friendly assistant of Volt Electronics, a small electronics shop. You are friendly and brief, answer in at most 3 sentences, and help with our products, prices, orders, and returns. Never make up a price or product you do not know; say you will check with the shop.

Example 1:
User: Do you sell wireless earbuds?
Volt: Yes, we carry several brands of wireless earbuds starting at $29.99. You can visit our shop to try them out or order directly with us. Would you like to know which models we have in stock?

Example 2:
User: Can you write a Python script for me?
Volt: I can only help with questions related to Volt Electronics and our shop. I would be happy to assist you with our products, prices, orders, or returns instead!

Example 3:
User: How much is the SuperSonic 8K TV?
Volt: I am not certain of the current price for that TV, so I will check with the shop and get back to you. Would you like me to check our available television models?

Always end with: Anything else I can help with?

One honest note: the first example answer has a sample price in it. It is only an example inside the prompt, not a real price; the real price list comes in Chapter 6.

One question, three answers

Pick each version from Settings › Character version, start a new chat, and ask the same thing: My order has not arrived. What can I do?

VersionThe answerTokens inTokens out
roleFour paragraphs: sympathy, a request for the order number, a promise to check, a closing line44127
step-by-stepThree short sentences, asking for the order number12345
examplesTwo sentences, in the shape of the sample answers24931
One assistant, three system prompts, same question My order has not arrived: role only, 2 lines, 127 tokens out; step by step, the role plus how to answer, 45 out; examples, the role plus 3 sample answers, 31 out.
The more the prompt shows, the tighter the answer, and the longer the prompt.
Three versions, one question, sped up. Watch this step in the video.

Then Settings › Edit character… opens the current version. Add one line at the end, Always end with: Anything else I can help with?, click Save and ask again. The reply now ends with that line: the new text is used from the next question on.

Memory still works

A character does not replace memory; it sits above it. Start a new chat, say My name is Adi., ask about a cable, then ask your name: "Your name is Adi. Anything else I can help with?"

Our project after Chapter 5: you, ui.py with its Settings menu, bot.py, the key in .env, short-term and long-term memory, and a new part in orange: the character from prompts/system/, Volt in 3 versions, sent as the system instruction. Gemini 3.1 Flash Lite in Google's cloud.
Our project so far. The new part is in orange: the character.

Quick reference

Every command and menu from this chapter. The prompts are above.

Command or menuWhat it doesUse it when
Review and implement prompts/05-character.txtAdds the character and its fileAfter writing the first prompt
Review and implement prompts/05-styles.txtAdds three versions, the menu and the editorAfter the second prompt
python ui.pyOpens the windowTo try each version
Settings › CharacterSends the system prompt, or notTo compare with and without
Settings › Character versionPicks a file from prompts/system/To compare the versions
Settings › Edit character…Edits and saves the current versionTo change how Volt answers

The takeaway

  1. A system prompt is sent with every call as the system instruction, not as a chat message, and it costs tokens every time.
  2. Keeping it in its own file makes the character plain text you can read, switch and edit.
  3. Role only gives loose answers; steps and examples give tighter ones, at the price of a longer prompt.

Next: today's date and a price list

Ask Volt for today's date and it can only say it helps with the shop. Ask the price of the 20W charger and it has to check with the shop. In Chapter 6 it gets both: today's date, and our own product sheet.

It knows nothing of our shop yet, sped up. Watch this step in the video.

References

Where each number on this page comes from. Everything was also checked in our own recording on 20 Nov 2026.

  1. Google · Text generation: system instructions A system instruction steers the model for the whole request, separate from the conversation. https://ai.google.dev/gemini-api/docs/text-generation
  2. Google · Google AI Studio The System instructions box in Run settings. https://aistudio.google.com
  3. Learn AI by Building · chatbot-from-scratch on GitHub This chapter's finished code and prompts. https://github.com/Aditya-402/chatbot-from-scratch
  4. My own recording · 20 Nov 2026, Windows 11 Every answer and token count on this page is from those takes, on Gemini 3.1 Flash Lite.
← Chapter 4MemorySeriesAll chapters