Persistent memory for
LangChain
LangChain's legacy BufferMemory and ConversationSummaryMemory APIs are no longer the current agent-memory path. db0 adds persistent, cross-session memory to today's createAgent API.
Install
npm i @db0-ai/langchain
What happened to LangChain memory
BufferMemory is legacy
Current LangChain agents use state with a checkpointer for thread memory and a store for cross-thread memory.
In-memory by default
The old default lived in the process. Durable storage required additional persistence infrastructure.
No semantic search
BufferMemory was a list of messages. No way to find relevant context from 50 conversations ago.
Two ways to use it
Memory tools for current LangChain agents. Direct persistent chat history for custom loops. Both use the same storage.
Agent tools (for ReAct agents)
Three DynamicStructuredTool instances. The model decides when to read and write memories.
import { createDb0 } from "@db0-ai/langchain"
import { ChatAnthropic } from "@langchain/anthropic"
import { createAgent } from "langchain"
const memory = await createDb0()
const agent = createAgent({
model: new ChatAnthropic({ model: "claude-sonnet-4-20250514" }),
tools: memory.tools,
})
await agent.invoke({
messages: [{ role: "user", content: "My name is Alex." }],
})Chat history (for custom loops)
Implements BaseListChatMessageHistory. Use it directly to store messages and extract facts without the deprecated RunnableWithMessageHistory wrapper.
import { createDb0 } from "@db0-ai/langchain"
const memory = await createDb0({ extractFacts: true })
const history = memory.chatHistory
await history.addUserMessage("I prefer TypeScript")
await history.addAIMessage("I'll remember that.")
const messages = await history.getMessages()Memory tools
| Tool | Description |
|---|---|
| db0_memory_write | Write a fact with content, scope, and optional tags. Supports superseding stale facts. |
| db0_memory_search | Search memories by query text with optional scope filtering. |
| db0_memory_list | List all memories, optionally filtered by scope. |
Migration from BufferMemory
Before
// Before — deprecated, in-process only
import { BufferMemory } from "langchain/memory"
import { ConversationChain } from "langchain/chains"
const memory = new BufferMemory()
const chain = new ConversationChain({ llm, memory })After
// After — persistent, survives restarts
import { createDb0 } from "@db0-ai/langchain"
import { createAgent } from "langchain"
const db0 = await createDb0()
const agent = createAgent({
model: llm,
tools: db0.tools,
})The difference: the default
BufferMemory setup was process-local. db0 memories persist in SQLite and survive across sessions, restarts, and deployments. See the ConversationBufferMemory migration guide for the current LangChain paths.What you get
Persistent storage
SQLite by default, PostgreSQL for production. Memories survive process restarts and deployments.
Scoped memory
4 scopes (task/session/user/agent). User preferences persist forever, session context expires naturally.
Automatic fact extraction
Chat history mode extracts facts from every message. Rules-based, zero LLM calls.
No platform lock-in
Local SQLite, your data. No cloud accounts, no API keys for memory operations.
Session management
newSession() creates a fresh conversation while preserving all accumulated memories.
Same db0 ecosystem
Same database works with CLI, inspector, AI SDK, OpenClaw, Claude Code, and Pi integrations.
Legacy memory is out.
Persistent knowledge is in.
$ npm i @db0-ai/langchain