quiet robot

Agent Playground

Recipe: Fix until tests pass

Writes a function, runs the tests, fixes what failed and runs them again until they pass. What it does, when to use it, how to make it yours, and what a run costs.

View as Markdown

Runs a project's tests, and when they fail, fixes the code and runs them again, until they pass or the loop limit is reached. It's the simplest useful loop, and the shape behind most "keep at it until it works" jobs.

At a glanceNotes
CategoryCoding
ShapeA loop
PlanFree and up
Needs a Claude keyNo
Limits it comes with5 loops, 180 seconds, $0.05
Fix until tests pass, as it is on the canvas.Set up project (Run command), Write code (Run command), Run tests (Run command), Fix failures (Run command), Save result (Run command). Arrows: Set up project to Write code; Write code to Run tests; Run tests to Fix failures on Failed; Fix failures to Run tests; Run tests to Save result on Passed.FailedPassed>_ RUN COMMANDSet up project>_ RUN COMMANDWrite codego back here>_ RUN COMMANDRun tests>_ RUN COMMANDFix failures>_ RUN COMMANDSave result
Fix until tests pass, as it is on the canvas.
The Fix until tests pass recipe in the builder after a run, with each step's result on the canvas and the run's steps listed on the right.
A real run of the recipe. The panel on the right lists every step with what it printed.

When to use it

  • You have a check that says pass or fail (tests, a linter, a script that validates a file) and something that can make the next attempt better.
  • You want an AI agent to keep fixing code until the tests are green, with a cap on how many tries it gets.
  • You're learning the Playground: this is the recipe to start with.

Run it

  1. Open Agent Playground in the dashboard and find Fix until tests pass under Start from a recipe. 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. Choose Simulate to see the forecast, then Run.

What you'll see: Run tests fails three times, each time with fewer failures (1 passed, 3 failed, then 2 passed, then 3 passed), and passes on the fourth try. The panel groups the steps by First pass, Loop 1, Loop 2 and Loop 3, and Save result packs the working code into result.tgz.

Make it yours

  1. Change Set up project to get your own code, for example git clone https://github.com/you/app proj && cd proj && pip install -r requirements.txt. For a private repository, save a token under Policies → Secrets first.
  2. Change Run tests to your test command: pytest -q, npm test, go test ./....
  3. Replace Fix failures with an Agent. Set its Goal to The tests in proj fail. Fix the code so they pass. Don't change the tests., use Insert… to add the output of Run tests, and set Check that it worked to your test command. You'll need your Claude key.
  4. Change Save result to whatever should happen with working code: package it, open a pull request, or add an Approval first.
  5. Open Limits and set Loops to how many tries you'd accept (3 to 5 is typical with an agent), and Spend to cover the agent's Claude use.

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.0002$0.0004$0.0023
How long it takes20 seconds35 seconds180 seconds

A typical run uses $0.0002 of sandbox time, so about 4,000 runs cost $1, and every plan includes $5 of usage a month. At most is the most a run could cost with these limits: it stops at $0.05 or 180 seconds, whichever comes first.

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