Iterative Self-Correction Loops
Run tests, parse failures, ask the model to fix — the inner loop of every modern code agent.
Why Self-Correction?
First attempts often fail. The defining property of a code agent is its ability to:
- Run the code
- Read the error
- Fix the code
- Repeat
This inner loop is what separates real coding agents from text-completion demos.
The Loop
def code_until_pass(task, max_iters=10):
write_initial_code(task)
for i in range(max_iters):
result = run_tests()
if result.passed:
return 'success'
fix_prompt = f'Tests failed:\n{result.stderr}\nRead the code, identify the bug, and fix it with edit_file.'
agent.run(fix_prompt)
return 'gave up'All lessons in this course
- Agentic Patterns: Plan-Execute-Verify
- Tool Surfaces for Coding (Read, Edit, Bash)
- Iterative Self-Correction Loops
- SWE-Agent and OpenDevin Architectures