Metadata-Version: 2.5
Name: benchbook
Version: 0.1.1
Summary: Shared ledger for Claude Code subagents and agent swarms: results go to Postgres instead of the lead's context, and a subagent's "done" is re-run before it counts.
Project-URL: Homepage, https://github.com/Jake-Network/benchbook
Project-URL: Documentation, https://github.com/Jake-Network/benchbook/tree/main/docs
Project-URL: Repository, https://github.com/Jake-Network/benchbook
Project-URL: Issues, https://github.com/Jake-Network/benchbook/issues
Project-URL: Changelog, https://github.com/Jake-Network/benchbook/blob/main/CHANGELOG.md
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: agent-memory,agent-swarm,agents,ai-agents,autoresearch,claude-code,codex,coding-agents,context-engineering,cursor,experiment-tracking,ledger,mcp,mcp-server,multi-agent,postgres,reproducibility,subagents,verification
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: alembic>=1.13
Requires-Dist: jinja2>=3.1
Requires-Dist: jsonschema>=4.22
Requires-Dist: mcp<3,>=2.3
Requires-Dist: pixeltable-pgserver>=0.7.2
Requires-Dist: psycopg-pool>=3.2
Requires-Dist: psycopg[binary]>=3.2
Requires-Dist: pydantic>=2.7
Requires-Dist: sqlalchemy>=2.0
Requires-Dist: starlette>=0.37
Requires-Dist: typer>=0.12
Requires-Dist: uvicorn>=0.30
Provides-Extra: examples
Requires-Dist: numpy>=1.26; extra == 'examples'
Requires-Dist: scipy>=1.12; extra == 'examples'
Description-Content-Type: text/markdown

# benchbook: a Postgres ledger for agent swarms

<!-- mcp-name: io.github.Jake-Network/benchbook -->

[![PyPI](https://img.shields.io/pypi/v/benchbook)](https://pypi.org/project/benchbook/)
[![Python](https://img.shields.io/pypi/pyversions/benchbook)](https://pypi.org/project/benchbook/)
[![License](https://img.shields.io/pypi/l/benchbook)](https://github.com/Jake-Network/benchbook/blob/main/LICENSE)

Subagents' results go to a database, not your lead agent's context, and their "done" is re-run before you trust it. On
SWE-bench Verified, 7 of 39 completions Claude Code reported as done failed the benchmark's tests on re-run (17.9%).

**benchbook re-runs the commit a subagent reports as done, in a clean worktree, before the report counts: on its own
with the Claude Code plugin, by `benchbook check verify` elsewhere. The experiments agents record and the check runs
and completions its hooks see go into one Postgres ledger, which the lead reads by SQL instead of from the subagents'
reports.**

A lead agent that fans work out to dozens of subagents gets every result back as natural-language text. With enough
workers those reports fill its context window, and what they said is lost at the next compaction or session.
benchbook keeps a ledger beside your repository: each worker records its experiments, check runs and completions the
moment they end and hands back only record ids, and the lead pulls what it needs from the ledger.

## Start

```bash
uv tool install --python 3.13 benchbook   # no Docker needed
benchbook install --no-cli --mcp   # Claude Code plugins: the hooks, plus the MCP server and the worker agent
```

Keep `--python 3.13`: without it uv may pick a free-threaded Python, and the install stops at `pixeltable-pgserver` with
"no wheels with a free-threading compatible ABI tag".

**A coding swarm.** `cd your-repo && benchbook init` proposes your test and lint commands as checks. Then work as
usual; the one convention is that an implementer ends its report with `DONE <sha>`.

**An experiment swarm.** `benchbook init --goal "Minimise validation loss" --metric val_loss --direction min`, then in
Claude Code `/benchbook-mcp:benchbook-lead Minimise val_loss of train.py; 3 rounds, 4 workers`, and `benchbook serve`
to watch at http://127.0.0.1:7466.

## What you get

- **Results in the ledger, ids in the context.** Workers record every run, failures included, and hand back a
  short summary with record ids. The lead reads a budgeted brief (best result, open work, what not to repeat) and
  queries details by SQL when it needs them.
- **Nothing lost.** Every evaluation a worker records, and every run of a declared check the hooks can read, is a
  row the moment it ends. A hook keeps a subagent's report even when the agent ignored the rules.
- **Nothing repeated.** The same experiment (config, code and seed) is refused, and a new seed counts as a
  replicate. A failed approach, in code implementation as in experiments, stays in the brief with its failure
  signature.
- **Across sessions and compaction** (experimental): a new or compacted session starts from the brief, not from
  what someone remembered.
- **Results are checked before they are built on.** An experiment result becomes the baseline only after other
  agents replicate it, and a worker's `DONE <sha>` is re-run on that commit in a clean worktree
  ([coding work](https://github.com/Jake-Network/benchbook/blob/main/docs/code.md)). These guarantees catch mistakes;
  on a shared database, per-agent tokens bind each write to its agent ([honest limits](https://github.com/Jake-Network/benchbook/blob/main/docs/concepts.md#honest-limits)).

Hooks never write to stderr and exit 0, except the completion gate, which exits 2 to keep a task open, and a worker's
report with over 600 characters besides the ids of records it wrote, which the SubagentStop hook sends back once for a
shorter rewrite; outside a benchbook project they do nothing.

## Commands for the lead

```bash
benchbook brief --here            # what the swarm has done on this branch, in a token budget
benchbook status                  # verified, undecided, reported only, mismatched; open findings; hook health
benchbook sql "SELECT ..."        # anything else, read-only
benchbook get c:7f3a91c2          # one record in at most 400 tokens
```

The [GitHub Action](https://github.com/Jake-Network/benchbook/blob/main/integrations/github-action/README.md) re-runs each piece a pull request completes. Codex,
Cursor, Gemini CLI, OpenCode and Pi get the brief and the check recording ([harnesses](https://github.com/Jake-Network/benchbook/blob/main/docs/harnesses.md)); a
Python SDK and the CLI work without any harness.

## Measured so far

- **The lead's peak context is lower, and it reads less than half the report tokens.** Circle packing at 8 and 16
  workers: peak lead context was 40.2k against 47.9k and 58.5k against 88.0k with plain subagents; 7.0k and 14.1k
  report tokens reached the lead, against 15.7k and 32.0k. Wider swarms are not yet measured like for like ("Fan-in
  after the lead-context changes" in the results).
- **About the same API cost as plain subagents.** Circle packing at 8 workers, 3 runs each: USD 1.11 against 1.16 per
  run (0.96x, the ranges overlap), with each evaluation checked, run and recorded in one Bash call. Neither side lost
  a result, and the share of duplicate evaluations was similar (32.6% against 31.3%). benchbook made about twice the
  model calls, mostly cache reads ("A against C after one-call recording" in the results).
- **Memory across restarts is not proven.** In four one-trial pilots a lead reading the brief answered fewer state
  questions than one keeping progress files. No pilot reached compaction.
- **Workers' "done" needs checking.** On SWE-bench Verified, 7 of 39 completions Claude Code reported done failed the
  benchmark's tests on re-run (17.9%, 95% CI 9.0% to 32.7%).

Methods, every pilot and the raw reports: [docs/results.md](https://github.com/Jake-Network/benchbook/blob/main/docs/results.md).

## What it fits

- **Coding work with a test suite**, split across many agents or sessions, each piece ending at a commit the checks
  can judge.
- **Experiments** that are all three: **A number per attempt** (every attempt yields a metric), **Re-runnable** (the
  same config runs again with only the seed changed) and **One space, explored together** (several workers search
  it at once). On many GPUs: [autoresearch](https://github.com/Jake-Network/benchbook/blob/main/docs/autoresearch.md).

## Works with

- **Your orchestrator.** Claude Code, Codex, Cursor or your own loop runs and routes the agents; benchbook records
  what they did.
- **Your tests and reviewers.** A re-run checks exactly what your declared checks cover, so better checks give
  stronger evidence.
- **Agent memory and tracing.** mem0 or Letta remember for one agent, and benchbook is the shared record of a swarm;
  records can carry a `trace_ref` to your observability tool.

## Docs

Each page and when to read it:

- [Concepts](https://github.com/Jake-Network/benchbook/blob/main/docs/concepts.md): how the ledger, briefs, claims and verification work, and the honest limits.
  Read this first.
- [Coding work](https://github.com/Jake-Network/benchbook/blob/main/docs/code.md): pieces, `DONE <sha>` re-runs and the false completion rate; start here for a
  coding swarm. In depth: [re-runs](https://github.com/Jake-Network/benchbook/blob/main/docs/code-verify.md), [the brief](https://github.com/Jake-Network/benchbook/blob/main/docs/code-brief.md),
  [pieces and path occupancy](https://github.com/Jake-Network/benchbook/blob/main/docs/code-pieces.md), [out-of-scope findings](https://github.com/Jake-Network/benchbook/blob/main/docs/code-findings.md),
  [CI evidence](https://github.com/Jake-Network/benchbook/blob/main/docs/code-ci.md).
- [Claude Code](https://github.com/Jake-Network/benchbook/blob/main/docs/claude-code.md): what each hook does in a session, installing the two plugins, the lead
  and worker loop.
- [Other harnesses](https://github.com/Jake-Network/benchbook/blob/main/docs/harnesses.md): what Codex, Cursor, Gemini CLI, OpenCode and Pi record, and how to
  install each.
- [GitHub Action](https://github.com/Jake-Network/benchbook/blob/main/integrations/github-action/README.md): re-run each piece a pull request completes and keep
  one summary comment on it.
- [autoresearch on many GPUs](https://github.com/Jake-Network/benchbook/blob/main/docs/autoresearch.md): many autoresearch agents on one shared ledger;
  [skills](https://github.com/Jake-Network/benchbook/blob/main/docs/autoresearch-skills.md) such as pi-autoresearch record into it too.
- [Circle-packing demo](https://github.com/Jake-Network/benchbook/blob/main/examples/circle-packing/README.md): an experiment swarm on a CPU, scripted in one
  minute or with Claude Code.
- [Results](https://github.com/Jake-Network/benchbook/blob/main/docs/results.md): every measurement with its method and raw reports.
- [Schema and SQL](https://github.com/Jake-Network/benchbook/blob/main/docs/schema.md): the tables and the read-only `v_*` views `benchbook sql` reads.
- [Python SDK](https://github.com/Jake-Network/benchbook/blob/main/docs/sdk.md): the `Ledger` API, for your own loop without a harness.
- [Several machines](https://github.com/Jake-Network/benchbook/blob/main/docs/multi-machine.md): one shared Postgres, the read-only role and per-agent tokens.
- [Releasing](https://github.com/Jake-Network/benchbook/blob/main/docs/releasing.md): how a `v*` tag becomes a PyPI release.

License: Apache-2.0.