Today AI coding assistants feel like magic. You describe what you want in sometimes barely coherent English, and they read files, edit your project, and write functional code.
But here’s the thing: the core of these tools isn’t magic. It’s about 200 lines of straightforward Python.
Let’s build a functional coding agent from scratch.
The Mental Model
Before we write any code, let’s understand what’s actually happening when you use a coding agent. It’s essentially just a conversation with a powerful LLM that has a toolbox.
You send a message (“Create a new file with a hello world function”) The LLM decides it needs a tool and responds with a structured tool call (or multiple tool calls) Your program executes that tool call locally (actually creates the file) The result gets sent back to the LLM The LLM uses that context to continue or respond
That’s the whole loop. The LLM never actually touches your filesystem. It just asks for things to happen, and your code makes them happen.
Three Tools You Need
Our coding agent fundamentally needs three capabilities:
Read files so the LLM can see your code
... continue reading