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 List files so it can navigate your project Edit files so it can give the directive to create and modify code That’s it. Production agents like Claude Code have a few more capabilities including grep, bash, websearch, etc but for our purposes we’ll see that three tools is sufficient to do incredible things. Setting Up the Scaffolding We start with basic imports and an API client. I’m using OpenAI here, but this works with any LLM provider: import inspect import json import os import anthropic from dotenv import load_dotenv from pathlib import Path from typing import Any, Dict, List, Tuple load_dotenv() claude_client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"]) Some terminal colors to make outputs readable: YOU_COLOR = "\u001b[94m" ASSISTANT_COLOR = "\u001b[93m" RESET_COLOR = "\u001b[0m" And a utility to resolve file paths (so file.py becomes /Users/you/project/...
First seen: 2026-01-08 20:49
Last seen: 2026-01-10 01:53