Velamuvi AIAcademy

Lesson 1 of 5 · Memory

Why Agents Forget

Why LLM agents forget: models are stateless and context windows are finite. The types of agent memory, and why a bigger window isn't the whole answer.

  • 7 min read
  • Intermediate
  • Reviewed
In this lesson you will learn
  • Explain why a language model remembers nothing between requests
  • Show how a full context window makes an agent forget older details
  • Name the main types of agent memory: short-term, semantic, episodic and procedural
  • Explain why a bigger context window doesn't solve memory on its own

The model remembers nothing

Chat with an assistant for an hour and it seems to remember everything you said. It doesn't. The language model behind it is stateless: each request is handled on its own, with no record of earlier requests.

What looks like memory is the application doing the work: before every call it sends the system prompt, the earlier messages and the new message together. The model reads all of it from scratch, every time.

Watch an agent forget

Resending everything works until the conversation outgrows the window. Then the application has to drop something, and the usual choice is the oldest messages. Here a user mentions an allergy in the very first message, then chats for a few weeks:

Try it yourselfPython
# Why agents forget: the model only sees what is sent in THIS request,
# and everything sent must fit in the context window.
CONTEXT_WINDOW = 1_000          # a tiny window, in tokens, to make the effect visible

def tokens(text):
    return len(text.split()) * 4 // 3      # rough rule: about 4 tokens for every 3 words

conversation = [("user", "Hi, I'm Mei. I'm allergic to peanuts.")]
for day in range(1, 40):
    conversation.append(("user", f"Day {day}: please suggest a dinner recipe with what's in season this week."))
    conversation.append(("assistant", f"Day {day}: here is a seasonal recipe with vegetables, grains and herbs " * 2))

def fit_to_window(messages, limit):
    """Keep the most recent messages that fit. Older ones are dropped."""
    kept, used = [], 0
    for role, text in reversed(messages):
        if used + tokens(text) > limit:
            break
        kept.insert(0, (role, text))
        used += tokens(text)
    return kept, used

kept, used = fit_to_window(conversation, CONTEXT_WINDOW)
print(f"Conversation: {len(conversation)} messages, about {sum(tokens(t) for _, t in conversation):,} tokens")
print(f"Sent to the model: last {len(kept)} messages, {used} tokens")
print("Does the model still know about the peanut allergy?",
      any("peanut" in text for _, text in kept))

The window here is tiny so the effect is easy to see, but real agents hit the same wall: long chats, big tool results and pasted documents fill even a window of hundreds of thousands of tokens. The allergy was mentioned once, at the start, so it was the first thing to go. Nothing failed with an error; the agent just quietly stopped knowing.

Types of agent memory

Researchers borrow names from human memory to describe the options. You'll see these terms in papers and agent frameworks:

TypeWhat it holdsExampleWhere it usually lives
Short-term (working)The current conversation and taskThe last few messages, the latest tool resultThe context window
SemanticFacts about the user or the world“Mei is vegetarian and lives in Lyon”A database or vector store
EpisodicPast events and experiences“Last month's trip booking failed because the card expired”A log or vector store of past sessions
ProceduralHow to do thingsThe system prompt, rules, learned instructionsPrompts, code and config

This course follows that order: short-term memory and how to manage it (lessons 2 and 3), long-term memory in a vector store (lesson 4), and the policy for deciding what deserves to be remembered (lesson 5).

Why not just use a bigger window?

Context windows have grown enormously, and for many tasks sending the whole conversation is the right answer. But a bigger window doesn't remove the need for memory:

  • Cost and speed. You pay for every input token on every call, and long inputs take longer to process. Resending a 200,000-token history on each turn gets expensive fast.
  • Attention isn't perfect. Models are often worse at using facts buried in the middle of a very long context than facts near the start or end.
  • Sessions end. When the user comes back tomorrow, a new conversation starts with an empty window. Only an external store can carry facts across sessions.
  • Not everything belongs. Old tool results and finished sub-tasks are noise. Less, better-chosen context often gives better answers.

Common mistakes

Practice exercise

Work out how long a conversation can get before the oldest messages must be dropped or summarised.

Your solutionPython
window = 8_000          # tokens the model can see at once
system_prompt = 1_200   # sent with every request
per_turn = 350          # a user message plus the reply, on average

# After how many turns does the full history (system prompt + all turns) no longer fit?
# Print: Fits up to 0 turns
Knowledge check

A user told an assistant their name an hour ago, and the assistant still uses it. What is most likely happening?

Summary

  • Language models are stateless: each request must carry everything the model should know.
  • The context window is finite, so long conversations force the application to drop or compress something.
  • Agent memory comes in types: short-term (the context), semantic (facts), episodic (past events) and procedural (how to do things).
  • Bigger windows help, but cost, attention, new sessions and noise still make memory management necessary.

Next: short-term memory, deciding what goes into each request.

Finished reading? Tick it off to track your progress.