Introduction
db0 is a TypeScript SDK that gives AI agents structured memory, recoverable state, and token-budgeted context assembly. It runs local-first on SQLite with no API keys required, and scales to PostgreSQL when you need cross-device sync.
Why db0
Every team building agents ends up rebuilding the same infrastructure: a memory store, some way to recover from bad states, a system for stuffing relevant context into the token window. db0 packages all of that into a single harness API.
- Memory — scoped key-value store with vector search, fact superseding, and relationship edges
- State — checkpoint, branch, and restore execution state
- Context — ingest documents, pack memories into token budgets, preserve facts before compaction
- Log — structured, append-only event logging
- Sub-agents — spawn child harnesses with shared user memory and isolated task memory
How it works
Everything goes through a harness — a scoped handle to the storage layer:
import { db0 } from "@db0-ai/core"
import { createSqliteBackend } from "@db0-ai/backends-sqlite"
const backend = await createSqliteBackend({ dbPath: "./agent.db" })
const harness = db0.harness({
agentId: "my-agent",
sessionId: "session-1",
userId: "user-123",
backend,
})
The harness scopes all operations to a specific agent, session, and user. Memory visibility follows a 4-level hierarchy: task < session < user < agent.
Packages
Core
| Package | Description |
|---|---|
@db0-ai/core |
Harness API — memory, state, context, log, spawn |
@db0-ai/backends-sqlite |
SQLite backend (local-first, works offline) |
@db0-ai/backends-postgres |
PostgreSQL + pgvector backend |
Integrations
| Package | Description |
|---|---|
@db0-ai/ai-sdk |
Memory middleware for the Vercel AI SDK |
@db0-ai/langchain |
Memory tools and chat history for LangChain |
@db0-ai/openclaw |
ContextEngine plugin for OpenClaw |
@db0-ai/claude-code |
MCP server for Claude Code |
@db0-ai/pi |
Memory extension for Pi coding agent |
Tools
| Package | Description |
|---|---|
@db0-ai/cli |
CLI for listing, searching, exporting memories |
@db0-ai/inspector |
Web UI for memory/state/log inspection |
Next
- Getting started — install and write your first memory
- Vercel AI SDK — add memory to the AI SDK in one line
- LangChain — replace deprecated BufferMemory
- Tutorial — build a chat agent with persistent memory