Build Your Own AI AgentElena Daehnhardt |
Image credit: Illustration created with Midjourney, prompt by the author.
Image prompt“An illustration representing cloud computing” |
Build Your Own AI Agent
Most writing about AI agents is either a demo or a diagram. This series is neither. Over six parts I build one agent in Python, from around 120 lines to something I would actually let near my own repository, and every part ends with working code you can run.
The agent reads, edits and creates files. It swaps between Claude, GPT and a local model on your own machine with a one-line change. It logs what it did and what it cost. And by the end it stops when a test says the work is finished, rather than when the model says so — which turns out to be the difference that matters.
What You’ll Learn
- Part 1: A Minimal AI Agent That Edits Your Files — the edit primitive everything rests on: replace exact text that must match exactly once, inside one directory the agent cannot leave
- Part 2: One Agent, Any Model — Claude, GPT, Ollama and anything OpenAI-compatible, with the provider as a config value rather than a code branch
- Part 3: Knowing What Your Agent Did (and What It Cost) — a per-action audit trail and real token accounting, including why cached tokens have to be counted separately
- Part 4: Tests as the Verdict — the agent checks its own work and the loop ends on an exit code; backups, a branch per run, and why there is no shell tool
- Part 5: Quality Gates for Prose and Data — the same idea generalised beyond code: link checking, schema validation, and a reviewer whose opinion is recorded but never allowed to decide
- Part 6: Off the Leash — splitting the work across roles, adopting a production harness, and an honest account of what I would still not automate
Series Progress
No posts are linked to this series yet.
All Posts in This Series
Getting Started
This series is coming soon. The first post introduces the foundations.
Who Is This Series For?
- Python developers who have used a coding assistant and want to know what is inside one
- Anyone building agents who has hit the point where the demo works and the real repository does not
- Readers who prefer local models — every part runs on Ollama as well as on a hosted API
- Sceptics, genuinely. If you think agents are mostly hype, the parts on verification are the argument worth reading
You should be comfortable with Python and the command line. You do not need any previous agent experience, and you do not need to pay for an API: a local model will do for all six parts.
Series Philosophy
- The tool contract is the lesson. The model is a string and the loop belongs to a library. What you actually design is what the tools refuse to do, and how clearly they say so.
- Deterministic beats agreeable. A test runner, an HTTP status and a schema cannot be talked round. A model asked to approve its own work usually can be.
- Small tool surfaces. An agent with a shell has every capability there is. There is no shell in any of the six parts.
- Honest limits. Containment is a guardrail, not a sandbox, and a green test is a floor, not a ceiling. I say so each time it matters.
- Every version runs. Each part is tagged, so the code in a post is a version you can check out rather than a snippet you have to reassemble.
Where This Came From
This series grew out of Two AI Agents, One Blog Post, where a writer agent and an editor agent passed a draft back and forth until the editor was satisfied. That project could not damage anything — the worst case was a mediocre draft.
Giving an agent write access to files changes the engineering completely. Not the prompt. Everything around it.
Questions or Feedback?
If you are building something similar and hit a problem I have not covered, I would like to hear about it — you can reach me through the contact form or leave a comment on any part.