Key ideas
- The one idea — An agent is so simple you can build one in ~30 lines: define a couple of tools, write a system prompt, then loop — send the model the goal + history, parse its reply, run any tool call, append the result, repeat until it emits a final answer.
- How it is shown — The tiny skeleton assembled live: tools as plain functions + descriptions; a system prompt with the rules; a while-loop of send → parse → execute → append.
- The trap to avoid — Thinking agent frameworks do something fundamentally deeper — they add ergonomics (parsing, retries, tracing, memory), but the core is this 30-line loop.
- What it sets up — Your agent works — now give it real tools and the open internet, and new dangers appear.
Strip away every agent framework and the core that's left is about thirty lines: a couple of tools, a system prompt, a loop. Let's build it.
The one idea
An agent is so simple you can build one in ~30 lines: define a couple of tools, write a system prompt, then loop — send the model the goal + history, parse its reply, run any tool call, append the result, repeat until it emits a final answer.
You've learned the loop, tool calling, planning, self-checks, and failure modes. Now the payoff, and it's a satisfying one: you can build a working agent in about thirty lines of code. Not a framework, not magic — a short loop wrapped around a model call. Let's walk through the whole skeleton, piece by piece. Start with tools. Pick a couple of plain functions — a calculator, a web search — ordinary code you could write any day. For each, write a short description: what it does and what arguments it takes. That description is the text you'll show the model, so it knows the tool exists and how to call it. Nothing fancy yet — just functions with labels. Next, the system prompt — the rules. You tell the model: here are your tools; to use one, output a JSON action with a name and arguments; when you're finished, output a final answer instead. This is the roles idea and structured output from earlier acts, put to work in a single short paragraph. The prompt defines how the model talks to your code.
How it works — the demo
The tiny skeleton assembled live: tools as plain functions + descriptions; a system prompt with the rules; a while-loop of send → parse → execute → append.
Now the loop itself, the heart of it. Send the model the goal plus the history so far. Read its reply. If it's a tool call, run that tool, append the result to the history as a new message, and loop again. If it's a final answer, stop and return it. That branch — tool call or answer — is the entire engine. Watch what flows around that loop. String in — the conversation. String out — the model's reply. Parse it: is this a tool call or an answer? Execute the tool. Append the result. Repeat.
The trap to avoid
Thinking agent frameworks do something fundamentally deeper — they add ergonomics (parsing, retries, tracing, memory), but the core is this 30-line loop.
Why it matters — and what’s next
Your agent works — now give it real tools and the open internet, and new dangers appear.
Every idea from this act — think, act, observe — is just those five plain steps running in a while-loop. There is nothing hidden in the gaps. And that's the whole thing — roughly thirty lines wrapped around one model API call. The agent is the loop you wrote; the intelligence is the model inside it. There's no hidden machinery, no secret sauce. When you truly get that the entire thing is this small, agents stop being mysterious and become something you can actually build yourself. The trap: assuming the big agent frameworks do something fundamentally deeper. They don't — they add ergonomics: parsing, retries, tracing, memory, hundreds of tools. Useful, but the core is this thirty-line loop. Your agent works. Now give it real tools and the open internet, and new dangers appear. Next: prompt injection.
This is one short episode in AI: Zero → Frontier, a step-by-step climb through how AI actually works. Each episode builds only on the ones before it.
Full transcript 3:00 of narration
You've learned the loop, tool calling, planning, self-checks, and failure modes. Now the payoff, and it's a satisfying one: you can build a working agent in about thirty lines of code. Not a framework, not magic — a short loop wrapped around a model call. Let's walk through the whole skeleton, piece by piece.
Start with tools. Pick a couple of plain functions — a calculator, a web search — ordinary code you could write any day. For each, write a short description: what it does and what arguments it takes. That description is the text you'll show the model, so it knows the tool exists and how to call it. Nothing fancy yet — just functions with labels.
Next, the system prompt — the rules. You tell the model: here are your tools; to use one, output a JSON action with a name and arguments; when you're finished, output a final answer instead. This is the roles idea and structured output from earlier acts, put to work in a single short paragraph. The prompt defines how the model talks to your code.
Now the loop itself, the heart of it. Send the model the goal plus the history so far. Read its reply. If it's a tool call, run that tool, append the result to the history as a new message, and loop again. If it's a final answer, stop and return it. That branch — tool call or answer — is the entire engine.
Watch what flows around that loop. String in — the conversation. String out — the model's reply. Parse it: is this a tool call or an answer? Execute the tool. Append the result. Repeat. Every idea from this act — think, act, observe — is just those five plain steps running in a while-loop. There is nothing hidden in the gaps.
And that's the whole thing — roughly thirty lines wrapped around one model API call. The agent is the loop you wrote; the intelligence is the model inside it. There's no hidden machinery, no secret sauce. When you truly get that the entire thing is this small, agents stop being mysterious and become something you can actually build yourself.
The trap: assuming the big agent frameworks do something fundamentally deeper. They don't — they add ergonomics: parsing, retries, tracing, memory, hundreds of tools. Useful, but the core is this thirty-line loop. Your agent works. Now give it real tools and the open internet, and new dangers appear. Next: prompt injection.