Quickstart
Run a Brain server and drive one session from TypeScript.
Run a server
docker run --rm -p 8080:8080 -v brain-data:/var/lib/brain ghcr.io/aexhq/brain:latestOr build it:
cargo build --release -p brain-server --bin brain -p brain-loophost --bin brain-loop-worker
BRAIN_DATA_DIR="$PWD/brain-data" \
BRAIN_LOOP_WORKER="$PWD/target/release/brain-loop-worker" \
./target/release/brain --listen 127.0.0.1:8080Brain listens on loopback and needs no token there. Set BRAIN_API_TOKEN to listen anywhere else —
it refuses to start on a non-loopback address without one.
Drive a session
npm install @aexhq/brain @aexhq/agentloop-piimport { Brain } from "@aexhq/brain";
import { pi } from "@aexhq/agentloop-pi";
const brain = new Brain({ baseUrl: "http://127.0.0.1:8080" });
const session = await brain.sessions.create({
model: {
provider: "openai",
name: "gpt-5-mini",
apiKey: process.env.OPENAI_API_KEY!,
},
agentloop: pi(),
system: "Answer briefly and directly.",
});
await session.send("Explain what a session runtime does, in one sentence.");
for await (const event of session.events()) {
console.log(event.sequence, event.type, event.data);
}
await session.end();
await session.delete();No tools means the model sees none. Add them once you have somewhere to run them — see
Tools and Environments.
Runnable versions
The examples/ directory in the repository has
four working scripts: a basic session, reading event history from a cursor, the full lifecycle, and
the same thing over raw HTTP with no SDK.