Integrations/LangChain
@db0-ai/langchainnpmGitHub

Persistent memory for
LangChain

LangChain deprecated BufferMemory and ConversationSummaryMemory in late 2024. db0 is a drop-in replacement that persists to SQLite, works locally, and requires no platform dependencies.

Install
npm i @db0-ai/langchain

What happened to LangChain memory

BufferMemory is deprecated
LangChain's built-in memory classes were removed in favor of LangGraph's store. But LangGraph is a separate dependency.
In-process only
The old memory lived in a variable. Kill the process, lose everything. No persistence across restarts or deployments.
No semantic search
BufferMemory was a list of messages. No way to find relevant context from 50 conversations ago.

Two ways to use it

Agent tools for ReAct agents. Chat history for chains. Both backed by the same persistent 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 { createReactAgent } from "@langchain/langgraph/prebuilt"

const memory = await createDb0()

const agent = createReactAgent({
  llm: new ChatAnthropic({ model: "claude-sonnet-4-20250514" }),
  tools: memory.tools,
})

await agent.invoke({
  messages: [{ role: "user", content: "My name is Alex." }],
})
Chat history (for chains)

Implements BaseListChatMessageHistory. Stores messages in db0 and automatically extracts facts.

import { createDb0 } from "@db0-ai/langchain"
import { RunnableWithMessageHistory } from "@langchain/core/runnables"

const memory = await createDb0({ extractFacts: true })

const chain = new RunnableWithMessageHistory({
  runnable: yourChain,
  getMessageHistory: () => memory.chatHistory,
})

Memory tools

ToolDescription
db0_memory_writeWrite a fact with content, scope, and optional tags. Supports superseding stale facts.
db0_memory_searchSearch memories by query text with optional scope filtering.
db0_memory_listList 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 { createReactAgent } from "@langchain/langgraph/prebuilt"

const db0 = await createDb0()
const agent = createReactAgent({
  llm,
  tools: db0.tools,
})
The difference: BufferMemory only lasted for the current process. db0 memories persist in SQLite and survive across sessions, restarts, and deployments.

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.

BufferMemory is gone.
db0 is here.

$ npm i @db0-ai/langchain