How to Build an Agent: an LLM, a loop, and enough tokens
Thorsten wrote the note for engineers who assumed coding agents hide some clever secret, and he asks them to type out every line so they see for themselves that they don't.
The claim, stated up front
The subtitle gives away the argument before any code appears. Watching an agent edit files and recover from errors, you assume there is a secret. Thorsten's answer is three nouns:
There isn’t. It’s an LLM, a loop, and enough tokens.— Thorsten Ball, How to Build an Agent
He defines an agent narrowly. The model has to be able to change something outside its own context window, and tools are how it does that. A model that only talks is a chatbot. The note links that definition to an earlier interview, Agents At Work 4 from February 2025, so he had been using it before he wrote any of this down:
an LLM with access to tools, giving it the ability to modify something outside the context window.— Thorsten Ball, How to Build an Agent
The setup is deliberately bare: Go, an ANTHROPIC_API_KEY environment variable, the official anthropic-sdk-go, and later invopop/jsonschema for generating tool schemas. There is no framework and no system prompt. The model constant in the code is ModelClaude3_7SonnetLatest with a 1024-token response cap.
Stage one: a chat loop, and who keeps the state
The first program is a REPL (read, evaluate, print, loop). Read a line from stdin, wrap it as a user message, append it to a slice called conversation, call the Messages API with the whole slice, append the reply, print any text blocks, repeat. The note puts this at 90 lines.
The point of this stage is to make you notice where the memory lives. The model remembers your name on turn three only because your program sent turns one and two again. The API is stateless, so the client owns the transcript and pays to resend all of it on every call. Every later feature hangs off that slice. Tool calls and their results become more entries in it, and the model sees its own earlier actions only because you replay them.
Before writing any tool code he shows that tool use is a convention the model already follows. In plain chat he tells Claude to answer weather questions with get_weather(<location_name>), asks about Munich, gets back exactly that string, types in a fake forecast, and Claude carries on as if it had looked something up. The provider APIs formalise this. You send a list of tool definitions, the provider turns them into prompt text the model was trained on, and the model answers in a structured shape when it wants one called. Anthropic documents the wrapping in its tool-use overview, which the note links.
Stage two: what a tool is, in four fields
Each tool is a name, a description, a JSON schema for its input, and a Go function that does the work. The first three go to the model. The function stays on your machine.
type ToolDefinition struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema anthropic.ToolInputSchemaParam `json:"input_schema"`
Function func(input json.RawMessage) (string, error)
}
That split carries the design. The description and schema are the tool's only interface to the model, so they are prompt engineering under another name. The read_file description says what it returns and also when not to use it ("Do not use this with directory names"). The function is ordinary code with no awareness of AI: read_file unmarshals a path and calls os.ReadFile. A small generic helper reflects a Go struct into the JSON schema, so the struct tags double as per-parameter descriptions.
Stage three: the round trip
With the first tool registered but the loop unchanged, asking "what's in main.go?" gets a reply announcing that Claude will read the file, then nothing. The model asked for a tool and the program dropped the request. The fix is a rewrite of Run(), and this is the core of it:
case "tool_use":
result := a.executeTool(content.ID, content.Name, content.Input)
toolResults = append(toolResults, result)
}
}
if len(toolResults) == 0 {
readUserInput = true
continue
}
readUserInput = false
conversation = append(conversation, anthropic.NewUserMessage(toolResults...))
Here is what happens on the wire. The model's reply is a list of content blocks. A text block is printed. A tool_use block carries an id, a tool name and a JSON input. executeTool looks the name up in the local registry, runs the function, and wraps the output in a tool_result block that points back to the same id. Errors go back as well, with an error flag set, so the model can see that a call failed and try something else. All the results from one turn are bundled into a single message with the user role and appended to the conversation.
Then comes the readUserInput flag. If the model asked for tools, the loop skips the "You:" prompt and calls the model again straight away with the results in context. If the reply was text only, control goes back to the human. That one boolean is the difference between a chatbot and an agent: the model can take several steps in a row while the human waits. The note admits this means a loop inside a loop and doesn't apologise for it.
The three tools, and what they show
read_file proves the round trip. With a riddle saved in secret-file.txt, the request "help me solve the riddle in the secret-file.txt file" makes Claude call read_file and answer. No instruction said "when the user mentions a file, read it". The description alone was enough.
You just give it a tool and it… uses it when it thinks it’ll help solve the task.— Thorsten Ball, How to Build an Agent
list_files walks a directory and returns a JSON array of relative paths, with directories marked by a trailing slash. It shows composition. Asked which Go version the project uses, Claude lists the directory, picks go.mod, reads it and answers, chaining two tools across two model calls with nobody prompting it in between. Thorsten uses this tool to make a point about output design. The trailing slash was his own choice, and any format works if the model can make sense of it, at an acceptable token cost:
There’s no fixed format. Anything goes as long as Claude can make sense of it and whether it can you need to figure out by experimentation.— Thorsten Ball, How to Build an Agent
edit_file is the one readers expect to be hard. It is string replacement: a path, an old_str, a new_str. An empty old_str on a missing file creates the file, which a small helper handles. He picked the interface because Claude 3.7 handles string replacement well, and he adds that you only find out what a model is good at by trying. Given that tool, Claude writes a runnable fizzbuzz.js, then reads it back and makes two edits to cut it to 15, changing the comment at the top to match without being asked. It also writes a congrats.js that ROT13-decodes the string the note gives it, and the decoded output congratulates you on building a code-editing agent.
One detail a careful reader will spot (our observation, not the note's): the schema tells the model that old_str must match exactly once, but the implementation calls strings.Replace(..., -1), which replaces every match. The model is told about a constraint the code does not enforce. That is the kind of gap Thorsten's "elbow grease" covers in a real product.
How little code it is
The note is written to make you feel the size of the program, so it reports a running count rather than a final figure:
| Promise at the start | "less than 400 lines of code, most of which is boilerplate" |
| Chat loop working | 90 lines |
| After read_file and list_files | "around 190 lines" |
| Closing line | "300 lines of code and three tools" |
The figures don't quite agree (under 400 at the top, 300 at the end), and in May he described it in Joy & Curiosity #40 as "around 300 lines of Go". Either way the scale is a few hundred lines, mostly Go error handling and SDK type plumbing. The same newsletter item points to Philip Zeyliger's The Unreasonable Effectiveness of an LLM Agent Loop with Tool Use, which gets the idea down to nine lines of pseudocode, and Thorsten recommends it.
Why the emperor has no clothes
The subtitle carries the thesis. Most of what makes an agent impressive comes from the model. The harness around it is a short loop that any competent engineer can write in an afternoon. The note ends by listing what Amp adds on top: editor integration, a tuned system prompt, the right feedback at the right time, a UI, better tooling around the tools, multiple agents. He calls all of it "practical engineering and elbow grease" with no moments of genius.
That cuts two ways, and he means both. For people sizing up agent products, the loop is not a moat, so judge them on the polish, the tools and the feedback, and expect a lot of capability to come from the model whoever built the wrapper. For engineers, the barrier to building your own is gone, and he wants you to find that out by doing it rather than by taking his word for it. That is why he keeps insisting you type the code. The note's last line is "That’s why we think everything’s changing."
The reaction surprised him. In Joy & Curiosity #36, published five days later, he reports nearly 1M views and thousands of likes, and calls the reactions the biggest surprise of the week. A tutorial that mostly says "this is easy" landed because most readers had been waiting for the catch the note never delivers.
What the podcast had already said
The note says this is "what we’ve been saying on the podcast" from the start, and the first episode of Raising an Agent (March 6, 2025, about six weeks earlier) shows that it was. At 6:33 the hosts break an agent into three pieces: the tools, the model, and the wiring that joins them. The answer is that the wiring is the easy part, since they reached a working prototype in roughly two weeks. Right after, one of them describes being surprised that once you give Claude some tools there is little else to do. The example is an edit call that failed twice, after which the model wrote the content to a new file and moved it over the old one with a terminal command. That prototype had a terminal tool and a system prompt. The note's agent has neither, which is how it shows that the minimum is smaller still.
The episode also names what the minimal version leaves out. At 10:43, past "the tools of course, the model of course", the hosts single out giving the agent the right feedback at the right time, such as compiler errors, test results and diagnostics, as the part that has to be got right. The same phrase turns up in the note's list of things Amp adds on top. The note and the podcast make one argument: the loop is trivial, and the quality lives in what you feed back into it.
Five months after the note, Quinn and Thorsten took the same framing onto Latent Space. The episode is titled Amp: The Emperor Has No Clothes and is listed on his podcasts page under 25 Sep 2025. The title reuses the note's subtitle, so by then the phrase had become a shorthand for Amp's whole position.
Is there a companion repo?
We found no official repository of the Go code under github.com/mrnugget or github.com/ampcode as of November 2026, and the note itself links none. That fits its insistence that you type the code yourself. The nearest thing he published is agent-openai-gpt-oss-20b, a small Rust agent for OpenAI's open-weight gpt-oss-20b running locally, whose README says it is based on How to Build an Agent. In Joy & Curiosity #49 (August 2025) he says Amp wrote it from the post and he didn't write a line by hand. That makes a neat test of the thesis: an agent rebuilt a working copy of the minimal agent from its own tutorial.
Try it
- Build the chat loop and test the statelessness. Create a Go module, add anthropic-sdk-go, write Run() and runInference() from the note, and talk to it. Then print len(conversation) each turn, or restart the program, and watch the memory disappear. If the SDK has moved on since April 2025, swap in a current model constant.
- Add read_file with the old loop first. Register the tool but keep the stage-one Run(), ask what is in a file, and see Claude announce a read that never happens. Then add the tool_use branch and the readUserInput flag. The difference between those two runs is the whole lesson.
- Add list_files and edit_file, then ask for a multi-step task. "Create fizzbuzz.js and make it run with Node" or "what Go version is this project on?" Count the model calls per human turn: that count is the agent working on its own.
- Find your own elbow grease. Make edit_file reject an old_str that matches more than once, return a useful error, and watch the model recover. Or add a tool that runs a command and feeds back compiler output, which is the feedback the podcast says matters most.