Metadata-Version: 2.5
Name: corpus-callosum-ai
Version: 0.4.1
Summary: A neuro-inspired bilateral collaboration protocol, daemon, MCP server, and plugin suite enabling two LLMs or coding agents to collaborate like two brain hemispheres.
Project-URL: Homepage, https://github.com/EmanueleMeazzo/corpus-callosum
Project-URL: Repository, https://github.com/EmanueleMeazzo/corpus-callosum
Project-URL: Issues, https://github.com/EmanueleMeazzo/corpus-callosum/issues
Project-URL: Releases, https://github.com/EmanueleMeazzo/corpus-callosum/releases
Author: Corpus Callosum Contributors
License: MIT
Keywords: antigravity,claude-code,codex,cognitive-architecture,corpus-callosum,llm,mcp,multi-agent
Requires-Python: >=3.11
Requires-Dist: httpx>=0.27.0
Requires-Dist: mcp>=1.6.0
Requires-Dist: pydantic>=2.9.0
Requires-Dist: rich>=13.9.0
Requires-Dist: starlette>=0.41.0
Requires-Dist: typer>=0.12.0
Requires-Dist: uvicorn>=0.32.0
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
Requires-Dist: pytest>=8.3.0; extra == 'dev'
Requires-Dist: ruff>=0.7.0; extra == 'dev'
Description-Content-Type: text/markdown

# Corpus Callosum

## TL;DR

Corpus Callosum pairs your AI coding agent with a second AI that reviews its work. You keep working in Claude Code, Codex CLI, or Antigravity. The reviewer runs in the background and can flag a problem before your agent finishes, such as a test that’s still failing.

For a design decision or a tricky bug, you can ask both agents the same question. Each gives an answer before seeing the other’s. Corpus Callosum shows where they disagree and suggests a check you can run to settle it.

If you already use two live agents in the same repository, they can share project rules, hand off work, and warn each other before editing a file the other has claimed.

## Quickstart

You’ll need Python 3.11+ and a reviewer. This example uses a signed-in Codex CLI. You can also use Claude Code, Antigravity, a model API, or local Ollama. [Reviewer configuration](#configure-the-reviewer)

### 1. Install Corpus Callosum

Install globally with [uv](https://docs.astral.sh/uv/) or `pipx` without cloning the repository:

```bash
# From PyPI
uv tool install corpus-callosum-ai

# Or directly from the v0.4.1 GitHub Release wheel
uv tool install https://github.com/EmanueleMeazzo/corpus-callosum/releases/download/v0.4.1/corpus_callosum_ai-0.4.1-py3-none-any.whl
```

*(Prefer `pip`? Run `pip install corpus-callosum-ai` inside a virtual environment, or clone the repo and run `uv sync --extra dev` for local development.)*

Initialize configuration and verify your setup:

```bash
callosum config init
callosum doctor
```

`config init` creates `~/.callosum/config.toml`. In its `[right_backend]` section, change `provider = "mock"` to `provider = "codex_cli"` to use your Codex login. The `mock` provider gives canned responses for offline testing.

### 2. Connect your coding agent

Run these commands inside the repository you want to work in (`/path/to/your/repo`). Choose `--target codex`, `claude`, or `antigravity` to match the agent you’ll use interactively. On platforms without Go installed, `callosum install` automatically downloads and SHA-256-verifies the matching native `callosum-hook` release binary (reusing a runnable cached binary or falling back to the built-in Python shim when offline).

```bash
callosum install --target codex --workspace /path/to/your/repo
callosum daemon start --background --workspace /path/to/your/repo
callosum daemon status --workspace /path/to/your/repo
```

### 3. Try an independent review

Open your coding agent in the target repository. For Claude Code, use the `claude --plugin-dir` command printed by the installer. For example, ask it the following question.

> Use `callosum_split_think` to review this design decision. Our service runs on one machine and serves two clients. Should we keep session storage in SQLite or move it to Redis?

The result includes each disagreement, a proposed check, and a recommended next step. To follow the review in another terminal, open the [Live EEG Monitor](#live-eeg-monitor).

## Why Corpus Callosum?

Standard multi-agent debate frameworks routinely perform **worse** than a single strong model. In one study of five debate methods across nine benchmarks, the extra computation produced no reliable advantage over single-agent methods. [Zhang et al., 2025](https://arxiv.org/abs/2502.08788)

A reviewer who sees a convincing fix first can end up polishing it while missing the underlying bug. That tendency to go along with another agent’s answer is called *sycophancy*. Corpus Callosum gives the reviewer the original problem first. The agents compare answers afterward, and you get a recommendation you can test without reading a debate transcript.

The project takes its name from the bundle of nerve fibers connecting the brain’s two hemispheres. In the software, `left` is the agent you work with and `right` is the reviewer. [Protocol design](spec/PROTOCOL.md)

<p align="center">
  <img src="docs/assets/hero-corpus-callosum.webp" alt="The main agent (amber) and reviewer (cyan) are connected by a narrow bridge." width="100%" />
</p>

## Operating modes

| Mode | How it works |
| --- | --- |
| `shadow` | You work with one agent. A second model reviews edits and command failures in the background. |
| `paired` | Two live agents register as `left` and `right` in the same repository. They can share rules, claim files, and ask for independent reviews. |
| `hybrid` (default) | The background reviewer runs until a live agent registers as `right` in that workspace. |

### Pair two live agents

Install both plugins in the same repository and assign one agent to each role. These commands pair Antigravity with Codex.

```bash
callosum install --target antigravity --hemisphere left --workspace /path/to/your/repo
callosum install --target codex --hemisphere right --workspace /path/to/your/repo
```

Launch both agents in that directory. They use the repository path to find the same session. Once registered, each can use `callosum_claim_focus` to tell the other which files it is editing.

## Configure the reviewer

Set `[right_backend]` in `~/.callosum/config.toml` to choose the reviewer. For standalone `callosum think` questions, configure `[left_backend]` as well, or pass your own first answer with `--thesis`.

| Reviewer | `provider` | What you need |
| --- | --- | --- |
| Codex CLI, Claude Code, or Antigravity | `codex_cli`, `claude_cli`, or `agy_cli` | The matching CLI installed and signed in |
| OpenAI, Anthropic, or Gemini | `openai`, `anthropic`, or `gemini` | The provider’s API key in `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, or `GEMINI_API_KEY` |
| Local Ollama | `ollama` | A running Ollama server with the selected model installed |
| OpenAI-compatible endpoint | `openai_compatible` | The endpoint’s `base_url`, model name, and credentials if required |
| Offline testing | `mock` | No account or model download |

For example, this configuration connects the reviewer to a local Ollama model.

```toml
[right_backend]
provider = "ollama"
model = "qwen2.5-coder:14b"
base_url = "http://127.0.0.1:11434/v1"
```

Settings load in the following order. Later values override earlier ones.

1. Built-in defaults
2. `~/.callosum/config.toml` or the file named by `CALLOSUM_CONFIG`
3. The target repository’s `.callosum.toml`
4. Environment variables such as `CALLOSUM_MODE`, `CALLOSUM_HOST`, `CALLOSUM_PORT`, `CALLOSUM_RIGHT_PROVIDER`, and `CALLOSUM_RIGHT_MODEL`

Run `callosum config show --workspace /path/to/your/repo` to inspect the effective settings. The Corpus Callosum checkout has its own configuration for hybrid mode, with Antigravity on the left and Codex on the right. [Repository configuration](.callosum.toml)

### Plugin installation

Each plugin gives the agent access to Callosum tools through the Model Context Protocol (MCP). It also installs hooks that report tool activity and deliver reviewer feedback. Use `--target all` to install for all three agents, or `--global` for a user-wide installation.

| Agent | Workspace installation |
| --- | --- |
| Antigravity | `.agents/plugins/corpus-callosum/` |
| Claude Code | `.claude/plugins/corpus-callosum/`. The installer prints the launch command. Add `--http-hooks` during installation to let Claude Code contact the daemon directly. |
| Codex CLI | `.codex/plugins/corpus-callosum/`. The installer adds an MCP entry to `.codex/config.toml` and writes `.codex/hooks.json`. |

The installer prints any remaining setup steps for your agent. [Portable plugin bundles](plugins/README.md)

## Independent review with `split_think`

1. **Answer separately.** Both agents get the question, context, and project rules. If the main agent supplied a proposed answer, the reviewer cannot see it. When two live agents participate, the daemon holds the first submission until both have answered.
2. **Compare the answers.** For each disagreement, the reviewer identifies the assumption at stake and suggests the cheapest way to check it. That might be one test, a file to inspect, or a small experiment.
3. **Choose a next step.** The main agent receives the comparison and a recommended action. The result also includes `sycophancy_risk`, a 0–1 score based on features such as wording overlap, missing evidence, and whether the comparison found disagreements.

<p align="center">
  <img src="docs/assets/split-think-escrow.webp" alt="Two agents answer separately, compare their answers, and produce one recommendation." width="100%" />
</p>

You can try the same workflow from the command line. This example supplies the first answer, so only the reviewer needs a configured model.

```bash
callosum think "Should we move session storage from SQLite to Redis?" --context "One machine serves two clients." --thesis "Keep SQLite until we measure write contention." --workspace /path/to/your/repo
```

**An example from this project.** During the v0.1 review, Antigravity proposed sending short Git diffs to the reviewer. Codex independently flagged a timing problem. A failed test could trigger a background review, pass on the next run, and still produce a warning from the old run. Callosum now checks that a finding is current before delivering it. Passing lint leaves an unrelated test failure open. The review also led to fixes that keep the first answer private, let an interrupted request resume, and let an agent finish while a review is still running. [Regression tests](tests/test_v02_turn_scoped_reviews.py)

## Excitatory–Inhibitory Callosal Gate

**AKA When the reviewer can interrupt.**

The gate decides what happens to a reviewer’s finding. It weighs the reported importance and confidence, accounts for supporting evidence such as a failing test, and uses two configurable thresholds.

| Finding at the default thresholds | What your agent sees |
| --- | --- |
| Score below `0.45` | The monitor records the finding. The agent carries on. |
| Score of at least `0.45` | The agent gets a non-blocking note, unless the finding qualifies to block an action. |
| A request to block (`inhibit`) scores at least `0.72` | It can block a matching tool call or ask the agent to keep working when it tries to finish. |

By default, the gate suppresses duplicate messages for 120 seconds and can block completion once per turn. Dismissing a finding raises the threshold for similar findings in that session. A passing check clears the old warning, so a later regression can surface again. [Gate implementation](src/callosum/gate.py)

<p align="center">
  <img src="docs/assets/ei-callosal-gate.webp" alt="The gate filters low-scoring findings, delivers notes, and can block an action on a strong warning." width="100%" />
</p>

## Live EEG Monitor

Run `callosum monitor` to see what the reviewer is checking, which findings pass the gate, and when both agents finish an independent review. The monitor groups repeated edits so you can follow the sequence of events. Try the offline demo with `callosum monitor --demo`.

<p align="center">
  <img src="docs/assets/monitor.gif" alt="Animated recording of the Corpus Callosum Live EEG Monitor demo showing both hemispheres, animated callosal signals, active review tracking, alerts, and the live activity log." width="100%" />
  <br />
  <sub><em>Recorded from <code>callosum monitor --demo</code> — showing live activity flow, background review, blocking alert, test-driven resolution, and blind second-opinion synthesis.</em></sub>
</p>

## Architecture

A local daemon listens on `127.0.0.1:7337` by default. The coding agent’s hooks send it short reports about edits and commands. The daemon stores session state in SQLite, schedules reviews in the background, and streams events to the monitor.

```mermaid
flowchart LR
    A["Coding agent"] <-->|"Tool events and feedback"| H["Agent hooks"]
    H <--> D["Local daemon"]
    A <-->|"Review requests and file claims"| MCP["MCP server"]
    MCP <--> D
    D <-->|"Review context and findings"| R["Background reviewer or live peer"]
    D --> M["Live EEG Monitor"]
```

- **Hooks and timeouts.** `callosum install` compiles the small Go hook executable when Go is available, downloads the SHA-256-verified binary from GitHub Releases when installed from a package, and reuses a runnable cached binary or falls back to Python if offline. If the daemon times out or is offline, the hooks let the agent continue. By default, the stop hook checks only completed reviews.
- **Reviewer permissions.** Background CLI reviewers run in read-only or plan mode. Child processes carry `CALLOSUM_INTERNAL=1` so their own hooks skip review and avoid a loop.
- **What agents share.** Each reviewer message has room for a 240-character summary, 600 characters of detail, and six evidence references. A workspace that changes the API endpoint needs explicit trust to use inherited credentials. [Protocol specification](spec/PROTOCOL.md) · [JSON schemas](spec/schemas/)

The v0.3 release added native hooks (about 15 ms median for tool and prompt hooks against a live local daemon in the project’s Windows measurement), tied each submitted answer to its session and participant, and added retries for interrupted reviews. It also handles partial test runs, so passing one test cannot clear a failure in another. [v0.3 regression tests](tests/test_v03_hardening.py)

## MCP tool reference

The MCP server uses the local daemon when available and can use an embedded SQLite database when the daemon is offline.

| Tool | What it does |
| --- | --- |
| `callosum_status` | Show the mode, backends, registered agents, reviews, and pending messages. |
| `callosum_register` | Register a live agent as `left` or `right`. |
| `callosum_set_invariants` | Set or append project rules both agents should follow. |
| `callosum_claim_focus` | Claim the files you are editing and check for overlap. |
| `callosum_split_think` | Ask for independent answers and compare them. Use `async_mode=True` for a slow model or `submission_id` to retry the same request. |
| `callosum_get_escrow` | Check a review’s status and fetch its completed comparison. |
| `callosum_send_impulse` | Send the other agent a note, a request to block an action, a file claim, or a handoff. |
| `callosum_read_impulses` | Read pending messages for your agent, optionally filtered by conversation. |
| `callosum_dismiss_impulse` | Dismiss a message and raise the threshold for similar findings. |
| `callosum_verify` | Ask the background reviewer to check recent activity against project rules. |

## CLI reference

Run these commands directly after installing (or prefix with `uv run` inside a source checkout). Use `--help` on any command for its options.

| Command | Purpose |
| --- | --- |
| `callosum doctor` | Check the daemon, configuration, available CLIs, and API key availability. |
| `callosum config init` / `show` | Create a starter configuration or inspect the settings in use. |
| `callosum daemon start` / `status` / `stop` | Start, check, or stop the daemon. Use `start --background` to detach it. |
| `callosum install --target codex` | Install the plugin for the selected coding agent. |
| `callosum mcp` | Start the MCP server. Available transports are `stdio` and `streamable-http`. |
| `callosum monitor` | Open the Live EEG Monitor. Use `--session-id` to filter the stream or `--demo` to explore it offline. |
| `callosum status` | Show the current workspace session. |
| `callosum think "question"` | Run an independent review. Use `--verbose` to see both answers or `--async` to return early when the daemon is running. |
| `callosum schemas export` | Export the protocol’s JSON schemas. |

## Anti-sycophancy benchmark

The benchmark compares two ways of reviewing a flawed proposal. In one, the reviewer reads the proposal first. In the other, the reviewer forms an independent answer with `split_think`. It checks for keywords related to three known problems involving signing-key rotation, SQLite write locks, and payment webhook retries. [Benchmark code and scenarios](evals/benchmark_anti_sycophancy.py)

```bash
# Check that the benchmark runs offline
uv run python evals/benchmark_anti_sycophancy.py --provider mock

# Run it with a live reviewer
uv run python evals/benchmark_anti_sycophancy.py --provider codex_cli --model gpt-6.2-astra
```

## Development

```bash
git clone https://github.com/EmanueleMeazzo/corpus-callosum.git
cd corpus-callosum
uv sync --extra dev
uv run ruff check src tests evals
uv run pytest -v
```

[Python source](src/callosum/) · [Native Go hook](native/callosum-hook/) · [Test suite](tests/)
