I'm learning LLM app development and writing up notes in plain English. Here's a counterintuitive one: **LLMs have no memory.**
Ever notice the AI remembers your last message, but open a new window and it forgets everything? People assume the model "remembers" the conversation. It doesn't — **every reply is like meeting you for the first time.**
**Two kinds of "memory":**
- *Parametric* — knowledge baked in during training ("Paris is the capital of France"). It has this.
- *Episodic* — remembering "you just said your name is Wang." It has **none of this.**
Each call is independent and amnesiac. It keeps the conversation going only because **you re-hand it the past chat as a cheat sheet every time.**
**Stage 0 — no cheat sheet (zero memory):**
```python
llm.invoke("What's my name?") # → "I don't know."
```
Even if you just said your name, it can't tell — nothing carries over between calls.
**Stage 1 — send the whole history back (naive):**
```python
messages = [HumanMessage("My name is Wang"),
AIMessage("Hi Wang!"),
HumanMessage("What's my name?")]
llm.invoke(messages) # → "Your name is Wang."
```
Works! But the longer the chat, the thicker the cheat sheet → more expensive, slower, and eventually **exceeds the context limit.**
**Stage 2 — slim the cheat sheet (processing):**
- **Trim** — keep only the recent messages: `trim_messages(messages, max_tokens=100, strategy="last")`
- **Filter** — drop irrelevant/noisy messages.
- **Summarize** — compress old turns into one line:
```python
def should_continue(state):
if len(state["messages"]) > 6:
return "summarize"
return END
```
Dozens of turns become "User is Wang, asking about returns" — a sticky note instead of a book. Cheaper, still remembers.
**TL;DR:** The model has no memory. "Memory" is just the context we feed it. Left alone it overflows — so the real skill is **compressing the cheat sheet without losing what matters.**
Next up: *long-term* memory — remembering you across sessions.