---
title: Recipe: Three agents race, tests pick · Agent Playground docs
description: Copies a project into three sandboxes, gives each a differently told agent, and keeps the passing fix with the fewest changes. What it does, when to use it, how to make it yours, and what a run costs.
url: https://www.quietrobot.ai/docs/playground/recipes/agent-race
---

# Recipe: Three agents race, tests pick

Copies a project into three sandboxes, gives each a differently told agent, and keeps the passing fix with the fewest changes. What it does, when to use it, how to make it yours, and what a run costs.

Copies one project into three sandboxes and sets an agent loose in each, told to work a different way: the smallest fix, a clean rewrite, or the rules first. A score step in each lane runs the tests and counts changed lines, and the judge keeps the lane that passes with the fewest changes. The losers' sandboxes are deleted.

| At a glance | |
|---|---|
| **Level** | Advanced |
| **Category** | Coding |
| **Shape** | Forked sandboxes, an agent in each, a judge |
| **Plan** | Pay as you go (runs 4 sandboxes at once) |
| **Needs a Claude key** | Yes |
| **Limits it comes with** | 1 loop, 900 seconds, $1.00 |
| **Claude key limit for a run** | $1.00 of Claude |

```flow
{"recipe": "agent-race", "title": "Three agents race, tests pick, as it is on the canvas.", "nodes": [["setup", "run", "Set up the project"], ["fork", "fork", "Fork ×3", "lanes A, B and C"], ["agentA", "agent", "Smallest fix", "lane A"], ["agentB", "agent", "Clean rewrite", "lane B"], ["agentC", "agent", "Rules first", "lane C"], ["scoreA", "run", "Score lane A", "lane A"], ["scoreB", "run", "Score lane B", "lane B"], ["scoreC", "run", "Score lane C", "lane C"], ["judge", "judge", "Highest score", "highest \"score\""], ["keep", "run", "Keep the winner"]], "edges": [["setup", "fork"], ["fork", "agentA"], ["agentA", "scoreA", "Done"], ["scoreA", "judge"], ["fork", "agentB"], ["agentB", "scoreB", "Done"], ["scoreB", "judge"], ["fork", "agentC"], ["agentC", "scoreC", "Done"], ["scoreC", "judge"], ["judge", "keep", "Passed"]]}
```

## The steps

| Step | Block | What it does |
|---|---|---|
| Set up the project | Run command | Writes a small shopping-cart module with three pricing bugs and five tests, and commits it so changes can be counted. |
| Fork ×3 | Try in parallel | Copies the sandbox into lanes A, B and C. |
| Smallest fix | Agent | Lane A: an agent fixes it with the smallest change it can. |
| Clean rewrite | Agent | Lane B: an agent rewrites the functions cleanly. |
| Rules first | Agent | Lane C: an agent writes down the rules first, then fixes. |
| Score lane A, B, C | Run command, one per lane | Each lane's score: 100 for each passing test, minus 1 for each changed line, printed as `{"score": ...}`. |
| Highest score | Keep the best | Keeps the lane with the highest score. |
| Keep the winner | Run command | Shows the winning change and saves it as `shop/winning.patch`. |

## When to use it

* You don't know which approach, prompt or model will solve a task, and trying them one after another is slow.
* You want the winner picked by tests and numbers, not by taste.
* Each try must not see or break the others.

## Run it

The quick way: choose **Try it now** under the drawing. It opens the recipe in the Playground as a flow of your own, after you sign in if you aren't yet. **Simulate** opens it and shows the forecast, and **Run** opens it and asks before it starts, with what the run will likely cost. From the dashboard instead:

1. In the dashboard sidebar, open **Agent Playground → Recipes** and find **Three agents race, tests pick**. Choose **Advanced** to filter the list. In the builder, **Recipes** in the toolbar lists them too.
2. Choose **Use this recipe**. It becomes a flow of your own, so changing it never changes the recipe.
3. If you haven't yet, [save your Claude key](https://www.quietrobot.ai/docs/playground/ai-steps#add-your-claude-key) on the **Secrets** page. The builder offers **Add a key…** in the step's key list if it's missing.
4. Choose **Simulate** to see the forecast, then **Run**.

**What you'll see:** The three agents work at the same time, each in its own sandbox. Open each lane's score step to compare them. The judge keeps one, and **Keep the winner** shows its diff.

## Make it yours

1. Clone your repository in **Set up the project** instead of writing the sample, and change the test command in `.qr/score.py`.
2. Give each agent a different goal, model or turn limit. Each agent's caps are on its step, under **It stops at whichever comes first**.
3. Change the score: for example passing tests minus seconds taken, or a benchmark's number. The judge reads the last JSON line each lane prints.
4. The flow's key limit caps all three agents together at $1 a run. The **Policy** panel shows it; change it in the flow's JSON under `policy.keyBudgets`.

## What a run costs

These are the builder's own forecast for the recipe as it comes, with its limits, rounded. **Simulate** shows the same numbers for your version, and they change as you change the flow.

| | Typical | 1 in 10 runs | At most |
|---|---|---|---|
| **Sandbox time** | $0.006 | $0.008 | $0.04 |
| **Claude, on your key** | $0.21 | $0.34 | the run's spend limit |
| **How long it takes** | about 2 minutes | about 3 minutes | 900 seconds |

A typical run uses $0.006 of sandbox time, so about 180 runs cost $1, and every plan includes $5 of usage a month. That includes all 4 sandboxes: the main one and each lane. Claude is billed by Anthropic to your own key, at their usual prices. The run counts it toward its spend limit, so it can't overspend, but we don't charge you for it. **At most** is the most a run could cost with these limits: it stops at $1.00 or 900 seconds, whichever comes first.

## Related

* [Try 3, keep the best](https://www.quietrobot.ai/docs/playground/recipes/try-three)
* [Tutorial 4: Try a few ways at once](https://www.quietrobot.ai/docs/playground/tutorials/lanes)
* [Agent fixes the failing test](https://www.quietrobot.ai/docs/playground/recipes/agent-fix-test)
* [All recipes](https://www.quietrobot.ai/docs/playground/recipes)
