Getting started
Install
npm i @db0-ai/core @db0-ai/backends-sqlite
The core package provides the harness API. The SQLite backend stores everything locally — no network, no signup.
Create a harness
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,
})
Every operation goes through the harness. It scopes memory, state, and logs to this specific agent + session + user combination.
Write and search memories
// write a memory
await harness.memory().write({
content: "User prefers dark mode and TypeScript",
scope: "user",
embedding, // number[] from your embedding provider
tags: ["preference"],
})
// search memories
const results = await harness.memory().search({
embedding: queryVec,
scope: ["user", "agent"],
scoring: "hybrid",
limit: 10,
})
for (const r of results) {
console.log(r.content, r.score)
}
Checkpoint state
// save a checkpoint before a risky operation
const cp = await harness.state().checkpoint({
label: "before-api-call",
})
// ... do something risky ...
// roll back if it went wrong
await harness.state().restore(cp.id)
Log events
await harness.log().append({
event: "tool_call",
level: "info",
data: { tool: "web_search", query: "TypeScript best practices" },
})
Close
await harness.close()
Only the root harness closes the backend. Spawned sub-agents share the connection.
Using a framework?
If you're using the Vercel AI SDK or LangChain, you don't need to touch the core harness API. The integration packages handle setup, extraction, and context injection for you:
# Vercel AI SDK
npm i @db0-ai/ai-sdk
# LangChain
npm i @db0-ai/langchain
// Vercel AI SDK — one-line middleware
import { createDb0 } from "@db0-ai/ai-sdk"
const memory = await createDb0()
// pass memory.middleware to generateText()
// LangChain — drop-in tools
import { createDb0 } from "@db0-ai/langchain"
const memory = await createDb0()
// pass memory.tools to createReactAgent()
See Vercel AI SDK docs or LangChain docs for full setup.
Using a coding agent?
npx @db0-ai/openclaw init # OpenClaw
npx @db0-ai/claude-code init # Claude Code
npx @db0-ai/pi init # Pi
Each one-liner installs the plugin and configures it. No code changes needed.