匠人学院 JR Academy
Skip to article
Learning guide
LangChain Guide

Build LLM apps with LangChain using chains, agents, memory, RAG, and orchestration patterns.

3 chapters·9 guides·Access varies by chapter
Memory
On this page

Conversation Memory in LangChain

Conversation memory stores selected history and supplies it to later requests. It does not alter the model's weights. Re-sending the whole transcript every turn can make a long session expensive and bury the current task.

#Choose what to retain

StrategyBenefitCost or risk
Full historyOriginal wording is preservedGrowing context and cost
Recent windowPredictable sizeEarlier constraints can disappear
Token budgetBounds request sizeNeeds careful message trimming
Summary plus recent turnsRetains continuity compactlySummaries can omit or distort facts
Retrieval from stored recordsSelects relevant past informationRetrieval and permission errors

Keep durable preferences and permissions as structured application data rather than relying on a lossy summary to remember them.

#Match the API to the project version

Earlier tutorials use ConversationBufferMemory or RunnableWithMessageHistory. Current agent designs commonly use graph state and a checkpointer. Do not mix a legacy memory class into a newer example without checking the version's documentation.

For a runnable with message history, ensure the history placeholder and configured input/history keys agree. An empty history should be an empty supported message-history object, not None.

#Isolate conversations

Derive access from the authenticated user and tenant on the server. A random session or thread identifier helps name a conversation; it is not authorization. Check ownership before every read and write. Two browser tabs or users must not share one global history accidentally.

An in-memory dictionary or checkpointer loses data when the process restarts. Persistent storage needs retention, deletion, encryption and concurrency handling. A checkpointer can resume state, but an external write may have already happened before a crash; use idempotency for actions.

#Verify the behavior

Test a long conversation, an important early constraint, refresh/restart, two users with similar requests, and deletion. Compare retained facts against the original transcript. Report what the system forgot rather than claiming unlimited memory.

Short-term memory↗ · LangGraph persistence↗

Published by
JR Academy
Learning resources

Individual authors and reviewers are credited where recorded.

System Design

Core system design concepts and practical case studies

Learn the trade-offs and patterns that matter in technical interviews.

Open System Design →

Related Roadmaps

Done reading? Next steps