Build your own AI agent
Everyone selling you an AI agent is selling you a monthly bill for something you could stand up yourself in an afternoon. The word sounds like a product. It isn't. It's a shape you can build.
Strip the marketing off and an agent is three plain parts: a model that can read and write text, a way for you to talk to it, and a set of tools it is allowed to use on your behalf. That's the whole animal. A model with a phone and a short list of things it's allowed to touch.
Think of it like hiring. A chatbot is a person who can only answer questions. An agent is a person you can actually hand a task to, because you gave them keys to a couple of specific rooms and nothing else. The intelligence was always in the model. The useful part is the keys, and the keys are yours to hand out.
Why bother when the paid ones exist
Because the paid one runs on someone else's computer, reads whatever you feed it, and can change its price or its rules on a Tuesday. When you own the loop, the model is a part you can swap, the tools are yours, and the whole thing keeps working whether or not a company still feels like offering it. You wire it to your stuff, not to their catalog.
I built mine as a chat bot first, because a chat window is the fastest way to prove the thing is alive. You type, it answers, you see it happen. That proof-of-life bot took an evening. Everything after that was just handing it more keys.
The part that trips people up
People think the hard part is the model. It isn't. Running a capable model is now a one-line install. The hard part, the part that makes it an agent instead of a parrot, is the loop: the model asks to use a tool, your code runs that tool, you hand the result back, and it decides what to do next. That back and forth is the entire trick, and once you've watched it happen once it stops being magic and starts being plumbing.
Start with a model that fits your machine. A smaller model that runs on the hardware you own beats a giant one you rent, because you can let it run all day for free and it never phones home. Field Log 001 covers picking a local model in detail. This log is what you build on top of it.
Now the part where I gave it too many keys
The first time I let a bot run a real command for me, I let it run any command. Felt powerful for about a day. Then it confidently misread a request and did the literal thing I typed instead of the thing I meant, which is exactly what a very fast, very literal intern would do. Nothing burned down, but it taught me the actual lesson of agents: the model is not the risk, the keys are. A model that can only do three specific things can only ever surprise you in three specific ways.
So I put it on a leash. Every tool it can call is a function I wrote, with the input checked before anything happens, and the genuinely destructive actions ask me first. It got less exciting and far more useful the same afternoon.
A working agent from zero: a model, a chat channel to reach it, and a small set of tools it's allowed to call. Runs on a machine you already own. Replace every value in angle brackets with your own.
1. Get a model talking
Install a local model runner and pull a model that fits your memory. This gives you a local endpoint that speaks the same request shape as the big hosted APIs, which means everything you build against it also works against a hosted model later if you ever want to swap.
# install a runner, then pull a small model that fits your RAM
ollama pull <small-model>
# it now serves a local, OpenAI-compatible API on your own machine
curl http://localhost:11434/api/generate -d '{"model":"<small-model>","prompt":"say hello"}'
Source: the runner (ollama.com) or, if you'd rather build it yourself, llama.cpp.
2. Give it a mouth
Pick one channel you already live in so you never have to build a UI. A chat app is perfect. Register a bot, get a token, and your code now has a place to receive messages and send replies. This is the proof-of-life step: get it echoing before it's clever.
# minimal loop, any language:
# 1) receive a message from the chat channel
# 2) send the text to the model from step 1
# 3) send the model's reply back to the chat
# that's a working assistant. commit here before adding tools.
Source: the Telegram Bot API is a clean, free place to start, but any chat channel with an API works.
3. Give it hands
A tool is just a function you wrote, described to the model in plain words: what it does and what inputs it takes. Start with one safe, read-only tool, like "look something up" or "read a file I name." Describe it, and let the model ask for it by name.
# describe each tool to the model: name, what it does, its inputs.
# keep the first one read-only so a misfire can't hurt anything.
tool: get_weather(city) # returns text, changes nothing
4. Close the loop
This is the step that turns a chatbot into an agent. When the model asks to use a tool, your code runs that function, hands the result back, and asks the model what to do next. Repeat until it has a final answer. That cycle, model to tool to model, is the entire idea.
# the agent loop:
# model -> "call get_weather('<your-city>')"
# your code runs it -> feeds the result back to the model
# model -> final answer, or asks for the next tool
# loop until done. cap the number of turns so it can't spin forever.
5. Keep it on a leash
Now, and not later, put the guardrails on. Validate every input before a tool runs. Keep tools narrow, one job each. Make anything destructive ask you for a yes before it acts. The model is not the danger, the keys you hand it are, so hand out few keys and check them at the door.
# the three rules that make an agent safe to leave running:
# 1) each tool does ONE narrow thing
# 2) validate the inputs before you act on them
# 3) destructive actions require an explicit yes from you
You now own an agent. Swap the model for a bigger one when you need more, add a tool when you have a new job for it, and it keeps costing you nothing to leave running. Next, point it at the rest of your stack from these logs.