quiet robot

Recipe: Agent swarm, fork the best

Five agents speed up the same slow program in forked sandboxes. The fastest is forked again for three more tries. What it does, when to use it, how to make it yours, and what a run costs.

View as Markdown

Five agents work on the same slow program at once, each in its own copy of the sandbox and each told to try a different way. Every try is timed on the sandbox's own CPU, and its output must match the original byte for byte. The judge keeps the fastest. Then the winner is copied again, three more agents try to beat it, and the winner itself races too, so a round that finds nothing faster keeps it. The losers' sandboxes are deleted as soon as each round is judged.

At a glanceNotes
LevelAdvanced
CategoryCoding
ShapeFive agents race, the fastest is forked and raced again
PlanPay as you go (runs 6 sandboxes at once)
Needs a Claude keyYes
Limits it comes with1 loop, 1,800 seconds, $1.00
Claude key limit for a run$0.90 of Claude
Agent swarm: fork the best, as it is on the canvas.Make the slow program (Run command), Fork ×5 (Try in parallel), Profile first (Agent), No regex (Agent), Clean rewrite (Agent), Time lane A (Run command), Time lane C (Run command), Time lane E (Run command), Fastest of five (Keep the best), Best so far (Run command), Fork the best ×4 (Try in parallel), Hot loop (Agent), Another idea (Agent), Time lane F (Run command), Time lane H (Run command), Time the parent (Run command), Fastest overall (Keep the best), Report the winner (Run command). Arrows: Make the slow program to Fork ×5; Fork ×5 to Profile first; Fork ×5 to No regex; Fork ×5 to Clean rewrite; Profile first to Time lane A on Done; No regex to Time lane C on Done; Clean rewrite to Time lane E on Done; Time lane A to Fastest of five; Time lane C to Fastest of five; Time lane E to Fastest of five; Fastest of five to Best so far on Passed; Best so far to Fork the best ×4; Fork the best ×4 to Hot loop; Fork the best ×4 to Another idea; Fork the best ×4 to Time the parent; Hot loop to Time lane F on Done; Another idea to Time lane H on Done; Time lane F to Fastest overall; Time lane H to Fastest overall; Time the parent to Fastest overall; Fastest overall to Report the winner on Passed.DoneDoneDonePassedDoneDonePassed>_ RUN COMMANDMake the slow program⑂ TRY IN PARALLELFork ×5lanes A to E◉ AGENTProfile firstlane A◉ AGENTNo regexlane C◉ AGENTClean rewritelane E>_ RUN COMMANDTime lane Alane A>_ RUN COMMANDTime lane Clane C>_ RUN COMMANDTime lane Elane E★ KEEP THE BESTFastest of fivelowest "ms">_ RUN COMMANDBest so far⑂ TRY IN PARALLELFork the best ×4lanes F, G, H and P◉ AGENTHot looplane F◉ AGENTAnother idealane H>_ RUN COMMANDTime lane Flane F>_ RUN COMMANDTime lane Hlane H>_ RUN COMMANDTime the parentlane P★ KEEP THE BESTFastest overalllowest "ms">_ RUN COMMANDReport the winner
Agent swarm: fork the best, as it is on the canvas.
Try it nowSimulateRun

Opens it in the Playground as a flow of your own. Simulate shows what a run costs. Run asks before it starts.

The picture leaves out a few lanes so it fits: the recipe has five agents in the first round (A to E) and three in the second (F, G and H), each followed by its own timing step, and lane P has one more step before its timing.

The steps

StepBlockWhat it does
Make the slow programRun commandWrites a 17 MB web server log and report.py, which summarizes it correctly but slowly, then times the original.
Fork ×5Try in parallelCopies the sandbox into lanes A to E.
Profile first, One pass, No regex, Smallest change, Clean rewriteAgent, one per laneEach agent makes report.py faster in its own way. Its output must not change.
Time lane A to ERun command, one per laneChecks the output against the original, then times three runs and prints the median as {"ms": ...}.
Fastest of fiveKeep the bestKeeps the fastest lane. The other four are deleted.
Best so farRun commandSays how fast the winner is. The next round's agents are told this number.
Fork the best ×4Try in parallelCopies the winner into lanes F, G, H and P.
Hot loop, Cheaper parsing, Another ideaAgent, one per laneEach agent tries to beat the winner.
The parent, as it isRun commandLane P leaves the winner as it is, so it races too.
Time lane F, G, H, Time the parentRun command, one per laneThe same timing as the first round.
Fastest overallKeep the bestKeeps the fastest of the second round, which may be the parent.
Report the winnerRun commandSays how much faster the winner is than the original.

When to use it

  • There's more than one good way to do a job and you don't know which will win: try them all at once and keep the best.
  • The score is a number you can measure, like time, test results or a benchmark, so nobody has to judge by taste.
  • You want to build on the best result so far instead of starting every try from scratch.

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 Agent swarm: fork the best. 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 on the Secrets page.
  4. Choose Simulate to see the forecast, then Run.

What you'll see: The original takes about 3 to 4 seconds. Five agents work at the same time, each in its own sandbox, and each lane's timing step shows how much faster it got. The second round starts from the winner and usually pushes it further. Report the winner says how much faster the final version is.

Make it yours

  1. Swap the sample for your own slow code: clone your repository in Make the slow program, and change .qr/check.py to run your tests and your benchmark. The judge reads the last JSON line each lane prints, so any number works.
  2. Give the agents different instructions, models or turn limits. Each agent's caps are on its step, under It stops at whichever comes first.
  3. Want more rounds? Copy Best so far, the second fork, its lanes and its judge, and connect them after Fastest overall. A run can make up to 30 sandboxes in all and 10 lanes per fork.
  4. The flow's key limit caps all eight agents together at $0.90 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.

NotesTypical1 in 10 runsAt most
Sandbox time$0.02$0.02$0.05
Claude, on your key$0.04$0.05the run's spend limit
How long it takesabout 5 minutesabout 6 minutes1,800 seconds

A typical run uses about $0.02 of sandbox time for ten sandboxes in all, and every plan includes $5 of usage a month. 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 1,800 seconds, whichever comes first.

  • Agent PlaygroundQuickstart: build and run your first flow
  • Agent PlaygroundBlocks
  • Agent PlaygroundRecipes
  • SandboxesQuickstart: your first sandbox
  • SandboxesMCP server
  • SandboxesAPI reference
  • InsightsAll posts