/pattern/memory-architecture/

04 · ProductionMemory ArchitectureConversational MemoryEpisodic MemoryWorking Memory / ScratchpadMemory Management

Memory Architecture.
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.

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.

When it backfires

  • Privacy regulations forbid storage.
  • Tasks are strictly stateless.
  • A static semantic knowledge base suffices.

The tradeoff

Improved context and adaptability are achieved against higher token costs, privacy risks, and context window exhaustion.

The effect

What it actually does.

The run writes facts now and recalls them on a later turn.

store turnmemoryrecall later
Pitfalls

Two ways this pattern will hurt you.

Memory bleeds across sessions

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.

Over-eager retrieval bloating context

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.

Framework support

Where Memory Architecture is native.

LangGraphState and CheckpointersNative
OpenAI Agents SDKsessions + stateNative
Microsoft Agent Frameworkthreads + memoryNative
AutoGen / AG2conversable memoryNative
CrewAIshort/long-term memoryNative

Search

Search patterns, frameworks, and pages.