Metadata-Version: 2.5
Name: benchbook
Version: 0.1.0
Summary: A Postgres ledger for agent swarms: subagents write results to the database instead of the lead's context, and the lead reads them back by SQL.
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: agents,autoresearch,claude-code,experiment-tracking,ledger,mcp,multi-agent,postgres,reproducibility,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

**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 --from git+https://github.com/Jake-Network/benchbook 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 config, code and seed is refused; a new seed counts as a replicate. A failed
  approach 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)).

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).

## What it is not

- Not an orchestrator: it does not run or route agents. It sits under Claude Code, Codex, Cursor or your own loop.
- Not a code reviewer or test writer: a re-run checks only what your declared checks cover.
- Not a duplicate blocker for code implementation: for code it remembers which approaches failed, not exact repeats.
- Not a single-agent memory (mem0, Letta) or an observability tool (records can carry a `trace_ref`).
- Not a defence against a hostile agent on a shared owner URL: the guarantees catch mistakes
  ([honest limits](https://github.com/Jake-Network/benchbook/blob/main/docs/concepts.md#honest-limits)).

## Docs

[Concepts](https://github.com/Jake-Network/benchbook/blob/main/docs/concepts.md) · [Coding work](https://github.com/Jake-Network/benchbook/blob/main/docs/code.md) · [Claude Code](https://github.com/Jake-Network/benchbook/blob/main/docs/claude-code.md) ·
[Other harnesses](https://github.com/Jake-Network/benchbook/blob/main/docs/harnesses.md) · [Results](https://github.com/Jake-Network/benchbook/blob/main/docs/results.md) · [Schema and SQL](https://github.com/Jake-Network/benchbook/blob/main/docs/schema.md) ·
[Several machines](https://github.com/Jake-Network/benchbook/blob/main/docs/multi-machine.md) · [Python SDK](https://github.com/Jake-Network/benchbook/blob/main/docs/sdk.md) · [autoresearch](https://github.com/Jake-Network/benchbook/blob/main/docs/autoresearch.md) ·
[Circle-packing demo](https://github.com/Jake-Network/benchbook/blob/main/examples/circle-packing/README.md) · [Releasing](https://github.com/Jake-Network/benchbook/blob/main/docs/releasing.md)

License: Apache-2.0.