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

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
@db0-ai/openclaw OpenClaw ContextEngine plugin
@db0-ai/claude-code Claude Code MCP server
@db0-ai/cli CLI for listing, searching, exporting memories
@db0-ai/inspector Web UI for memory/state/log inspection

Next