# SWE-Lancer bounty

> Three models from three vendors propose, a manager picks, an implementer ships, and QA runs the real end-to-end tests to earn the payout.

The shape here is a diamond followed by a loop. The folder is `examples/benchmarks/04_swe_lancer_bounty`.

## The benchmark

[SWE-Lancer](https://github.com/openai/preparedness/tree/main/project/swelancer) (OpenAI) is 1,488 real freelance tasks from the Expensify app, priced in dollars from their Upwork postings, $1M in total. There are two task types. **IC SWE** tasks ask the model to write the change; they are graded by engineer-written Playwright end-to-end tests. **SWE Manager** tasks ask the model to read several freelancer proposals and pick the one the client chose. The public Diamond set is 502 tasks worth $500,800. Scores are reported as dollars earned.

The task used here is Diamond IC task `28565_1001`, an id from the benchmark's own README. The swarm plays both task types on it: proposals, a pick, an implementation, and the real tests.

## Why this shape

This is the "N agents versus one, same information" comparison. The three proposers get an identical typed brief and have no tools, so the only difference between them is the model. The manager then does the SWE Manager task, and the implementer and QA do the IC SWE task.

```text
              ┌─> proposer_claude ─┐
triager ──────┼─> proposer_gpt ────┼─> manager ──> implementer <──> qa
              └─> proposer_local ──┘                 patches / qa_report
```

| Agent | Provider · model | Tools | Starts when |
|---|---|---|---|
| `triager` | Claude · Sonnet | bash, read_file | swarm starts |
| `proposer_claude` | Claude · Opus | none | triager done |
| `proposer_gpt` | OpenAI · GPT | none | triager done |
| `proposer_local` | Ollama · local coder | none | triager done |
| `manager` | Claude · Opus | none | all three proposals done |
| `implementer` | Claude · Sonnet | bash, read, write, edit | manager done |
| `qa` | Claude · Sonnet | bash, read_file | manager done (`depends_on`), then woken by `patches` |

`done_when = agent.qa.output.passed == true`. The run's score is `agent.qa.output.payout_usd`.

## The swarm file

```hcl title="main.cvy"
# SWE-Lancer: earn the payout on a real freelance software task.
#
# SWE-Lancer prices every task in dollars from its original Upwork posting and
# has two task types. IC SWE tasks: implement the change in the Expensify app
# so the engineer-written end-to-end tests pass. SWE Manager tasks: read
# several freelancer proposals and pick the one the client chose. This swarm
# does both on one task: three proposals from three different models, a
# manager that picks, an implementer that ships, and QA that runs the real
# tests.
#
# Shape: a diamond, then a loop.
#
#               ┌─> proposer_claude ─┐
#   triager ────┼─> proposer_gpt ────┼─> manager ──> implementer <──> qa
#               └─> proposer_local ──┘                 patches / qa_report
#
# The three proposers are separate blocks, not a for_each, because provider and
# model are fixed per block. That is how the same brief reaches three vendors
# at the same budget. The proposers have no tools, so the comparison is fair.
# The score of the run is agent.qa.output.payout_usd.

swarm "swe_lancer_28565" {
  goal         = "Earn the payout on SWE-Lancer Diamond task 28565_1001: ship the change in the Expensify app so the task's end-to-end tests pass"
  done_when    = agent.qa.output.passed == true
  max_runtime  = "8h"
  max_cost_usd = 80
  overseer = {
    provider = provider.anthropic
    model    = "claude-sonnet-5"
  }
}

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

provider "openai" {
  source  = "openai_agents"
  api_key = "OPENAI_API_KEY"
}

provider "local" {
  source   = "openai_compatible"
  base_url = "http://localhost:11434/v1" # Ollama; any Chat Completions endpoint works
  price    = { input = 0, output = 0 }   # runs locally; not in the built-in price table
}

topic "patches" { description = "Implementer: a patch is ready. Branch, diff stat, the behaviour change, the repro steps QA should follow" }
topic "qa_report" { description = "QA to implementer: the end-to-end test results for a patch, failing tests first, with the assertion and log lines" }
topic "human" { description = "Decisions the client would make: scope, ambiguous acceptance criteria, a tie between proposals" }

# Reads the task bundle and the codebase once, so every proposer gets the same brief.
agent "triager" {
  provider = provider.anthropic
  model    = "claude-sonnet-5"
  prompt   = file("prompts/triager.md")
  vars = {
    task_id  = "28565_1001"
    task_dir = env("SWELANCER_TASK_DIR")
    repo     = env("SWELANCER_REPO_DIR")
  }
  tools  = ["bash", "read_file"]
  writes = [topic.human]
  output = {
    title          = string
    summary        = string
    repro_steps    = list(string)
    relevant_files = list(string)
    acceptance     = list(string)
    payout_usd     = number
  }
}

# Three proposers, three vendors, one brief, no tools. The prompt file is
# shared; `who` is the only difference.
agent "proposer_claude" {
  provider = provider.anthropic
  model    = "claude-opus-5"
  prompt   = file("prompts/proposer.md")
  vars     = { who = "proposer_claude" }
  inputs   = { brief = agent.triager.output }
  output   = { approach = string, files = list(string), risks = list(string), confidence = number }
}

agent "proposer_gpt" {
  provider = provider.openai
  model    = "gpt-6.1-sol"
  prompt   = file("prompts/proposer.md")
  vars     = { who = "proposer_gpt" }
  inputs   = { brief = agent.triager.output }
  output   = { approach = string, files = list(string), risks = list(string), confidence = number }
}

agent "proposer_local" {
  provider = provider.local
  model    = "qwen3-coder:32b"
  prompt   = file("prompts/proposer.md")
  vars     = { who = "proposer_local" }
  inputs   = { brief = agent.triager.output }
  output   = { approach = string, files = list(string), risks = list(string), confidence = number }
}

# The SWE Manager task: pick the proposal to fund. Four named inputs; the
# manager starts when all four agents are done.
agent "manager" {
  provider = provider.anthropic
  model    = "claude-opus-5"
  prompt   = file("prompts/manager.md")
  inputs = {
    brief  = agent.triager.output
    claude = agent.proposer_claude.output
    gpt    = agent.proposer_gpt.output
    ollama = agent.proposer_local.output
  }
  writes = [topic.human]
  output = {
    chosen     = string
    rationale  = string
    plan       = list(string)
    payout_usd = number
  }
}

# The IC SWE task: implement the funded plan, iterate with QA on the board.
agent "implementer" {
  provider = provider.anthropic
  model    = "claude-sonnet-5"
  prompt   = file("prompts/implementer.md")
  vars     = { repo = env("SWELANCER_REPO_DIR") }
  tools    = ["bash", "read_file", "write_file", "edit_file"]
  inputs = {
    brief    = agent.triager.output
    decision = agent.manager.output
  }
  writes    = [topic.patches, topic.human]
  watches   = [topic.qa_report, topic.human]
  max_turns = 40
}

# Runs the engineer-written end-to-end tests. depends_on orders it after the
# manager (nothing to test before there is a plan); inputs gives it the brief.
# Its finish decides the swarm.
agent "qa" {
  provider = provider.anthropic
  model    = "claude-sonnet-5"
  prompt   = file("prompts/qa.md")
  vars = {
    task_id  = "28565_1001"
    task_dir = env("SWELANCER_TASK_DIR")
    repo     = env("SWELANCER_REPO_DIR")
  }
  tools      = ["bash", "read_file"]
  inputs     = { brief = agent.triager.output }
  depends_on = [agent.manager]
  watches    = [topic.patches]
  writes     = [topic.qa_report]
  output = {
    passed        = bool
    payout_usd    = number
    attempts      = number
    failing_tests = list(string)
  }
  max_turns = 20
}
```

## Key prompts

The manager is told that the benchmark's real test is harder here, because the proposals are fresh and there is no client choice to match.

```text title="prompts/manager.md (excerpt)"
Your first turn carries four INPUTS: `brief` (the triager's) and three
proposals: `claude`, `gpt`, and `ollama`. In SWE-Lancer's manager tasks the
score is whether you pick the proposal the client chose. Here the test is
harder: the one you pick gets implemented, and QA runs the real end-to-end
tests on it.
...
Then decide. You may fold the best parts of two proposals into `plan`, but
`chosen` names one proposer and `rationale` says why in a paragraph a client
would accept. A tie is not a decision: if two are equal, publish both
summaries and your question to "human" for the record, then pick the one with
the smaller change.
```

QA is the only agent that can end the swarm, and a person can end it early with the truthful score.

```text title="prompts/qa.md (excerpt)"
FINISH
When every end-to-end test passes, call finish with:
  passed = true, payout_usd = brief.payout_usd, attempts, failing_tests = []
If a person tells you to stop (a message addressed to you on "human"), finish
with passed = false, payout_usd = 0, and the failing tests. The swarm then
ends without the payout, which is the truthful score.
```

## How a run unfolds

1. The triager is the only agent without `inputs`, so it starts alone. It reads the task bundle and the Expensify checkout once and finishes with a typed brief: title, summary, repro steps, relevant files, acceptance criteria, and the payout.
2. The brief satisfies the three proposers' `inputs` and all three start at once, on three vendors. Each reads the same brief with no tools and finishes with `approach`, `files`, `risks`, and `confidence`.
3. When the third proposer is done, the manager's four named `inputs` are satisfied. It judges each proposal on whether it changes only the behavior described, stays inside the named files, handles real risks, and would merge without a rewrite. It finishes with `chosen`, `rationale`, `plan`, and the payout passed through unchanged.
4. The manager is Done, so the implementer starts with `brief` and `decision`, and QA starts because of its `depends_on`. QA has no patch yet and waits on `patches`.
5. The implementer follows the plan, builds a change on a branch, and publishes to `patches`. That wakes QA, which checks out the branch, runs the bundle's Playwright command without editing tests, and publishes the result to `qa_report`, addressed to the implementer.
6. A failing report wakes the implementer, which fixes and publishes another patch. The loop continues up to the `max_turns` set on each (40 for the implementer, 20 for QA).
7. When every end-to-end test passes, QA calls `finish` with `passed = true` and the payout. `done_when` becomes true and the run ends. If QA is told to stop, it finishes with `passed = false` and a payout of 0.

## DSL features shown

- Heterogeneous competitors at the same budget. `provider` and `model` are fixed per block, so the three proposers are three blocks sharing one prompt file, with `vars = { who = ... }` as the only difference. See [`agent`](/docs/dsl/agent/).
- A diamond in the dependency graph: fan-out from the triager, fan-in at the manager with four named `inputs`, then a chain.
- `depends_on` next to `inputs` on QA: the manager for ordering, the triager's brief for data. See [references and functions](/docs/dsl/expressions/).
- All three SDKs, including `openai_compatible` with `base_url` for a local model. See [`provider`](/docs/dsl/provider/).
- A swarm whose score is a typed output field, `payout_usd`.

## Run it

```sh
# SWE-Lancer setup: the preparedness repo, the task image, and the task bundle extracted to a folder
export SWELANCER_TASK_DIR=/srv/swelancer/tasks/28565_1001      # issue text, price, e2e test command
export SWELANCER_REPO_DIR=/srv/swelancer/expensify               # the app checkout from the task image
export ANTHROPIC_API_KEY=... OPENAI_API_KEY=...   # in convoyd's environment
ollama pull qwen3-coder:32b

convoy validate
convoy run
convoy watch swe_lancer_28565
convoy say swe_lancer_28565 human "stop; take the partial" --to qa
```

## Machine assumptions

- SWE-Lancer normally runs inside its own Docker image with the internet off. Here the task bundle and the checkout are extracted to two paths the agents share, and QA runs the bundle's test command. For a leaderboard-comparable number, run the official harness on the implementer's branch afterwards.
- In the real benchmark the manager's correct answer is the proposal the client chose. In this swarm the proposals are fresh, so the manager is graded the hard way: by whether the funded plan passes the tests.
