Get Started

Build a coding agent that fixes its own mistakes

An AI agent is not a chatbot. It is a loop: a model that can call tools, run over and over until a job is done. In this mission you build a small coding agent in Python, hand it a failing test on a toy repository, and watch it read the code, write a fix, run the tests, read the failure, and try again until the tests pass or a step budget stops it. It runs entirely on your own machine against a local model through Ollama, so there is nothing to buy and nothing leaves your computer. You will see it fix a two-part bug it gets wrong on the first try, watch a weaker model get stuck and the step budget end the run, and build the safety rails that make an agent safe to run at all: a working directory it cannot escape, a step budget, and an approve-before-write switch.

72 minAdvancedTools: FreeStep 1 free
Tested 12 Oct 2026 · qwen2.5:3b (1.9GB) through Ollama 0.40.3, with Python 3.13.5 and uv 0.11.9, on Windows 11, CPU only, no GPU. The step-budget run used llama3.2:1b (1.3GB). Every trace below is real output from running the kit on that machine, with the model temperature set to 0. A model is not fully deterministic even at temperature 0, so an exact run can vary: the number of steps, and which fix lands first, may differ for you. That is normal and the lesson says where it matters.
A working coding agent in one Python filethree tools (read a file, write a file, run the tests), a local model wired in through Ollama, and the loop that drives them
A real trace of the agent fixing a bug it gets wrong at first: it writes a fix, runs the tests, reads the failure, corrects itself, and goes green, all on a CPU with no GPU
The safety rails that make an agent safe to run on your machine: a working directory it cannot write outside of, a step budget that stops it looping forever, an approve-before-write mode, and an honest look at what a 3B model can and cannot do
Before you start
  • Ollama with a small, tool-capable model. Run AI on your PC installs Ollama in a few minutes. Then pull the model this mission uses: ollama pull qwen2.5:3b (1.9GB). It runs on a normal laptop CPU; no GPU needed.
  • uv, the Python tool from Level 0. Install anything from GitHub, safely shows the one-line install. Check with uv --version.
  • A little Python: functions, dicts and lists. You do not need to have built an agent before. Every file is complete and explained, and the whole agent is in the starter kit.
  • A terminal you are comfortable in. The terminal survival kit covers the basics if they are new.
01/07What an agent really is: a loop with tools0 done
STEP 01 of 07~8 min

What an agent really is: a loop with tools

Pin down the one idea the hype hides before writing any code. An agent is a loop: a model decides, a tool acts, the result comes back, and round it goes until a stopping condition is met.

  1. An agent is a program that gives a model a set of tools and runs it in a loop. The model looks at the situation, decides on one action, your program carries that action out, and the result is fed back so the model can decide again. That loop, observe, think, act, repeated until a goal is met or a limit is hit, is the whole idea. Everything else is detail.

  2. Tool calling (also called function calling) is how the model takes an action in the real world. On its own a model only produces text. You give it a short menu of tools it is allowed to use, for example 'read a file' or 'run the tests', and the model replies with the name of a tool and the arguments to call it with. Your code runs the tool and hands back the result. The model never touches your files itself; it asks, and your code decides what to do.

  3. For the agent you are about to build, one turn of the loop looks like this:

    • Observe: the agent is told the task and which files are in the folder.
    • Think: the model picks one tool: read a file, write a file, or run the tests.
    • Act: your code runs that tool inside a sandbox folder and captures the result.
    • Repeat: the result is fed back and the model decides again, until the tests pass or the step budget runs out.
  4. The part people forget is the stopping condition. A loop with no way to stop is a program that burns time and money forever. This agent has two ways to stop: the tests pass (it won), or a step budget is used up (it gives up). You will build both, because the second one is what makes an agent safe to leave running.

    TipThis is the same shape as the large coding agents. Claude Code, Cursor's agent and Aider are far bigger and cleverer, but underneath they are this loop: a model, a set of tools, and a condition that ends the run. Building the small version is the fastest way to understand the large ones.
    CarefulAn agent writes files and runs commands for real. Never point one at your home folder, your documents, or a project you care about, and never let one run arbitrary commands on a machine that matters. Everything in this mission stays inside one throwaway folder, and the agent is built so it cannot write outside it. Treat that confinement as the rule, not the exception.
✓
CheckpointYou can say, in one sentence, what observe, think, act means, and name the two ways this agent is allowed to stop.
Stuck? Ask the community
Next mission · AI engineeringSort thousands of records with a local AI, for free
→