Skip to content
aexhqPublic

About

A minimal and extensible agent server for building agent applications

Topics

Resources

Stars

29 stars

Watchers

0 watching

Forks

Repository files navigation

              ______ ______ _______ _______ _______
  ▄████▄     |   __ \   __ \   _   |_     _|    |  |
▄██▄██▄██▄   |   __ <      <       |_|   |_|       |
  ▀▀  ▀▀     |______/___|__|___|___|_______|__|____|

A minimal and extensible agent server for building agent applications

Quickstart · Docs · API reference · Examples · Roadmap

Brain is a single application you deploy as a service to run the agents behind your products. It's an open-source alternative to Claude Managed Agents and the OpenAI Agents SDK, running on your own infrastructure with the models you choose.

Brain gives you session-oriented primitives for building agents. Your application starts sessions, streams what the agent does, and connects tools from application code and services. Brain runs the agent loop and records each session's history, so you can replay a session or recover it after a failure.

  • Sessions: agent conversations that outlive connections and restarts.
  • Events: an ordered record of what the agent does, streamed live or replayed.
  • Harnesses: pluggable agent loops that drive the model and manage context.
  • Tools: capabilities implemented in your application, clients, or services.
  • Checkpoints: portable session state for recovering and moving sessions.
import { Pi, BrainServer, Model } from "brainserver";

const brain = new BrainServer();
await brain.start();
try {
  const session = await brain.create({ harness: Pi(), model: Model("openai/gpt-4.1-mini"), tools: [] });
  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.stop();
}

Save this as agent.mjs and follow the setup below.

Why Brain

  • Choose where tools run. Compose functions into your application, attach client functions, or connect services in any language.
  • Decide what the agent can do. The model sees exactly the tools you enable for each session.
  • Reconnect at any time. Sessions keep running when clients disconnect and survive server restarts, so any client can reconnect and continue from the last event it read.
  • Move sessions between servers. Checkpoints let another server recover a session after a failure or take it over in a planned handoff.
  • Isolate every customer. Keep each customer's sessions and tools separate, and give each client only the access it needs.
  • Run it yourself. Brain is open source and self-hosted, with structured logs and OpenTelemetry traces and metrics.

Get started

You need Node.js 24+ and an OpenAI API key for the example above.

  1. Install Brain. The package includes the server and harness runtimes:

    npm install brainserver
  2. Run your script. Set the provider key, then start the example:

    export OPENAI_API_KEY="your-provider-key"
    node agent.mjs

The Quickstart includes PowerShell setup. For a separately deployed server, use the container image and connect with @aexhq/brain or aex-brain.

Documentation

I want to… Read
Run my first session Quickstart
Understand how Brain runs a session Architecture
Stream events, interrupt turns, and resume sessions Session lifecycle
Write a tool service Distributed tools
Connect a remote MCP server MCP tools
Issue tokens and isolate customers Authentication
Back up sessions and move them between servers Persistence & recovery
Deploy and monitor Brain Operations & observability
Call Brain from my backend TypeScript SDK or Python SDK
Look up routes and config fields HTTP API and Host configuration
See what's coming next Roadmap

Build with a coding agent

Give your coding agent Brain's docs as plain text: llms-full.txt has every page in one file, and llms.txt lists the pages.

Contributing

Install the dependencies and run every local check before you open a pull request. The checks need Go 1.26+, Node.js 24+, and Python 3.11+.

node scripts/setup.mjs
node scripts/check.mjs

Development & verification covers what the checks run, how CI publishes releases, and how to preview the docs.

License

Brain is released under the MIT License.

Docs · Roadmap · Architecture · License · Issues

About

A minimal and extensible agent server for building agent applications

Topics

Resources

Stars

29 stars

Watchers

0 watching

Forks

Packages

Used by

Contributors

Languages