# Commit0 library

> Rebuild simpy from its spec with a lead, a pool of four implementers, and an integrator, and compare it with a one-agent baseline at the same budget.

The shape here is a task board with a worker pool. The folders are `examples/benchmarks/02_commit0_library` (the team) and `examples/benchmarks/02_commit0_library/solo` (one agent).

## The benchmark

[Commit0](https://commit-0.github.io/) asks an agent to rebuild one of 54 real Python libraries from commit zero. It gets the specification, the source tree with every function stubbed (signature and docstring, no body), and the library's real unit-test suite. The score is the share of tests that pass. Libraries range from 38 tests to 40,000, and no published agent has fully reproduced one.

The library used here is `simpy`, discrete-event simulation: a core event loop, event types, resources (container, resource, store), real-time mode, and utilities. It has clean module boundaries, so modules can be owned.

## Why this shape

Rebuilding a library is parallel work with one shared oracle. Modules can be written independently, but the real test suite only tells the truth when everything is assembled. So one agent decomposes the stub tree and assigns each module, a pool of identical workers implements, and one integrator runs the whole suite on every build and routes failures back to the owner.

```text
lead ──tasks──> implementer[0..3] ──builds──> integrator
  │                     ^                               │
  │                     └───────── failures ────────────┘
  └── inputs: who owns what ────────────────────────────┘
```

| Agent | Model | Starts when | Lives |
|---|---|---|---|
| `lead` | Opus | swarm starts | one turn: maps modules, assigns them, finishes with the owner map |
| `implementer[*]` (4) | Sonnet | swarm starts | on the board: woken by assignments and by failures addressed to them |
| `integrator` | Sonnet | lead is done (`inputs`) | on the board: runs the real suite on every build, finishes at 95% |

`done_when = agent.integrator.output.pass_rate >= 0.95`.

## The team: main.cvy

```hcl title="main.cvy"
# Commit0: build a whole library from its specification until the test suite passes.
#
# Library: simpy (discrete-event simulation), one of the 54 Commit0 libraries.
# Commit0 gives a spec, a source tree of function stubs with docstrings and no
# bodies, and the library's real unit-test suite. The score is the share of
# tests that pass.
#
# Shape: a task board.
#
#   lead ──tasks──> implementer[0..3] ──builds──> integrator
#     │                     ^                               │
#     │                     └───────── failures ────────────┘
#     └── inputs: who owns what ────────────────────────────┘
#
# The lead decomposes the stub tree into modules and assigns each one by
# publishing to "tasks" with "to" set to one implementer. The implementers are
# an anonymous pool: one block, four instances, the same prompt. The integrator
# starts when the lead's assignment map exists, runs the real suite on every
# build, and routes failures back to the owner. The swarm ends when the suite
# passes.

swarm "commit0_simpy" {
  goal         = "Rebuild the simpy library from the Commit0 specification and stubs until at least 95 percent of its unit tests pass and lint is clean"
  done_when    = agent.integrator.output.pass_rate >= 0.95
  max_runtime  = "12h"
  max_cost_usd = 150
  overseer = {
    provider = provider.anthropic
    model    = "claude-sonnet-5"
  }
}

provider "anthropic" {
  source  = "claude_agent_sdk"
  api_key = "ANTHROPIC_API_KEY"
}

topic "tasks" { description = "Lead: one module assignment per message, addressed to the implementer that owns it: module, public names, the tests that cover it, what it depends on" }
topic "builds" { description = "Implementers: a module is ready to test. Module path, files touched, the test ids it should pass" }
topic "failures" { description = "Integrator: failing tests or lint for one module, addressed to its owner, with the test ids and the first assertion of each" }
topic "human" { description = "Spec ambiguities only a person can settle" }

# Runs once. Reads the spec and the stub tree, assigns modules, finishes with
# the owner map that the integrator needs to route failures.
agent "lead" {
  provider = provider.anthropic
  model    = "claude-opus-5"
  prompt   = file("prompts/lead.md")
  vars = {
    repo    = env("COMMIT0_REPO_DIR")
    library = "simpy"
    workers = "implementer[0], implementer[1], implementer[2], implementer[3]"
  }
  tools  = ["bash", "read_file"]
  writes = [topic.tasks, topic.human]
  output = {
    owners = map(string)  # module path -> implementer instance name
    order  = list(string) # module paths, leaves first
    notes  = string
  }
}

# One block, four identical workers. Each instance learns its own name through
# vars and acts only on messages addressed to it.
agent "implementer" {
  count    = 4
  provider = provider.anthropic
  model    = "claude-sonnet-5"
  prompt   = file("prompts/implementer.md")
  vars = {
    me      = "implementer[${count.index}]"
    repo    = env("COMMIT0_REPO_DIR")
    library = "simpy"
  }
  tools     = ["bash", "read_file", "write_file", "edit_file"]
  writes    = [topic.builds, topic.human]
  watches   = [topic.tasks, topic.failures]
  max_turns = 60
  can_spawn = true # may create a helper for an oversized module
}

# Starts when the lead is done (a graph edge), then cycles with the
# implementers through the board (not a graph edge). Its finish ends the swarm.
agent "integrator" {
  provider = provider.anthropic
  model    = "claude-sonnet-5"
  prompt   = file("prompts/integrator.md")
  vars = {
    repo    = env("COMMIT0_REPO_DIR")
    library = "simpy"
  }
  tools   = ["bash", "read_file"]
  inputs  = { assignments = agent.lead.output }
  writes  = [topic.failures, topic.human]
  watches = [topic.builds, topic.human]
  output = {
    passed     = number
    total      = number
    pass_rate  = number
    lint_clean = bool
  }
  max_turns = 80
}
```

## Key prompts

The lead assigns one module per message, addressed with `to`. The pool is anonymous; routing is a field on `publish`, not a runtime list in the DSL, because `count` is static.

```text title="prompts/lead.md (excerpt)"
3. Assign. For each module publish ONE message to "tasks" with "to" set to the
   owner. The owners are exactly: {{workers}}. Each message says: the module
   path, its public names, the test ids that cover it, what it depends on and
   who owns that, and the spec sections the implementer must read. One module
   per message so the owner can report progress per module.
4. Where the spec and the tests disagree, the tests win; say so in the message.
   Where only a person can settle it (a removed feature, a licence question),
   publish to "human" and move on.
```

The integrator keeps the owner map from its first input and uses it to route.

```text title="prompts/integrator.md (excerpt)"
EACH TURN
1. Run the whole suite, not just the module announced:
     cd {{repo}} && commit0 test {{repo}} --backend local --timeout 1800
   then lint: `commit0 lint {{repo}}`. Save the output under
   {{repo}}/.integrator/run-<n>.txt so you can diff runs.
2. Count: passed, total, pass_rate = passed / total. Call report_progress with
   those numbers and the run id. That number is what everyone watches.
3. For every module with failing tests, publish ONE message to "failures" with
   "to" set to owners[module]: the failing test ids, the first assertion line
   of each, and whether the failure looks like it belongs to a dependency
   owned by someone else (then address that owner instead and say why).
4. A module whose tests all pass gets no message. Silence means good.
```

## How a run unfolds

1. The controller creates the lead, four implementers, the integrator, and the overseer. The lead and the implementers have no `inputs`, so all five start. The implementers have nothing addressed to them yet and idle on the board; the integrator stays Pending until the lead finishes.
2. The lead reads the spec and the stub tree, groups the modules into four workloads of similar size, and publishes one message per module to `tasks`, each with `to` set to an owner such as `implementer[1]`. It finishes with `owners` (module to instance), `order` (leaves first), and `notes`.
3. Each assignment wakes its addressed implementer, which implements the bodies, runs that module's tests, and publishes to `builds`. An implementer that finds a module too large may call `create_agent` for a helper, because `can_spawn = true`. The child can only use the parent's tools, provider, and model, and stops when the parent stops.
4. The lead is Done, so the integrator starts with `assignments`. Each `builds` message wakes it. It runs the whole suite and lint, reports the pass rate, and publishes a message to `failures` addressed to the owner of each failing module.
5. A failure message wakes its owner, which fixes and publishes to `builds` again. Four implementers edit one checkout; ownership is per module, so they do not collide, and the integrator's full-suite run is what catches a signature change under someone else's module.
6. The integrator calls `finish` when `pass_rate >= 0.95` and lint is clean. That makes `done_when` true and the run ends.
7. A person can intervene at any point: `convoy say commit0_simpy human "skip the rt module" --to integrator`.

## The solo arm

`solo/` is the same job for one agent: same provider, model, tools, `max_runtime`, and `max_cost_usd`, with spawning off for the agent and the overseer.

| | Team | Solo |
|---|---|---|
| Provider, model, tools | Sonnet with bash, read, write, edit for the workers | the same |
| `max_runtime` | 12h | 12h |
| `max_cost_usd` | 150 | 150 |
| Overseer | Sonnet, spend counts | Sonnet, spend counts, `can_spawn = false` |
| Can grow | implementers have `can_spawn = true` | no agent can spawn |

The team's lead runs on Opus; that is part of what the team design buys with the same budget.

```hcl title="solo/main.cvy"
# Commit0, solo arm: the same job as ../main.cvy, done by one agent.
#
# This is the baseline for the MVP's acceptance test: does a declared team beat
# one agent at the same budget? Everything the team has, this agent has: the
# same provider, model, and tools as the team's implementers, the same
# max_runtime, and the same max_cost_usd. The overseer runs here too and its
# spend counts, as in the team arm. Neither the agent nor the overseer may
# create agents, so the solo arm stays one agent for the whole run.
#
# The score is not taken from this file. After the run, the library's real test
# suite is run on the checkout by a script outside convoy, for both arms.

swarm "commit0_simpy_solo" {
  goal         = "Rebuild the simpy library from the Commit0 specification and stubs until at least 95 percent of its unit tests pass and lint is clean"
  done_when    = agent.solo.output.pass_rate >= 0.95
  max_runtime  = "12h"
  max_cost_usd = 150
  overseer = {
    provider  = provider.anthropic
    model     = "claude-sonnet-5"
    can_spawn = false
  }
}

provider "anthropic" {
  source  = "claude_agent_sdk"
  api_key = "ANTHROPIC_API_KEY"
}

topic "human" { description = "Spec ambiguities only a person can settle" }

# One agent does the lead's, the implementers', and the integrator's work. It
# watches nothing, so it never waits: each time it ends a turn without calling
# finish it gets a continue turn, until it finishes or reaches max_turns. A
# person steers it with `convoy say commit0_simpy_solo human "..." --to solo`;
# addressed messages arrive at the start of its next turn.
agent "solo" {
  provider = provider.anthropic
  model    = "claude-sonnet-5"
  prompt   = file("prompts/solo.md")
  vars = {
    repo    = env("COMMIT0_REPO_DIR")
    library = "simpy"
  }
  tools     = ["bash", "read_file", "write_file", "edit_file"]
  writes    = [topic.human]
  watches   = []
  can_spawn = false
  output = {
    passed     = number
    total      = number
    pass_rate  = number
    lint_clean = bool
  }
  max_turns = 200
}
```

The solo agent watches nothing, so it never waits. Each time it ends a turn without calling `finish` it gets a continue turn, until it finishes or reaches `max_turns`. A person steers it with `--to solo`. This is the one swarm that gets the expected `TS051` warning from [`convoy validate`](/docs/cli/validate/), because its `human` topic has no watcher.

## The MVP acceptance test

The two folders are the MVP's acceptance test. The MVP is done when it can answer one question on one Commit0 library: does a declared team beat one agent at the same budget?

- Two swarm folders: the team and the solo arm. Both use the same model, tools, `max_runtime`, and `max_cost_usd`, and run on the same `convoyd`.
- Each is run 3 times, each on a fresh checkout so the arms never share files.
- After each run, a script outside Convoy runs the library's real test suite and records the pass rate. The swarm's own `done_when` decides when to stop; it is not trusted as the score.
- The report is one row per run: pass rate, dollars spent, wall-clock time, and end reason (`done`, `budget`, `max_runtime`), taken from `convoy status --json`.

Convoy's job is to run both arms identically and report spend honestly. Scoring stays outside it. The MVP is done regardless of which arm wins; the answer is the result.

```sh title="one solo run"
export COMMIT0_REPO_DIR=/srv/commit0/runs/solo-1/simpy
commit0 setup simpy --base-dir /srv/commit0/runs/solo-1
convoy validate
convoy run
convoy status commit0_simpy_solo --json   # spend, elapsed time, end reason
```

## DSL features shown

- The task-board shape: one agent publishes tasks, a pool watches for them. Assignment is decided at runtime by the lead; the pool is `toset(["a", "b", "c", "d"])` and routing is the `to` field of `publish`. See [`agent`](/docs/dsl/agent/).
- An anonymous worker pool: one block with `count = 4` and `vars = { me = "implementer[${count.index}]" }` so each knows its own name.
- A graph edge and a board loop on the same agent: the integrator starts from the lead's typed `output` and then cycles with the implementers through `builds` and `failures`. See [topics and the board](/docs/concepts/board/).
- Long-lived agents with explicit `max_turns`, next to a single-turn agent without one.
- `create_agent` from a prompt, gated by `can_spawn = true`. See [spawning agents](/docs/concepts/spawning/).
- A person in the loop through the `human` topic and [`convoy say`](/docs/cli/say/).

## Run the team

```sh
pip install commit0
export COMMIT0_REPO_DIR=/srv/commit0/repos/simpy
commit0 setup simpy --base-dir /srv/commit0/repos    # one repository is a valid split; "lite" and "all" also work
commit0 build

export ANTHROPIC_API_KEY=...   # in convoyd's environment: api_key names this variable
convoy validate
convoy run
convoy watch commit0_simpy
```

## Machine assumptions

- The integrator runs `commit0 test --backend local`. Commit0's default backend is Modal; change the prompt if you run there.
- The 95% bar is a choice for this sample. Commit0's own score is the raw pass share, and the integrator's output carries `passed` and `total`, so the official number is in the finish payload too.
- Four implementers edit one checkout on one machine.
