Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

AI Agents · Const

Short-term Memory

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.

How it works

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.

Syntax

builder.compile({ checkpointer });

Key points

  • It maintains message history for the current session, making multi-turn conversations possible.
  • The conversation history is held in agent state rather than treated as unrelated external data.
  • A checkpointer saves state so an interrupted or later invocation can resume the same thread.
  • Execution reads current state at step boundaries and writes updates after invocation or completed steps.

Common mistakes

  • Long conversations can exceed the model's context window; trim, delete, or summarize messages before invoking the model.
  • Memory is isolated by thread, so use a consistent thread identifier for one conversation and a different one for another.

Example: Preserve conversation state across invocations

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.

When to use it

Multi-turn chat

A support assistant needs to remember earlier turns while handling one customer conversation.

Resumable workflows

An agent must continue after a process restart or later request.

Conversation history management

A long-running conversation needs controlled context growth.

Interview questions

QWhat is short-term memory in LangGraph?

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.

QHow is short-term memory persisted?

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.

QWhen is short-term memory read and updated?

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.

  • Memory
  • checkpointer
  • thread
  • state
  • persistence
  • trim messages
  • delete messages
  • summarize messages

Source: Memory. Checked 2026-10-15.