LESSON · 1 OF 5

Multi-turn conversations

Multi-turn conversations

A chat with a model looks like it remembers what you said, but nothing on the model's side is keeping notes. Every request starts from zero. The trick is that a conversation is just the messages list from the last topic, grown one turn at a time.

The history is the memory

You already know a request carries a messages list where each entry is a role and its content. A single turn holds one user message. To continue the conversation, you do two things and re-send the whole list:

  1. Append the model's own reply as an assistant message.
  2. Append your next user message after it.

After two turns the list looks like this:

json
"messages": [
  {"role": "user", "content": "What's a good language for a first web scraper?"},
  {"role": "assistant", "content": "Python is a solid choice - it has requests and BeautifulSoup."},
  {"role": "user", "content": "Show me the install command for those two."}
]

The third message says "those two" and never names the libraries. The model answers correctly anyway, because the earlier turns are sitting right there in the list it receives. The history you send IS the memory.

No memory between calls

Leave out the earlier messages and the model has no idea what "those two" means. It never stored your first question. Each call is independent, so every time you want continuity you resend the full running list. A chat app does exactly this behind the scenes - it keeps appending to the array and posting the whole thing on every turn.

Next: that growing list can't grow forever. The limit on how much it can hold is the context window.


Your lab setup

This VM comes preconfigured with your AI keys - just type claude to get started. Your key and URL are already set as $OPENAI_BASE_URL and $OPENAI_API_KEY.

Spin up a fresh environment and practice live.
linux-basic-ai · fresh machine · ready in under a minute