↻ The Agent Loop

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.

npm run agent
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

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.

Hi, I'm George.

I'm a senior web developer. I teach developers to build software with AI, from useful scripts to app features. Small examples, explained clearly. If this helped, the best thanks is a follow, and tell me what you built.

Follow @georgehanu on X