cd /news/ai-agents/how-to-build-a-coding-agent-that-fix… · home › topics › ai-agents › article
[ARTICLE · art-179736] src=getfloo.com ↗ pub= topic=ai-agents verified=true sentiment=· neutral

How to build a coding agent that fixes a failing test

A tutorial published on getfloo.com shows how to build a coding agent that repairs a failing test by giving the model a reproduced failure and a single file to edit, rather than repository write access. The example uses a shipping-fee bug in which an order of exactly 5,000 cents should charge 0 but the function returns 599, and the agent's proposed fix changes `subtotal > 5000` to `subtotal >= 5000`, after which the check prints "3 cases passed". The host requires a failure with the expected three values before asking the model to edit anything, allows two failed proposals before ending the run, and returns a unified diff for human review.

recommendation

Reproduce the exact failing test before letting the agent edit, give it one file, cap retries at two, and apply the returned diff to a clean checkout and run CI before merging.

more in playbook: Working with AI coding agents
by read3 min views1 publishedNov 26, 2026

TL;DR #

An order for exactly $50 qualifies for free shipping. The checkout still adds $5.99. Give a coding agent a way to reproduce that single failure and verify the change it proposes.

  • Keep the original source and the three test cases on the host.
  • Send the model the observed failure and let it propose a source edit.
  • Run the check again and return a diff for review.

Put the boundary in the test #

The fixture uses integer cents. Shipping is 599 cents below the threshold and zero from 5,000 cents up. The bug is easy to miss in a demo because orders on either side already work.

def shipping_cents(subtotal):
    return 0 if subtotal > 5000 else 599

Test 4,999, 5,000, and 5,001 cents. The middle case distinguishes “at least” from “more than.” The case immediately below it prevents a superficially successful fix that makes shipping free for everyone. Repair agent source · Host helper

Run the repair #

Use Python 3.10 or later, a signed-in Claude Code CLI, and a floo account with sandbox credits. Sign in with the floo CLI or set FLOO_API_KEY in your shell. Run these commands in an empty directory.

python3 -m venv .venv
. .venv/bin/activate
python -m pip install floo-sandbox==0.2.0
export FLOO_API_KEY="${FLOO_API_KEY:-$(floo auth token)}"
base=https://getfloo.com/examples/sandbox-agents
curl -fsSLO "$base/agent_tools.py"
curl -fsSLO "$base/repair_agent.py"
python repair_agent.py

The script writes shipping.py and check.py into one sandbox. It runs the original code first. The host requires a failure with the expected three values before it asks the model to edit anything.

Reproduced: AssertionError: (5000, 0, 599)

Read the tuple as input, expected fee, and actual fee. A missing interpreter or a broken import produces a different failure. Sending that to a model as evidence of a shipping bug would send it after the wrong problem.

Give the agent one file to change #

The host sends Claude the pricing rule, original function, test, and captured failure. Claude returns replacement Python. The host writes the candidate to the workspace and invokes the same check with bytecode caching disabled. That detail matters for tiny edits made within the same second: the next test should load the bytes the agent just wrote.

If a proposal fails, the second attempt sees the candidate and its error. Two failed proposals end the run. On a pass the host computes a unified diff against the original source. Here's the change from our run:

-    return 0 if subtotal > 5000 else 599
+    return 0 if subtotal >= 5000 else 599

The check printed 3 cases passed. A reviewer can connect that one character to a business rule, three inputs, and an observed failure. Nothing in this example grants the model repository write access.

Adapt it to an actual bug #

Pick one failing test in your project and copy the smallest source tree and dependency lockfile that reproduce it. Record the exact command and expected failure. Replace the toy fixture only after that command fails for the same reason in the sandbox and in your normal test environment.

The tutorial checks one behavior. Before accepting a patch to your project, apply the diff to a clean checkout and run your usual suite in CI. A model proposal and its sandbox output are inputs to the review. The independent checkout is what verifies the patch you would merge. Sandbox execution guide

── more in #ai-agents 4 stories · sorted by recency
── more on @getfloo.com 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/how-to-build-a-codin…] indexed:0 read:3min 2026-11-26 · —