Skip to content

Repository files navigation

brain-ai

A small runtime that emulates a mind as a society of agents. One meta-reasoning model plays Consciousness; a handful of specialized models play brain regions. Consciousness never perceives, speaks, or acts itself — it reads a continuous stream of perception plus the live output of every region, and decides where attention goes: which regions to spawn, kill, re-task, or focus.

The regions run concurrently and asynchronously, each streaming from the Anthropic Messages API. Their tokens land in per-region buffers as they arrive, so Consciousness can judge and steer a region mid-thought instead of waiting for a finished answer.

How it works

        stdin (perception: text + images)
                    │
                    ▼
        ┌───────────────────────┐        status board (live tails)
        │     Consciousness     │ ◄──────────────────────────────┐
        │   (claude-fable-5)    │                                │
        └───────────┬───────────┘                                │
                    │ tool calls                                 │
     spawn / kill / send / focus                                 │
                    ▼                                             │
        ┌──────────┬──────────┬──────────┐                       │
        │ region A │ region B │ region C │  ── async streams ────┘
        └──────────┴──────────┴──────────┘
          (claude-opus-4-8, one asyncio task each)
  • Each region is an asyncio task streaming from the Messages API. Its output accumulates in a buffer that Consciousness can read at any moment.
  • "Killing" a region cancels its task, which closes the HTTP stream and aborts generation server-side. Before the object is dropped, a carryover is kept: the tail of its output and the last few images it was fed.
  • Respawning with carry_context: true seeds the new instance with that carryover plus the kill reason, so it continues rather than cold-starting.
  • Consciousness is a tool-calling loop. Each tick it receives (1) new perception drained from stdin and (2) a status board — the live tail and state of every region — and emits spawn_part / kill_part / send_to_part / focus calls, which the orchestrator executes.
  • While regions are still working, Consciousness re-ticks periodically (every TICK_SECONDS) so it can supervise partial output even with no new input.

The four verbs Consciousness has

Tool Effect
spawn_part Bring a region online with a task (optionally inheriting a killed predecessor's state).
kill_part Cancel a region's in-flight generation; retain its tail + recent images for respawn.
send_to_part Route new stimulus to a running region without restarting it.
focus Declare where attention goes; non-focused regions are throttled (fewer tokens, lower effort).

Files

File Purpose
orchestrator.py The runtime: region tasks, streaming, kill/carryover, the Consciousness tick loop.
consciousness.yaml Consciousness's model, system prompt, and the four tool definitions.
scenario_bicameral.yaml 2 regions — left (sequential/verbal/analytic) vs. right (holistic/spatial/affective).
scenario_lobes.yaml 4 regions — frontal, parietal, temporal, occipital cortical lobes.
scenario_faculties.yaml 6 regions — vision, motor, speech, emotion, creativity, memory. The richest scenario for watching recruit/prune.

A scenario defines the available regions (parts), per-region defaults (model, effort, carryover budget, modalities), and points at a Consciousness config via consciousness_ref.

Install

pip install anthropic pyyaml
export ANTHROPIC_API_KEY=sk-ant-...

Run

python orchestrator.py scenario_faculties.yaml
# or scenario_bicameral.yaml / scenario_lobes.yaml
# (defaults to scenario_faculties.yaml if omitted)

Then type stimuli at the prompt:

> a loud crash comes from the next room
> img:/path/to/photo.png a person waving at the door   # send an image (+ optional caption)
> quit                                                  # exit

Perception is fed to Consciousness, which routes it to regions and prints their streamed output tagged by source:

  • [consciousness] — Consciousness's own text (rare; it mostly emits tool calls)
  • [orchestrator] — spawn/kill bookkeeping
  • [<region>] — a region's live output (e.g. [vision], [left], [frontal])

Models

  • Consciousness runs on claude-fable-5 (the deep meta-reasoner) with a server-side fallback to claude-opus-4-8 to rescue benign classifier refusals.
  • Regions run on claude-opus-4-8 at low effort — fast and cheap, since Consciousness is where the deliberation lives. Focused regions get more tokens.

Image-capable regions (marked modalities: [text, image]) can receive forwarded perception images; text-only regions cannot.

Tuning

Runtime knobs live at the top of orchestrator.py:

Constant Meaning
PART_MAX_TOKENS / FOCUS_MAX_TOKENS Token budget for unfocused vs. focused regions.
CONSCIOUSNESS_MAX_TOKENS Token budget per Consciousness tick.
STATUS_TAIL_CHARS How much of each region's output the status board shows.
MAX_TOOL_ROUNDS_PER_TICK Max tool-call rounds Consciousness may take in one tick.
TICK_SECONDS Re-tick cadence while regions are still generating.

Carryover budget (how much of a killed region survives) is per-scenario, under defaults.carryover (text_tail_chars, last_images).

brain-ai

A small runtime that emulates a mind as a society of agents. One meta-reasoning model plays Consciousness; a handful of specialized models play brain regions. Consciousness never perceives, speaks, or acts itself — it reads a continuous stream of perception plus the live output of every region, and decides where attention goes: which regions to spawn, kill, re-task, or focus.

The regions run concurrently and asynchronously, each streaming from the Anthropic Messages API. Their tokens land in per-region buffers as they arrive, so Consciousness can judge and steer a region mid-thought instead of waiting for a finished answer.

How it works

        stdin (perception: text + images)
                    │
                    ▼
        ┌───────────────────────┐        status board (live tails)
        │     Consciousness     │ ◄──────────────────────────────┐
        │   (claude-fable-5)    │                                │
        └───────────┬───────────┘                                │
                    │ tool calls                                 │
     spawn / kill / send / focus                                 │
                    ▼                                             │
        ┌──────────┬──────────┬──────────┐                       │
        │ region A │ region B │ region C │  ── async streams ────┘
        └──────────┴──────────┴──────────┘
          (claude-opus-4-8, one asyncio task each)
  • Each region is an asyncio task streaming from the Messages API. Its output accumulates in a buffer that Consciousness can read at any moment.
  • "Killing" a region cancels its task, which closes the HTTP stream and aborts generation server-side. Before the object is dropped, a carryover is kept: the tail of its output and the last few images it was fed.
  • Respawning with carry_context: true seeds the new instance with that carryover plus the kill reason, so it continues rather than cold-starting.
  • Consciousness is a tool-calling loop. Each tick it receives (1) new perception drained from stdin and (2) a status board — the live tail and state of every region — and emits spawn_part / kill_part / send_to_part / focus calls, which the orchestrator executes.
  • While regions are still working, Consciousness re-ticks periodically (every TICK_SECONDS) so it can supervise partial output even with no new input.

The four verbs Consciousness has

Tool Effect
spawn_part Bring a region online with a task (optionally inheriting a killed predecessor's state).
kill_part Cancel a region's in-flight generation; retain its tail + recent images for respawn.
send_to_part Route new stimulus to a running region without restarting it.
focus Declare where attention goes; non-focused regions are throttled (fewer tokens, lower effort).

Files

File Purpose
orchestrator.py The runtime: region tasks, streaming, kill/carryover, the Consciousness tick loop.
consciousness.yaml Consciousness's model, system prompt, and the four tool definitions.
scenario_bicameral.yaml 2 regions — left (sequential/verbal/analytic) vs. right (holistic/spatial/affective).
scenario_lobes.yaml 4 regions — frontal, parietal, temporal, occipital cortical lobes.
scenario_faculties.yaml 6 regions — vision, motor, speech, emotion, creativity, memory. The richest scenario for watching recruit/prune.

A scenario defines the available regions (parts), per-region defaults (model, effort, carryover budget, modalities), and points at a Consciousness config via consciousness_ref.

Install

pip install anthropic pyyaml
export ANTHROPIC_API_KEY=sk-ant-...

Run

python orchestrator.py scenario_faculties.yaml
# or scenario_bicameral.yaml / scenario_lobes.yaml
# (defaults to scenario_faculties.yaml if omitted)

Then type stimuli at the prompt:

> a loud crash comes from the next room
> img:/path/to/photo.png a person waving at the door   # send an image (+ optional caption)
> quit                                                  # exit

Perception is fed to Consciousness, which routes it to regions and prints their streamed output tagged by source:

  • [consciousness] — Consciousness's own text (rare; it mostly emits tool calls)
  • [orchestrator] — spawn/kill bookkeeping
  • [<region>] — a region's live output (e.g. [vision], [left], [frontal])

Models

  • Consciousness runs on claude-fable-5 (the deep meta-reasoner) with a server-side fallback to claude-opus-4-8 to rescue benign classifier refusals.
  • Regions run on claude-opus-4-8 at low effort — fast and cheap, since Consciousness is where the deliberation lives. Focused regions get more tokens.

Image-capable regions (marked modalities: [text, image]) can receive forwarded perception images; text-only regions cannot.

Tuning

Runtime knobs live at the top of orchestrator.py:

Constant Meaning
PART_MAX_TOKENS / FOCUS_MAX_TOKENS Token budget for unfocused vs. focused regions.
CONSCIOUSNESS_MAX_TOKENS Token budget per Consciousness tick.
STATUS_TAIL_CHARS How much of each region's output the status board shows.
MAX_TOOL_ROUNDS_PER_TICK Max tool-call rounds Consciousness may take in one tick.
TICK_SECONDS Re-tick cadence while regions are still generating.

Carryover budget (how much of a killed region survives) is per-scenario, under defaults.carryover (text_tail_chars, last_images).

Author's Thoughts

The current design uses a single "overseer" Consciousness backed by a large, capable model. That works — but I don't think it's the right way.

The right way, I suspect, is a fast and dumb overseer. Our own perception and reaction aren't driven by real-time deep analysis; most of the loop is cheap, approximate, and immediate. An overseer model should be the same: super fast, and allowed to be pretty stupid. Its only job is to read the general gist of a situation. Something scary moves into the camera — it doesn't need to be understood, it just needs to be noticed. The fast overseer kills the current task and escalates directly to a bigger, slower model.

That points at a two-tier architecture — fast thinking and slow thinking:

  • Fast tier: fast perception (e.g. vision), fast overseer, fast reaction. This handles the common case in near real time.
  • Slow tier: when something odd happens — a region stuck in a loop, an ambiguous or high-stakes situation the fast tier can't resolve — the fast overseer kills the current task and spins up a bigger model with the carried-over context, itself supervised by a bigger, slower overseer.

In practice this roughly doubles the number of models and agents: instead of 2, you run 4 — two fast, two slow. The fast pair keeps the organism reactive; the slow pair is recruited only when reactivity isn't enough. That escalation-on-surprise structure feels closer to how minds actually allocate effort than a single always-deep overseer does.

About

brain-ai emulates a mind as a society of AI agents. A Consciousness meta-reasoner (claude-fable-5) reads a live stream of perception plus every region's streaming output, then spawns, kills, re-tasks, or focuses specialized brain regions (opus-4-8) running concurrently. Killed regions carry over state, so respawns continue instead of cold-starting.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages