When to reach for it
- User context must be maintained across multiple turns.
- The agent needs to learn from past cases.
- Multi-step tasks require tracking intermediate states.
Short-term, long-term, retrieved.
Relevant conversation history, completed task episodes, and structured long-term knowledge are stored and retrieved to give agents persistent context across turns and runs.
In practiceA travel-planning assistant pulls the user's long-term seating preferences and the prior session's unfinished itinerary from memory, so it resumes mid-task without the user restating either.
The run writes facts now and recalls them on a later turn.
| Store | What it supplies | Lives for |
|---|---|---|
| Conversational memory | The last turns of this chat: the trip is to Lisbon, in May | This session |
| Episodic memory | The last trip: Hotel Avenida, three nights, the card needed a second attempt | Across sessions, for this user |
| Semantic memory | Stable facts about the user: quiet room, no early check-out, loyalty number | Across sessions, for this user |
| Working memory | The plan the agent builds from these: Hotel Avenida, five nights, price still to confirm | This run |
| RAG, not memory | The hotel's cancellation policy | Until the hotel changes it; the same for every user |
When to reach for it
When it backfires
User A's private context leaks into User B's conversation because the retrieval layer doesn't filter by session ID.
Countermeasure
Tag every memory entry with a session or user dimension. Enforce dimension-scoped retrieval at the store layer.
The retriever fetches 20 relevant memories and dumps them into the prompt, crowding out the current turn's context.
Countermeasure
Cap retrieved chunks and rank by recency + relevance. Summarize old memories rather than inlining them verbatim.
Next pattern
Search patterns, frameworks, and pages.