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.
/pattern/memory-architecture/
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.
When to reach for it
When it backfires
The tradeoff
Improved context and adaptability are achieved against higher token costs, privacy risks, and context window exhaustion.
The run writes facts now and recalls them on a later turn.
User A's private context leaks into User B's conversation because the retrieval layer doesn't filter by session ID.
Fix · 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.
Fix · Cap retrieved chunks and rank by recency + relevance. Summarize old memories rather than inlining them verbatim.
Next pattern
Search patterns, frameworks, and pages.