Free · 6 lessons · TypeScript · No framework
You use coding agents every day.
Build one.
Six short lessons that take you from a single model call to a small coding agent that plans, reads your code, asks before it edits, and checks its work with your tests. The loop and its tools come to about 250 lines.
you The tests are failing. Find out why and fix it. ── turn 1 ────────────────────────────── ◐ Run the tests and find the failure ○ Read the code under test ○ Fix the bug ○ Run the tests again ── turn 2 ────────────────────────────── tool → run_tests() tool ← 5 pass, 1 fail: "shipping is free at exactly 50.00" ── turn 4 ────────────────────────────── model The test is right and the code is wrong. tool → edit_file(src/cart.js) - return subtotal(items) > FREE_SHIPPING_FROM ? 0 : SHIPPING_COST; + return subtotal(items) >= FREE_SHIPPING_FROM ? 0 : SHIPPING_COST; Allow edit_file on src/cart.js? [y/N] y ── turn 5 ────────────────────────────── tool → run_tests() tool ← 6 pass
No API key to start
Every lesson runs in replay mode with pre-written model replies. The loop, the tools and the tests are real. Add a key to run it live against Claude.
No framework
Just the official Anthropic SDK and a while loop. Once you know what frameworks do for you, picking one gets much easier.
Safe by default
The agent works on a throwaway copy, can't leave the project folder, and asks you before every edit.
The lessons
1
Text in, text out
Tool calling with no tools API. Just a prompt and an if.
2
Your first real tool call
Schemas, tool_use, tool_result, and where one round runs out.
3
Keep going until it's done
Let the model take as many rounds as it needs.
4
Give it a to-do list
The checklist trick from coding agents, in one tool.
5
Guardrails: the boring code that matters
Sandboxed paths, recoverable errors, approvals, limits.
6
A mini coding agent
All of it together, fixing a real failing test.
+
Do you even need an agent?
Workflows vs agents, and a 4-question checklist.
Run it in a minute
git clone https://github.com/georgehanu/the-agent-loop.git
cd the-agent-loop
npm install
npm run lesson1
Node.js 20 or newer. That's it.