Multi-turn chat
A support assistant needs to remember earlier turns while handling one customer conversation.
AI Agents · Const
Short-term memory gives an agent thread-scoped state for maintaining multi-turn conversation history. A checkpointer persists that state so the same thread can continue across invocations.
Short-term memory is thread-scoped agent state backed by a checkpointer. The checkpointer saves checkpoints so a conversation can continue across invocations, while each step reads the current state and updates it as execution proceeds.
builder.compile({ checkpointer });import { MemorySaver } from "@langchain/langgraph";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
const checkpointer = new MemorySaver();
const agent = createReactAgent({
llm,
tools: [],
checkpointSaver: checkpointer,
});
await agent.invoke(
{ messages: [{ role: "user", content: "My name is Bob" }] },
{ configurable: { thread_id: "conversation-1" } },
);
const result = await agent.invoke(
{ messages: [{ role: "user", content: "What is my name?" }] },
{ configurable: { thread_id: "conversation-1" } },
);
console.log(result.messages.at(-1)?.content);The checkpointer stores agent state for a thread. Reusing the same thread identifier on later invocations lets the agent access earlier conversation messages.
A support assistant needs to remember earlier turns while handling one customer conversation.
An agent must continue after a process restart or later request.
A long-running conversation needs controlled context growth.
Short-term memory is thread-level persistence that lets an agent track a multi-turn conversation. It is represented in the agent state and persisted through a checkpointer.
Follow-up: How would you prevent unbounded history growth? Use message trimming, deletion, summarization, checkpoint management, or another filtering strategy.
A checkpointer persists a thread's graph state as checkpoints. Supplying it when compiling or creating the agent enables conversation continuity across invocations.
Follow-up: How does this differ from long-term memory? Long-term memory uses a store for application-defined data outside graph state and can span threads.
The graph updates short-term memory when it is invoked or when a step completes, and reads the state at the beginning of each step. This allows later steps to use the accumulated conversation state.
Follow-up: What does a checkpoint represent? It is a persisted snapshot of the thread's graph state that can support resumption and related workflows.
Memorycheckpointerthreadstatepersistencetrim messagesdelete messagessummarize messages