Skip to content
brain.GitHub
Developer docs OPEN SOURCE

Quickstart

Start the four Docker services and run a Pi session from TypeScript or the CLI.

Install Docker with Compose and Node.js 24+, then clone the repository:

git clone https://github.com/aexhq/brain.git
cd brain
node scripts/docker-env.mjs
docker compose -f deploy/docker/compose.yaml --profile images build
docker compose -f deploy/docker/compose.yaml up -d --wait
npm --prefix clients/sdks/typescript ci
npm --prefix clients/sdks/typescript run build

The setup script creates an ignored deploy/docker/.env file with random access and encryption keys. Brain listens on http://127.0.0.1:8080.

Run from the CLI

Set your provider key:

export OPENAI_API_KEY="your-provider-key"

Create a session with an ID chosen by your application, send a message and observe its events:

node --env-file=deploy/docker/.env clients/sdks/typescript/dist/cli.mjs create --id support/42 --model openai/gpt-4.1-mini --credential-env OPENAI_API_KEY
node --env-file=deploy/docker/.env clients/sdks/typescript/dist/cli.mjs send support/42 "Explain what makes a good agent tool."
node --env-file=deploy/docker/.env clients/sdks/typescript/dist/cli.mjs observe support/42

Ctrl+C stops observation. Use history support/42 to read retained events, or interrupt support/42 to stop a turn.

Run from TypeScript

Install @aexhq/brain in your application. Save this as agent.mjs and run it from the repository root with node --env-file=deploy/docker/.env agent.mjs:

import { Brain, Pi, Model, ApiKey } from '@aexhq/brain';

const brain = new Brain('http://127.0.0.1:8080', process.env.BRAIN_API_KEY);
try {
  const session = await brain.create({
    id: 'example/first-agent',
    harness: Pi(),
    model: Model('openai/gpt-4.1-mini', ApiKey(process.env.OPENAI_API_KEY)),
  });
  const input = await brain.send(session.id, { type: 'user.message', text: 'Say hello.' });
  for await (const event of brain.observe(session.id)) {
    if (event.type === 'assistant.message') console.log(event.data.text);
    if (event.input_id !== input.id) continue;
    if (event.type === 'session.error') throw new Error(event.data.message);
    if (event.type === 'session.status' && event.data.status === 'idle') break;
  }
} finally {
  await brain.dispose();
}

Attach input

Upload content, then reference its finalized ID in a message:

const attachment = await brain.uploadAttachment(session.id, 'notes.txt',
  new Blob(['Summarize these notes.'], { type: 'text/plain' }));
await brain.send(session.id, {
  type: 'user.message', text: 'Summarize the attachment.', attachments: [attachment.reference],
});

Next steps

Read Tools to install capabilities, Operations to configure persistence and telemetry, and Session lifecycle to interrupt and recover sessions. For starting a server inside Node.js, use the embedded application guide.

On this page