npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@db0-ai/langchain

v0.3.0

Published

Persistent memory for LangChain.js agents. Replaces deprecated ConversationBufferMemory and RunnableWithMessageHistory. Framework-agnostic storage that survives LangChain upgrades.

Readme

@db0-ai/langchain

The Problem

LangChain.js deprecated all memory classes (BufferMemory, ConversationSummaryMemory, etc.) in v0.3.1. The recommended replacement — LangGraph checkpointers and Store — has real issues:

  • 4-6 packages to assemble. Checkpointers, stores, and embedding providers are all separate packages with poorly documented interfaces. Getting them to work together is non-trivial.
  • Messages vanish silently. The recommended createAgent + checkpointer pattern has a bug where messages disappear after server restart with no error. Thread metadata persists but conversations are empty.
  • Store bugs block production. store.get() works locally but throws errors on LangGraph Platform. PostgresStore has an encoding bug where data is stored but unretrievable.
  • No memory extraction in JavaScript. LangMem (automatic fact extraction) is Python-only. JS developers must manually decide what to store and when.
  • Self-hosted vs. platform is unclear. Developers can't tell what requires LangGraph Platform (the paid service) vs. what they can run themselves.

@db0-ai/langchain replaces all of that with one package. Persistent memory that works locally — scoped, versioned, with automatic fact extraction. SQLite or Postgres, no platform dependency.

Quick Start

npm install @db0-ai/langchain @langchain/core
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],  // db0_memory_write, db0_memory_search, db0_memory_list
});

await agent.invoke({
  messages: [{ role: "user", content: "Remember that I prefer dark mode" }],
});

// New session — agent can search its memory
memory.newSession();
const result = await agent.invoke({
  messages: [{ role: "user", content: "What are my preferences?" }],
});

What You Get

  • Memory toolsdb0_memory_write, db0_memory_search, db0_memory_list as LangChain DynamicStructuredTools, ready for any agent
  • Chat message historyDb0ChatMessageHistory implements BaseListChatMessageHistory with automatic fact extraction on every message
  • One package — no checkpointer packages, no store packages, no embedding provider packages
  • Local-first — SQLite by default, Postgres for production. No cloud service, no platform lock-in
  • Automatic extraction — rules-based fact detection from conversations, zero LLM calls

Two Ways to Use It

1. Agent Tools

Give the agent explicit tools to manage memory. Best for agents that should decide what to remember.

const memory = await createDb0();

const agent = createReactAgent({
  llm: yourModel,
  tools: [...yourTools, ...memory.tools],
});

2. Chat Message History

Drop-in replacement for deprecated BufferMemory / ConversationSummaryMemory. Stores messages and extracts facts automatically.

import { Db0ChatMessageHistory } from "@db0-ai/langchain";

const history = new Db0ChatMessageHistory({ harness: memory.harness });

await history.addUserMessage("I always use TypeScript with strict mode");
await history.addAIMessage("Got it! I'll remember your TypeScript preference.");

// Facts extracted automatically — searchable across sessions
const messages = await history.getMessages();

Use Cases

ReAct agent that learns from past tasks

An agent that remembers solutions to problems it's solved before — across sessions, without you managing any storage.

const memory = await createDb0({ agentId: "code-reviewer" });

const agent = createReactAgent({
  llm: yourModel,
  tools: [...memory.tools, fileReadTool, shellTool],
});

// Session 1: agent fixes a CORS issue
await agent.invoke({
  messages: [{ role: "user", content: "Fix the CORS error in our API" }],
});
// Agent calls db0_memory_write to save the solution

// Session 2: similar issue in a different project
memory.newSession();
await agent.invoke({
  messages: [{ role: "user", content: "I'm getting CORS errors again" }],
});
// Agent calls db0_memory_search, finds the previous fix

Multi-user chatbot with per-user memory

Each user gets isolated memory. One SQLite file, scoped by userId.

async function handleMessage(userId: string, message: string) {
  const memory = await createDb0({ userId, agentId: "support-bot" });

  const agent = createReactAgent({
    llm: yourModel,
    tools: [...memory.tools],
  });

  const result = await agent.invoke({
    messages: [{ role: "user", content: message }],
  });

  memory.close();
  return result;
}

Migrating from deprecated BufferMemory

Before (deprecated):

import { BufferMemory } from "langchain/memory";  // ⚠️ deprecated in v0.3.1
import { ConversationChain } from "langchain/chains";

const memory = new BufferMemory();
const chain = new ConversationChain({ llm, memory });

After:

import { createDb0 } from "@db0-ai/langchain";

const memory = await createDb0();
// Use memory.chatHistory for message storage with automatic extraction
// Use memory.tools for agent-controlled memory
// Facts persist to SQLite — no more in-memory-only conversations

RAG pipeline with persistent knowledge

Ingest documents into db0's scoped memory, then search them with hybrid scoring.

const memory = await createDb0({ agentId: "knowledge-base" });
const { harness } = memory;

// Ingest documents
for (const doc of documents) {
  await harness.context().ingest(doc.content, {
    scope: "agent",
    tags: ["knowledge", doc.category],
  });
}

// Search with hybrid scoring (similarity + recency + popularity)
const ctx = await harness.context().pack("How does authentication work?", {
  tokenBudget: 3000,
});
// ctx.text → relevant knowledge, ready for the system prompt

Configuration

const memory = await createDb0({
  dbPath: "./my-app.sqlite",   // default: "./db0.sqlite"
  agentId: "my-agent",         // default: "langchain"
  userId: "user-123",          // default: "default"
  extractFacts: true,          // auto-extract from chat history (default: true)
  consolidateFn: async (memories) => {  // optional: LLM-assisted memory merging
    const res = await llm.invoke(`Merge these facts into one:\n${memories.map(m => m.content).join("\n")}`);
    return { content: res.content as string };
  },
});

PostgreSQL for Production

import { createPostgresBackend } from "@db0-ai/backends-postgres";

const backend = await createPostgresBackend(process.env.DATABASE_URL!);
const memory = await createDb0({ backend });

Session Management

// Start a new session (conversation resets, memories persist)
const { harness, chatHistory } = memory.newSession();

// Or with a specific session ID
const { harness, chatHistory } = memory.newSession("onboarding-v2");

Direct Harness Access

For advanced usage beyond what tools and chat history provide:

const { harness } = memory;

// Pack context for a custom prompt
const ctx = await harness.context().pack("user preferences", { tokenBudget: 1000 });

// Spawn sub-agents with shared memory
const child = harness.spawn({ agentId: "researcher", sessionId: "r1" });

Part of db0

This package is one entry point to the db0 SDK. The same memory database works with the core SDK, AI SDK integration, OpenClaw plugin, Claude Code MCP server, CLI, and inspector.

License

MIT