Home/
Part XIII — Expert Mode: Systems, Agents, and Automation/38. Building a Code-Change Agent Safely/38.3 Test-driven agent behavior
38.3 Test-driven agent behavior
Overview and links for this section of the guide.
On this page
TDD for Agents
Force the agent to write the test before the implementation.
- Write a failing test that reproduces the bug or asserts the feature.
- Run test -> FAIL (confirmed).
- Write implementation.
- Run test -> PASS (success).
If step 4 fails, the agent can see the error message and retry step 3. This self-healing loop is the "superpower" of vibe coding.
The Loop
max_retries = 3
while (test_fails and retries > 0):
error = run_tests()
code = model.fix(code, error)
retries -= 1