From 18707ebdea1c84e92bc1ab7624725a97f90d8702 Mon Sep 17 00:00:00 2001 From: Mahmut CAVDAR <4072246+mcavdar@users.noreply.github.com> Date: Sat, 8 Nov 2025 10:47:19 +0100 Subject: [PATCH 1/2] Add checkpointer to agent creation --- src/oss/langchain/short-term-memory.mdx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/oss/langchain/short-term-memory.mdx b/src/oss/langchain/short-term-memory.mdx index fb771648f9..e87bb734c5 100644 --- a/src/oss/langchain/short-term-memory.mdx +++ b/src/oss/langchain/short-term-memory.mdx @@ -952,6 +952,7 @@ graph TD :::python ```python from langchain.messages import RemoveMessage +from langchain_core.runnables import RunnableConfig from langgraph.graph.message import REMOVE_ALL_MESSAGES from langgraph.checkpoint.memory import InMemorySaver from langchain.agents import create_agent, AgentState @@ -979,10 +980,13 @@ def trim_messages(state: AgentState, runtime: Runtime) -> dict[str, Any] | None: ] } +checkpointer = InMemorySaver() + agent = create_agent( model, tools=tools, - middleware=[trim_messages] + middleware=[trim_messages], + checkpointer=checkpointer ) config: RunnableConfig = {"configurable": {"thread_id": "1"}} From e60ad3be7a40ed4c96b35158987c1ef72a2e0717 Mon Sep 17 00:00:00 2001 From: Mahmut CAVDAR <4072246+mcavdar@users.noreply.github.com> Date: Sun, 16 Nov 2025 06:18:40 +0000 Subject: [PATCH 2/2] add checkpointer js as well --- src/oss/langchain/short-term-memory.mdx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/oss/langchain/short-term-memory.mdx b/src/oss/langchain/short-term-memory.mdx index e87bb734c5..f7c0eb93e0 100644 --- a/src/oss/langchain/short-term-memory.mdx +++ b/src/oss/langchain/short-term-memory.mdx @@ -980,13 +980,11 @@ def trim_messages(state: AgentState, runtime: Runtime) -> dict[str, Any] | None: ] } -checkpointer = InMemorySaver() - agent = create_agent( model, tools=tools, middleware=[trim_messages], - checkpointer=checkpointer + checkpointer=InMemorySaver() ) config: RunnableConfig = {"configurable": {"thread_id": "1"}} @@ -1009,6 +1007,7 @@ If you'd like me to call you a nickname or use a different name, just say the wo ```typescript import { RemoveMessage } from "@langchain/core/messages"; import { createAgent, createMiddleware, trimMessages, type AgentState } from "langchain"; +import { MemorySaver } from "@langchain/langgraph"; const trimMessageHistory = createMiddleware({ name: "TrimMessages", @@ -1024,10 +1023,12 @@ const trimMessageHistory = createMiddleware({ }, }); +const checkpointer = new MemorySaver(); const agent = createAgent({ model: "gpt-5-nano", tools: [], middleware: [trimMessageHistory], + checkpointer, }); ``` :::