الانتقال إلى المحتوى
أساسيات الـ AIمفاهيم الـ AI· 6 دقائق للقراءة

The Context Window Is Not Memory: LLMs Are Stateless Between Calls

Every request starts from zero: the conversation lives in your app, and the model only sees what you send.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

A developer wires a support chatbot to an LLM API. In the demo, the user types "Hi, I'm Mona", then "What's my name?", and the bot says it doesn't know. The ticket reads: "Model forgets context. Try a bigger model?" A bigger model won't help. The bug is one line: the code sends only the newest message, so the model never saw the first one.

The common misconception

"The model remembers earlier chats and learns from them, because the conversation is stored inside it." Plenty of experience points that way:

  • In a chat app, the assistant refers back to something you said twenty messages ago, as if it had been listening all along.
  • Chat products manage history for you, so you never see that it's being sent again.
  • Give a model three examples of a format and it follows the pattern. That looks like learning.
  • Some assistants recall your preferences across separate chats.

The half-truth: within one request, the model really does use everything in front of it. But "in front of it" is the whole story. Nothing is written back into the model, and nothing carries over to the next request unless someone sends it again.

What actually happens

Every call starts from zero

Anthropic's docs put it directly: the Messages API is stateless, so you always send the full conversational history. Each request carries the system prompt and every earlier turn your app decided to include. The model reads that, generates a reply, and the request is over. Its parameters were fixed when training ended; your conversation doesn't change them.

Even when a provider keeps the conversation for you, the model still isn't remembering. Anthropic's message threads (in beta) let a later request send only the new messages, but it's storage around the model, and a thread expires five minutes after its last request. The history is still fed back in as input.

The context window is working memory for one request

The is all the text the model can reference while generating a response, including the response itself. Anthropic's docs call it a "working memory", distinct from the huge corpus the model was trained on. Everything counts against it: the system prompt, every message, tool definitions and results, and the output being generated.

In a conversation, each user message and assistant reply accumulates, so every new request is bigger than the last. The window has a hard size, up to 1M tokens depending on the model, and a request whose input alone exceeds it fails with a "prompt is too long" error. Size isn't the only limit: the docs warn that accuracy and recall degrade as the token count grows, which they call context rot.

In-context learning isn't training

The GPT-3 paper showed that a large model can do a new task from a few examples written into the prompt, applied "without any gradient updates or fine-tuning". That's : the examples steer this request only. Leave them out of the next request and the skill leaves with them. Correcting the model in chat works the same way: the correction is just more context.

So where does "memory" come from?

From code outside the model. Your app stores the messages and resends them; a chat product may drop or summarize the oldest turns to fit; a memory feature saves notes and puts the relevant ones back into the prompt. Anthropic's memory tool makes the split explicit: Claude asks to read or write files under /memories, your application performs those operations on storage you control, and the docs say the memory lives entirely in your application.

See it in code

Both versions call the same stateless API with the official Python SDK. The first sends only the newest message; the second keeps the history in the app and sends all of it every time.

Python chat.py
import anthropicclient = anthropic.Anthropic()def ask(text):    reply = client.messages.create(        model="claude-opus-5-5", max_tokens=16000,        messages=[{"role": "user", "content": text}],  # only the new turn    )    return next(b.text for b in reply.content if b.type == "text")ask("Hi, I'm Mona.")print(ask("What's my name?"))  # the model never saw "I'm Mona"

The right version appends reply.content, the full list of blocks, not just the text, so anything the API needs back on the next turn is preserved. It reads the answer from the first text block rather than content[0], because a reply can start with other blocks, such as thinking.

MythReality
The model stores our conversationYour app or the chat product stores it and sends it again
The context window is long-term memoryIt's one request's working memory: input plus the reply being generated
Examples and corrections teach the modelThey steer this request only; the weights don't change
A bigger window means it remembers everythingIt holds more, but recall degrades as the context grows
Memory features live inside the modelThey're storage outside it that puts saved notes back into the prompt

How to apply it in your project

  1. Own the transcriptTreat the message list as application data. Persist it, version it and decide in code what each request includes.
  2. Budget the contextCount tokens before sending long requests and set a limit below the model's window. When a conversation nears it, summarize older turns or use the provider's compaction feature.
  3. Make long-term memory explicitStore durable facts, such as a user's language or plan, in your own tables or a memory tool. Inject only the relevant ones into the prompt, and let users see and delete them.
  4. Put lasting corrections in the promptIf users keep correcting the same behavior, the model won't learn it from them. Fix it once in the system prompt or in your examples, and verify the change with an evaluation.

Key takeaways

  • The model is stateless between calls: it only knows what the current request contains.
  • The context window is working memory for one request, including the reply, not storage that persists.
  • In-context learning and in-chat corrections steer one request; they never update the weights.
  • Chat memory is built outside the model, by storing history or notes and sending them again.
  • Resending history costs tokens every turn, so budget, trim and compact deliberately.

📚 المصادر

  1. Using the Messages API: multiple conversational turns — Claude API Docs
  2. Context windows — Claude API Docs
  3. Memory tool — Claude API Docs
  4. Brown et al., Language Models are Few-Shot Learners (GPT-3), arXiv:2005.14165

التعليقات (0)