The anatomy of a prompt: system, user, assistant
If you ever wondered why ChatGPT "remembers it is Claude" or "stays in character", it is the system message. Mastering message roles is what separates hobbyists from engineers.
A play has three speakers: the director (system), the audience member who asks (user), the actor who responds (assistant). The director's notes set the stage. The audience asks. The actor delivers, then waits for the next prompt.
Modern chat APIs use a list of messages, each with a role:
- system: instructions, persona, constraints, format rules. Persistent and high priority.
- user: the human's request.
- assistant: the model's previous responses, sent back so the model has memory of what it already said.
- tool (newer): structured outputs from tool calls.
The API takes the entire array each call. There is no hidden server-side memory unless you build it. You manage memory.
A typical OpenAI call:
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a concise tutor. Answer in 2 sentences."},
{"role": "user", "content": "Explain RAG."},
],
)
print(response.choices[0].message.content)
Add the assistant reply back into messages for the next turn. That is conversation memory.
Quick recall
3 prompts · think before you flip
Prompt 1 of 3
What are the three core message roles?
Quiz time
1 question · tap an answer to check it
1. To make a chatbot remember what it said two turns ago, you must
Finished lesson 3.2?
Mark complete to update your module progress and unlock the streak.