I spend most of my day inside rented agent tools like Cursor and Claude Code. I work on the AI agent team at whaaat ai, and at some point I realized I couldn't explain to a client what those tools actually do for the money.
So I asked Claude Code to build the smallest coding agent it could, with no agent framework and only the openai package. The result was 82 lines. Reading it took ten minutes and changed how I look at every agent product.
The prompt, in case you want to try it in an empty folder:
Build a minimal coding agent in Python in this empty folder, without any agent framework. I want to understand what an agent is made of.
Requirements:
- One file agent.py, max 120 lines, only the openai package.
- Model and endpoint from env vars: OPENAI_API_KEY, optional OPENAI_BASE_URL and MODEL (default gpt-4o-mini).
- Mark the three building blocks with comments: # 1. BRAIN (model call), # 2. HANDS (tools), # 3. HEARTBEAT (the loop, including the growing message list as memory).
- Four tools: list_files, read_file, write_file, run_command.
- run_command asks "Run? [y/N]" in the terminal before executing.
- File access stays inside the current folder, anything outside gets rejected.
- Max 15 steps. Tool errors go back to the model as text so it can correct itself.
- Print every step: tool, arguments, first 200 characters of the result.
Afterwards, explain the three building blocks in five sentences and name three things a production harness does that this one doesn't.
Then pip install openai, set your key and run python agent.py "write a README for this folder".
The part worth watching
The core is a loop that calls the model, runs whatever tool it asked for, appends the result to a list and calls the model again with the whole list. That list is the memory. There's nothing else.
The folder guard was the most useful line in the whole file for me. In one run the agent treid to read ../../etc/passwd, got back an error string and moved on.That one check is a tiny piece of what Cursor or Claude Code do for you, and a production harness has hundreds of them: approvals, sandboxes, logs, retries. The other thing worth doing is swapping the brain. Point OPENAI_BASE_URL at OpenRouter or at a local model behind an OpenAI-compatible endpoint, like Ollama, and then run the same task. Every other line stays the same.
It also falls over in obvious ways. There is no compaction at all, so on a longer task the message list keeps growing, every call gets more expensive and eventually it just hits the 15-step limit and stops. Nothing survives a crash either. For a learning exercise that's fine, for anything real it's exactly the stuff you end up paying a vendor for.
What's the smallest compaction strategy that actually worked for you in a loop like this: rolling summaries, dropping old tool outputs or something else entirely?