πŸ“¦ Moved to new directory. Last updated 12.2.2026. New location: claude-config/library/03-memory-state/deep-dives/fw-langgraph.html

Framework deep dive: LangGraph memory and the 27 solutions

Nov 19, 2026 Β· Michael Chang Β· Status: βœ… used in NurseOps Now (AI Assist (the app's chat helper for staff questions))

Show definitions in ( ) Β· hover a highlighted word for its meaning, click it for details Β· open with ?defs=1 to show definitions

Part of: Remembering the right things: state management in NurseOps Now Β· All 27 solutions Β· Other frameworks: AutoGen Β· CrewAI Β· LlamaIndex

Read in this order

  1. In plain words
  2. What it gives you for memory: from the current docs
  3. How to implement it (ServiceApps): code and output
  4. The 27 solutions with LangGraph: replace, complement or still yours
  5. Use both: what you still build
  6. In NurseOps Now, Trade-offs and Interview answer

In plain words

LangGraph (a tool for building AI workflows step by step) builds an AI app as a graph of steps (nodes) that share a state (everything the app must remember to continue correctly). Its memory story is two pieces: a checkpointer (the code that saves a checkpoint after each step) that saves each conversation (thread (one saved conversation, here one per user and case)) after every step, and a Store for long-term memories shared across conversations.

In plain terms: a notebook per conversation that saves itself after every line, plus a shared filing cabinet per user.

What it gives you for memory

From the official memory docs (LangGraph memory docs), checked on Nov 19, 2026:

How to implement it (ServiceApps)

Illustrative example: made-up data, no ServiceApps (a company platform for IT tickets, HR requests and help-center articles) instance. The code was run as shown; the model is a scripted stand-in, so no API key (a secret code that lets the app use a paid service) is needed.

The scenario. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist as a one-node graph: each conversation is a thread (one saved conversation, here one per user and case) (u42:INC0012345), the user's saved preference is in the Store, and only the last ~60 tokens (pieces of words the AI reads and writes; cost is per token) of chat are sent.

Steps.

  1. Compile the graph with a checkpointer (the code that saves a checkpoint after each step) (persistence) and a Store (long-term memory).
  2. Pass thread_id (conversation) and user_id in the config on every call.
  3. In the node, trim the messages by tokens (pieces of words the AI reads and writes; cost is per token) and read the user's memories from the Store.
  4. Delete a conversation with checkpointer.delete_thread().

The code (Python):

from langchain_core.messages import AIMessage, HumanMessage, trim_messages
from langchain_core.messages.utils import count_tokens_approximately
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.graph import START, MessagesState, StateGraph
from langgraph.store.base import BaseStore
from langgraph.store.memory import InMemoryStore

RULES = "You are ServiceApps Assist. Cite KB numbers."

def respond(state: MessagesState, config, *, store: BaseStore):
    user = config["configurable"]["user_id"]
    window = trim_messages(state["messages"], strategy="last", token_counter=count_tokens_approximately,
                           max_tokens=60, start_on="human")                 # short-term limit (7.1)
    prefs = [i.value["text"] for i in store.search((user, "memories"))]   # long-term memory (7.3)
    # a real node would call the model with RULES + prefs + window; here we report what it would send
    return {"messages": [AIMessage(f"(would send {len(window)} of {len(state['messages'])} messages; memories: {prefs})")]}

builder = StateGraph(MessagesState)
builder.add_node("respond", respond)
builder.add_edge(START, "respond")
store = InMemoryStore()
graph = builder.compile(checkpointer=InMemorySaver(), store=store)            # persistence + long-term store

store.put(("u42", "memories"), "pref-1", {"text": "prefers short bullet answers"})
cfg = {"configurable": {"thread_id": "u42:INC0012345", "user_id": "u42"}}
for q in ["My VPN shows error 809", "I'm on hotel Wi-Fi", "Still failing on my hotspot"]:
    out = graph.invoke({"messages": [HumanMessage(q)]}, cfg)
    print(f"{q!r:32} -> {out['messages'][-1].content}")

print("saved in thread:", len(graph.get_state(cfg).values["messages"]), "messages")
new = {"configurable": {"thread_id": "u42:general", "user_id": "u42"}}
print("new thread, same user:", graph.invoke({"messages": [HumanMessage("Hi")]}, new)["messages"][-1].content)
graph.checkpointer.delete_thread("u42:INC0012345")
print("after delete_thread:", graph.get_state(cfg).values.get("messages", []))

Output (from running the code above on Nov 19, 2026):

'My VPN shows error 809'         -> (would send 1 of 1 messages; memories: ['prefers short bullet answers'])
"I'm on hotel Wi-Fi"             -> (would send 3 of 3 messages; memories: ['prefers short bullet answers'])
'Still failing on my hotspot'    -> (would send 3 of 5 messages; memories: ['prefers short bullet answers'])
saved in thread: 6 messages
new thread, same user: (would send 1 of 1 messages; memories: ['prefers short bullet answers'])
after delete_thread: []

What to watch for.

The 27 solutions with LangGraph

πŸ” Replace = LangGraph (a tool for building AI workflows step by step) does it, you configure it (8 of 27). 🀝 Complement = use both: LangGraph (a tool for building AI workflows step by step) gives the mechanism, you add the rules (14). πŸ›  Still yours = build it yourself (5). † = not a memory feature, so from general knowledge rather than the memory docs; check the current docs.

Memory solutionWith LangGraphHowSolution
Three-Tier Memory: Short-Term (Context Window) (what the AI sees in the current call)🀝 ComplementMessages live (using the real Claude API (costs money), not a fake stand-in) in graph state (everything the app must remember to continue correctly) per thread (one saved conversation, here one per user and case); you trim them with trim_messagesDeep dive
Three-Tier Memory: Long-Term (Vector Store) (knowledge saved outside the model and searched when needed)πŸ” ReplaceStore (InMemoryStore, PostgresStore, …) with semantic search, per namespaceDeep dive
Three-Tier Memory: Episodic (Experience Log) (a record of what happened, step by step)🀝 Complementget_state_history replays a thread (one saved conversation, here one per user and case)'s checkpoints (saved copies of a conversation's state); the audit log (a permanent record of who did what and when) is yoursDeep dive
Agentic Outcome: Token Budgets (keeping each call within a planned size)🀝 Complementtrim_messages(max_tokens=...); the budget per zone is yoursDeep dive
Agentic Outcome: Hybrid Memory Systems (recent chat in the window plus long-term search)πŸ” ReplaceCheckpointer (the code that saves a checkpoint after each step) (short-term) + Store (long-term) in one graphDeep dive
Agentic Outcome: Strict State Serialization (saving state so work can pause, crash and resume without loss)πŸ” ReplaceCheckpointers (the code that saves a checkpoint after each step) save after every step; resume with invoke(None, config); durability modesDeep dive
Token Counting Middleware (code that counts tokens before every AI call and acts when the window gets too full)🀝 Complementtrim_messages with a token_counter; thresholds (the cut-off a score must stay above) and actions are yoursDeep dive
Dynamic Context Loading (giving the AI tools to fetch data only when it needs it, instead of putting everything in the prompt)πŸ” ReplaceTools (a function the AI can call, such as policy search) and tool (a function the AI can call, such as policy search) nodes are standard †Deep dive
System Prompt Pinning (keeping the rules in a protected place that is sent on every call and never trimmed)🀝 ComplementYou add the system prompt (the standing instructions that set the AI's rules and role) in your node, outside the trimmed history †Deep dive
Textual Summarization (rewriting old conversation into short, dense notes)🀝 ComplementLangMem SummarizationNode, or a custom summary keyDeep dive
Rolling Summaries (a short running summary that replaces old conversation turns)🀝 ComplementLangMem SummarizationNode(max_tokens_before_summary=...)Deep dive
Entity Extraction (pulling key facts (names, dates, IDs) out of text into a structured record)🀝 ComplementWrite extracted facts to the Store yourself, or use LangMemDeep dive
Vector Compression via RAG (storing text as vectors and pulling back only the parts that match)πŸ” ReplaceStore semantic search over saved memoriesDeep dive
The Engineering Trade-off: Fidelity vs. Capacity (the trade-off between keeping every detail and fitting more in the window)πŸ›  Still yoursNo hard/soft split; your exact facts belong in your own tablesDeep dive
The Hot/Cold State Architecture (splitting memory into what is in the current call (hot) and what is saved for later (cold))🀝 ComplementGraph state (everything the app must remember to continue correctly) is hot; checkpointers (the code that saves a checkpoint after each step) and the Store are cold; you decide what goes whereDeep dive
Structured Storage (SQL/Postgres) (a database with fixed tables for exact facts)πŸ›  Still yoursPostgresSaver stores checkpoints (saved copies of a conversation's state), not your business tablesDeep dive
Semantic Storage (Vector DB like Pinecone, Weaviate, or Chroma) (a vector database that finds text by meaning)πŸ” ReplaceStore with an index (embeddings (text turned into numbers so similar meanings sit close together)), many backendsDeep dive
Session Caching (Redis/Key-Value) (saving a conversation's state so it can pause and resume)πŸ” ReplaceCheckpointers (the code that saves a checkpoint after each step) incl. RedisSaver, keyed by thread_idDeep dive
The Rehydration Pattern (fetch saved state, keep only what's relevant, and put it back into the next call)🀝 ComplementReload by thread_id, memories by namespace; filtering and injection (hidden text that tries to give the AI new orders) are yoursDeep dive
Sanitization layer (code that masks personal details and secrets before anything is saved)πŸ›  Still yoursNo redaction; EncryptedSerializer encrypts checkpoints (saved copies of a conversation's state) at rest (a common way for programs to talk over the web using URLs)Deep dive
TTL (time-to-live) expiration (deleting saved data automatically after a set time)πŸ›  Still yoursNo built-in TTL in the docs; they suggest a cron job to delete old checkpoints (saved copies of a conversation's state)Deep dive
GDPR Right to Be Forgotten (a person's right to have their stored data deleted (from the EU's GDPR law))🀝 Complementcheckpointer.delete_thread(thread_id); Store items deleted by keyDeep dive
Engineering Fix: Recursive Goal Injection (repeating a short reminder of the rules before every AI answer)🀝 ComplementAdd the reminder in the node that builds the prompt (the instructions and text given to the AI) †Deep dive
Engineering Fix: Strict RAG and Citation Enforcement (answering only from retrieved sources, and flagging any answer without one)πŸ›  Still yoursRetrieval (finding the right section of the right policy) tools (a function the AI can call, such as policy search) yes; checking citations (pointers to the exact page and quote that support each claim) is yours †Deep dive
Input Filtering: Relevance Pruning (checking and trimming a question before the AI sees it)🀝 ComplementAdd a gate (an automatic check that blocks a change when scores drop) node before the model (as NurseOps Now does) †Deep dive
Process Control: Self-Correction Loop (checking the AI's answer and sending it back once to fix what failed)🀝 ComplementConditional edges loop back to the model; the check is yours †Deep dive
Output Guardrails: Schema Enforcement (requiring the AI's answer to match a fixed shape, checked in code)πŸ” ReplaceStructured output with a Pydantic (a library that checks data fits a fixed form) model †Deep dive

Use both: what you still build

Still yours with LangGraph (a tool for building AI workflows step by step):

Use both (complement), with your rules on top:

In NurseOps Now

Used today: AI Assist (the app's chat helper for staff questions) compiles its LangGraph (a tool for building AI workflows step by step) graph with SqliteSaver (backend/app/services/assist.py), one thread per user and case (each nurse's conversation about each case is saved separately), cleared with delete_thread(). Masking (pii.py), the 10-turn window and SQL facts are NurseOps' own. The next step would be the Store for long-term per-user memory.

Trade-offs

Interview answer

"In LangGraph (a tool for building AI workflows step by step) I use a checkpointer (the code that saves a checkpoint after each step) for per-thread memory, which saves after every step so a conversation survives restarts, and the Store for long-term memories by user namespace. I trim by tokens (pieces of words the AI reads and writes; cost is per token) in the node, mask before saving, and delete threads (one saved conversation, here one per user and case) on a schedule because there's no built-in TTL."

All data in this post is made up.

← Back to all 27 solutions

Key terms

Every highlighted word in this post links here. Click ↩ Back to return to the spot you came from.

agentic outcome: hybrid memory systems
Recent chat in the window plus long-term search.Used in: The 27 solutions with LangGraph↩ Back to where you were
agentic outcome: strict state serialization
Saving state so work can pause, crash and resume without loss.Used in: The 27 solutions with LangGraph↩ Back to where you were
agentic outcome: token budgets
Keeping each call within a planned size.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
AI Assist
The app's chat helper for staff questions.Used in: In NurseOps Now↩ Back to where you were
API key
A secret code that lets the app use a paid service.Used in: How to implement it (ServiceApps)↩ Back to where you were
audit log
A permanent record of who did what and when.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
checkpointer
The code that saves a checkpoint after each step.Used in: In plain words, What it gives you for memory, How to implement it (ServiceApps), The 27 solutions with LangGraph, Use both: what you still build, Interview answer↩ Back to where you were
checkpoints
Saved copies of a conversation's state.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
citations
Pointers to the exact page and quote that support each claim.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
dynamic context loading
Giving the AI tools to fetch data only when it needs it, instead of putting everything in the prompt.Used in: The 27 solutions with LangGraph↩ Back to where you were
embeddings
Text turned into numbers so similar meanings sit close together.Used in: The 27 solutions with LangGraph↩ Back to where you were
engineering fix: recursive goal injection
Repeating a short reminder of the rules before every AI answer.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
engineering fix: strict rag and citation enforcement
Answering only from retrieved sources, and flagging any answer without one.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
entity extraction
Pulling key facts (names, dates, IDs) out of text into a structured record.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
gate
An automatic check that blocks a change when scores drop.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
gdpr right to be forgotten
A person's right to have their stored data deleted (from the EU's GDPR law).Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
injection
Hidden text that tries to give the AI new orders.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
input filtering: relevance pruning
Checking and trimming a question before the AI sees it.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
LangGraph
A tool for building AI workflows step by step.Used in: In plain words, How to implement it (ServiceApps), The 27 solutions with LangGraph, Use both: what you still build, In NurseOps Now, Interview answer↩ Back to where you were
live
Using the real Claude API (costs money), not a fake stand-in.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
one thread per user and case
Each nurse's conversation about each case is saved separately.Used in: In NurseOps Now↩ Back to where you were
output guardrails: schema enforcement
Requiring the AI's answer to match a fixed shape, checked in code.Used in: The 27 solutions with LangGraph↩ Back to where you were
process control: self-correction loop
Checking the AI's answer and sending it back once to fix what failed.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
prompt
The instructions and text given to the AI.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
Pydantic
A library that checks data fits a fixed form.Used in: The 27 solutions with LangGraph↩ Back to where you were
REST
A common way for programs to talk over the web using URLs.Used in: What it gives you for memory, The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
retrieval
Finding the right section of the right policy.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
rolling summaries
A short running summary that replaces old conversation turns.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
sanitization layer
Code that masks personal details and secrets before anything is saved.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
semantic storage (vector db like pinecone, weaviate, or chroma)
A vector database that finds text by meaning.Used in: The 27 solutions with LangGraph↩ Back to where you were
ServiceApps
A company platform for IT tickets, HR requests and help-center articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
session caching (redis/key-value)
Saving a conversation's state so it can pause and resume.Used in: The 27 solutions with LangGraph↩ Back to where you were
state
Everything the app must remember to continue correctly.Used in: In plain words, What it gives you for memory, How to implement it (ServiceApps), The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
structured storage (sql/postgres)
A database with fixed tables for exact facts.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
system prompt
The standing instructions that set the AI's rules and role.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
system prompt pinning
Keeping the rules in a protected place that is sent on every call and never trimmed.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
textual summarization
Rewriting old conversation into short, dense notes.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
the engineering trade-off: fidelity vs. capacity
The trade-off between keeping every detail and fitting more in the window.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
the hot/cold state architecture
Splitting memory into what is in the current call (hot) and what is saved for later (cold).Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
the rehydration pattern
Fetch saved state, keep only what's relevant, and put it back into the next call.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
thread
One saved conversation, here one per user and case.Used in: In plain words, How to implement it (ServiceApps), The 27 solutions with LangGraph, Use both: what you still build, Interview answer↩ Back to where you were
three-tier memory: episodic (experience log)
A record of what happened, step by step.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
three-tier memory: long-term (vector store)
Knowledge saved outside the model and searched when needed.Used in: The 27 solutions with LangGraph↩ Back to where you were
three-tier memory: short-term (context window)
What the AI sees in the current call.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
threshold
The cut-off a score must stay above.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
token counting middleware
Code that counts tokens before every AI call and acts when the window gets too full.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
tokens
Pieces of words the AI reads and writes; cost is per token.Used in: What it gives you for memory, How to implement it (ServiceApps), Interview answer↩ Back to where you were
tool
A function the AI can call, such as policy search.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
ttl (time-to-live) expiration
Deleting saved data automatically after a set time.Used in: The 27 solutions with LangGraph, Use both: what you still build↩ Back to where you were
vector compression via rag
Storing text as vectors and pulling back only the parts that match.Used in: The 27 solutions with LangGraph↩ Back to where you were