Short-Term Conversation Memory › How Conversation History Works

Michael BrenndoerferJuly 1, 20251 min read
AI Agent HandbookAll chapters
Part 6 of 15Memory and Retrieval - How Agents Remember
Chapter 15Short-Term Conversation Memory › How Conversation History Works
Reading section 4 of 15 · How Conversation History Works · 1 minSection 4 of 15 · 1 min

Book contents

Section 4 of 15 · 1 min read

Short-Term Conversation Memory › How Conversation History WorksOne section · Sections in this chapter4 / 15 ↓

Let's look at what's actually happening behind the scenes. After the two-question exchange above, our history list contains:

In[6]:
Code
[
    {"role": "user", "content": "What's the capital of France?"},
    {"role": "assistant", "content": "The capital of France is Paris."},
    {"role": "user", "content": "What's the population?"},
    {"role": "assistant", "content": "Paris has a population of approximately..."}
]
Out[6]:
Console
[{'role': 'user', 'content': "What's the capital of France?"},
 {'role': 'assistant', 'content': 'The capital of France is Paris.'},
 {'role': 'user', 'content': "What's the population?"},
 {'role': 'assistant',
  'content': 'Paris has a population of approximately...'}]

Each message is stored with its role (either "user" or "assistant") and content. When you ask a new question, the entire list goes to the model. The model sees the full conversation thread and can reference earlier messages.

Think of it like showing someone a chat transcript. They can read the whole conversation and understand the context of the latest message. That's exactly what we're doing with the language model.