# Conversation State

What the system remembers and re-sends across turns — history, summaries, extracted facts and pending actions.

**Rests on:** Agent Loop, Agent Memory Systems

**Leads to:** Conversational Agents

*AI Agents · AI Agents*


## Why learn this

Every time you chat with an AI assistant, it appears to remember your previous messages. That memory is not magic; it is a specific technical constraint that shapes how the system works. In this page you will learn exactly what information is stored and sent forward each time you type a message, why the system cannot keep every word of every conversation forever, and how summarizing, extracting key facts, and tracking tasks helps manage that limit. Understanding this process is essential for using AI agents effectively — systems that plan, call external tools, and perform multi-step work. If you do not understand how memory works here, your agents will forget who you are, repeat themselves, or fail at complex tasks because they lost the thread of what was discussed.


## The intuition

Imagine you are a customer service agent at a company. A customer calls, and you have only a small notepad. As the conversation goes on, you write down the key points: 'Customer's name is Priya', 'Problem with order #12345', 'She wants a refund'. You cannot write the whole conversation — there is no space and you would drown in detail. So you write a summary, you note the important facts, and you keep a list of what needs to happen next. When the next person takes over the call, you hand them the notepad. That notepad is the conversation state. In AI systems, this 'notepad' is a collection of data that stores the history of messages, a compressed summary, extracted facts, and a list of pending actions. Every time the model needs to respond, it reads this notepad and sends it back along with your new message. This notepad has a size limit — the maximum amount of text it can process at once — so you must decide what to keep and what to throw away. If you throw away something important, the model can no longer reason about it because that information is gone.


## An analogy

Think of the AI's memory like a whiteboard in a classroom. You and the AI are solving a problem together on this board. The AI reads whatever is written there to understand where things stand. But the whiteboard is only so big — you cannot write an entire novel on it. So, as new information comes in, old details fade or get wiped off to make room for what matters now. The AI might keep a list of key facts ('Priya's allergy: nuts') and a to-do list ('Send recipe'), but the full transcript of what was said five minutes ago is gone unless it was specifically saved to a separate note. The rule of this analogy is that if information is not currently on the whiteboard (the active state), the AI has no way to know it exists. It does not have an intuition or a gut feeling; it only knows what is written in front of it. That is why managing what goes on the board is critical.


## Definition

Conversation state is the specific set of information — including message history, summaries, facts, and tasks — that represents the current context of a dialogue and is provided to the AI model each time it generates a response. This set of information is constrained by the context window, which is the maximum amount of text the model can process in one turn.


## How it connects

This concept is the foundation for understanding AI agents, which are systems that perform multi-step actions rather than just answering questions. Conversation state provides the 'memory' that allows an agent to connect today's action to yesterday's plan. It also directly relates to the context window, which is the physical limit on how much information can be in that state at any given time. While conversation state defines *what* is remembered, the context window defines *how much* of that memory can fit into the model's immediate processing space.


## From scratch, in Python

```python
# We'll build a minimal conversation state manager.
# We'll use a list to store messages, a dictionary for facts, and a list for pending actions.

messages = []  # list of dicts: {'role': 'user' or 'assistant', 'content': '...'}
facts = {}      # dict: key = fact name, value = fact value
pending_actions = []  # list of strings

def add_message(role, content):
    messages.append({'role': role, 'content': content})

def add_fact(key, value):
    facts[key] = value

def add_pending_action(action):
    pending_actions.append(action)

def build_prompt(new_user_message):
    # Compose the full prompt from state + new message
    prompt_parts = []
    if facts:
        prompt_parts.append("Known facts: " + str(facts))
    if pending_actions:
        prompt_parts.append("Pending actions: " + str(pending_actions))
    for msg in messages:
        prompt_parts.append(msg['role'] + ": " + msg['content'])
    prompt_parts.append("user: " + new_user_message)
    return "\n".join(prompt_parts)

# Example usage
add_message('user', 'Hi, I want to order a pizza')
add_message('assistant', 'Sure, what size?')
add_fact('size', 'large')
add_fact('topping', 'paneer')
add_pending_action('confirm price')

prompt = build_prompt('What is the total?')
print(prompt)
```


## What the code does

First we create an empty list for messages. A list holds things in order — here we'll store one item per message. Each message is a dictionary, which maps names to values: the role (who said it) and the content (what was said). Then we have a dictionary for facts — that lets us look up a fact by name. The pending actions is a list of strings. The function add_message appends a new dictionary to the messages list. The function add_fact sets a key in the facts dictionary. add_pending_action appends to the actions list. The build_prompt function glues everything together into a single block of text that we would send to the model. It starts with the facts and pending actions, then the history, then the new user message. The output shows what the model would see: the facts, the pending actions, the history, and the new message. This is the essence of conversation state — the data structure, and the function that serialises it into a prompt.


## Common misconceptions

**The model remembers the conversation by itself** — The model has memory chips, so it remembers what I said last turn automatically.

The model is stateless — it has no memory of previous turns. Each time you send a message, the model sees only what is in the input text. The conversation history is part of the input, not a hidden memory. In fact: The system (the application) stores the conversation history and re-sends it along with each new message. The model itself forgets everything after each response.

**The raw transcript is the best thing to keep** — I should just keep the full chat log and send it all — that way nothing is lost.

The full log grows without bound and will eventually exceed the context window. Also, it may contain irrelevant noise. If the system truncates the log, the model loses early information. In fact: You must compact — summarise old messages, extract key facts and pending actions. This loses detail but preserves the information the task needs.

**A summary keeps all the important information** — If I write a good summary, the model can still answer any question about the earlier conversation.

A summary is lossy. It cannot capture every detail — a specific number, a name, a tone. Once summarised away, that detail is gone and the model cannot reason about it. In fact: Summaries are a tradeoff. You keep the main points, but you must deliberately choose which details matter and keep them in a structured fact list if you need precise retrieval.

**Bias means the model is unfair** — Bias in this context is about the model having prejudice.

Bias here is a technical term from the neuron formula — it is a constant added to the weighted sum, shifting the activation threshold. It has nothing to do with fairness. In fact: Bias is a learned number that shifts the neuron's output. It is not about fairness, though model bias in the ethical sense is a separate issue.


## In short

Conversation state is what the system remembers and re-sends across turns — history, summaries, extracted facts and pending actions. The model is stateless, so everything must be in the state. Because the context window is finite, you must compact. What you summarise away is what the model can no longer reason about. Explicit state — a structured representation — beats relying on the raw transcript.


## Where this is used

Conversation state is the backbone of every conversational AI system. In large language models like ChatGPT or Claude, the state is managed by the application layer: every time you send a message, the app retrieves the entire state — the message history, the summaries, extracted facts — and constructs a prompt that includes all of it. The model itself has no memory; it sees only the prompt. So the state is what makes the conversation feel continuous. In small language models that run on a phone or a laptop, the context window is much smaller, so compaction is even more critical. You might keep only the last few messages and a tightly written summary. Retrieval-augmented generation (RAG) also uses state: the system remembers the user's questions and the retrieved documents, and it might store which documents have been seen so it does not retrieve them again. In agentic systems, state is the agent's memory. The agent loop — decide, act, observe, repeat — relies on state to remember the goal, the steps taken, the results of tool calls, and the next action. For example, an agent that books a flight must remember the departure city, the destination, the date, and the passenger name. That is all in the state. A developer building a chat agent typically uses a framework like LangChain's ConversationBufferMemory or ConversationSummaryMemory, or they build their own state manager. What breaks when it is done badly: the model forgets important details, repeats itself, or hallucinates facts because the state was summarised too aggressively. The most important rule is: what you summarise away is what the model can no longer reason about. Good state design preserves the facts that matter, keeps the history as long as possible, and compacts only when necessary.


---

Read this on the web: https://basavapurushottam.com/learn-ai/conversation-state
