Module 2 · AI Chat Assistant · Lesson 5 of 34

Anatomy of a chat assistant

Roles, messages, a stateless API and the context window: what really happens when you press Send.

In this lesson · about 18 minutes

  • Name the three message roles and what each is for
  • Explain why the app must resend the whole conversation every turn
  • Predict what happens when a conversation outgrows the context window

A chat app looks like a conversation with someone who remembers you. Under the hood it is much simpler. Each time you press Send, the app makes one request to the model's API, and that request contains a list of messages, each with a role:

  • system: the instructions from the app's builder. Who the assistant is, what it may and may not do, the tone, the format. The user normally never sees it.
  • user: what the person typed.
  • assistant: what the model said earlier in the conversation.

The model reads the whole list and writes the next assistant message. Then it forgets everything. The API is stateless: the model keeps nothing between requests. The "memory" you feel is your app sending the entire history again, every single turn.

A request in Python looks roughly like this (each provider's library differs a little):

reply = client.chat(
    model="some-chat-model",
    max_tokens=300,
    temperature=0.3,
    messages=[
        {"role": "system", "content": "You are Pip, a help-desk assistant..."},
        {"role": "user", "content": "How do I reset my password?"},
    ],
)
print(reply.text)

Try it · simulator

Inside a chat request

Send the messages of a help-desk chat one by one. See the exact request your app sends, how many tokens it costs and what happens when the chat outgrows the context window.

No messages yet.

Messages in request

0

Input tokens now

0

Room left

240

Input tokens billed so far

0

The request your app sends (simplified)

// Press “Send the next message” to build the first request.
Every turn, your app resends the whole conversation. Watch the input tokens climb, and what happens when they hit the window. With the default window, watch what Pip remembers by turn 6. Then try the summary strategy.

Check your understanding0 of 3 correct

Question 1

1.Where does a chat assistant's memory of earlier turns actually live?

Question 2

2.Which role carries the builder's rules, such as “answer in two sentences”?

Question 3

3.A user's first message said they are vegetarian. Forty turns later the assistant suggests a steak. What is the most likely cause?

Quiz score: 0 of 3

Tip: answer every quiz question correctly first.

Written by Noviq Academy in its own words. The simulators are small teaching models that keep the real idea and leave out the scale; their numbers (prices, speeds, scores) are illustrative. Model names, prices and features change quickly, so check your provider's current documentation before you build. Read-aloud uses your device's built-in voices.