Reference · SDK

BrainBox SDK reference: ingest, recall, update and serve in TypeScript

For developers embedding the Brain in their own code or agent.

Updated

The BrainBox SDK (@brainbox-labs/sdk, 0.26.1) gives TypeScript code one handle with ingest, recall and update verbs that map to the hosted MCP tools, a sync for folders of docs, project listing, and a builder for a local MCP server. Recall and update can be passed straight to an agent framework as tools.

  • One handle: new BrainBox({ apiKey, org, project }).
  • recall and update map 1:1 to the hosted MCP tools; asTools() returns them in MCP format.
  • Errors are thrown as BrainDispatchError with status, code and retryable.

The handle

Everything starts from a BrainBox handle. apiUrl defaults to the hosted service.

import { BrainBox } from '@brainbox-labs/sdk';

const brain = new BrainBox({
  apiKey: process.env.BRAINBOX_API_KEY!,
  org: 'my-org',
  project: 'my-project',
});

Ingest, recall, update

brain.ingest blocks until each stage is published. recall_wiki hits carry the matching passage. create_learning files a correction.

await brain.ingest({
  postgres: { connectionString: process.env.DATABASE_URL! },
  docs: ['./docs/**/*.md'],
});

const hits = await brain.recall.recall_wiki({ q: 'returns policy' });

await brain.update.create_learning({
  rule: 'Returns over 30 days are written off, not refunded.',
});

Use the verbs as agent tools

asTools() returns tool objects you can pass to an agent framework, each with an input schema and an execute method.

const tools = [...brain.recall.asTools(), ...brain.update.asTools()];

No API key? Use the CLI

For a script that does not need a TypeScript handle, brainbox tool runs the same verbs with your brainbox login, so there is no key to create or store. See the CLI reference.

npx -y @brainbox-labs/cli@latest tool recall_wiki --project support-brain --args '{"q":"refund policy"}'

Sync a folder

brain.sync keeps a folder in step with the Brain by stable key: it uploads only new and changed docs and reports docs deleted locally as pendingDeletes. Nothing is archived unless you apply it with brain.prune. Preview first with dryRun.

const plan = await brain.sync({ dir: './docs/kb', dryRun: true });

const result = await brain.sync({ dir: './docs/kb' });
if (result.pendingDeletes.length) {
  await brain.prune(result.pendingDeletes.map((d) => d.sourceKey));
}
SDK namespaces
NamespaceUse
brain.ingestIngest a database schema, SQL files, docs and text; blocks until published
brain.recallRead the Brain: get_index, recall_domain, recall_wiki, recall_traces, get_wiki_page, list_learnings and more
brain.updateWrite: create_learning, process_event, create_skill, save_wiki_page, report_context_gap and more
brain.sync, brain.pruneKeep a folder of docs in step by stable key; archive reviewed deletes
brain.projectsList the organization's projects and create one
brain.serveBuild and start a local MCP server for your approved tools

FAQ

How do I install it?
npm install @brainbox-labs/sdk.
Can I use the Brain from a script without an API key?
Yes: brainbox tool in the CLI calls any Brain tool with your brainbox login and prints JSON. In code, the SDK takes an API key.
Which keys work?
An API key (bb_...) for an organization and project.
How do I give the verbs to my agent?
brain.recall.asTools() and brain.update.asTools() return tool objects with an MCP-format input schema and a bound execute method.
Which databases can brain.ingest read?
Postgres, Trino and Athena, plus SQL files, docs and inline text. Trino and Athena need optional dependencies.

Give your agents a brain.

Sign in and ask your first question.

Book a Demo