AI Agents from first principles
Published
Your bar: reconstruct the entire stack on a whiteboard from memory — to tell real capability from hype in pitches and reviews. So every level is built to be seen and redrawn, not read. Grounded in Anthropic’s Building effective agents 1 and the MCP spec. 3
One sentence holds the whole lesson. Each level just unpacks one chip of it:
An AI agent is a stateless text-prediction function
wrapped in a loop
given tools and a goal
run by ordinary code
LLM — the brain in a jar
The only irreducible primitive. Everything else is plumbing around it.
f(text) → text. A pure function: same call type, no side effects, nothing
retained.
Is A stateless function: text in → predicted text out.
Why it exists Turn fuzzy natural-language intent into output with no hand-coded rules.
Like (world) A genius consultant who read the whole internet but has total amnesia — and can only talk.
Like (code) A pure POST /predict endpoint. A Lambda with no DB. RAM,
no disk.
🧠 Memory rule: An LLM is a stateless text-prediction function — brain in a jar, no memory, no hands.
Memory check
- What three things can an LLM not do alone? → remember, act, retain state
- If it's stateless, how does a chatbot seem to remember? → the app resends the transcript
- Closest SWE primitive? → a pure stateless endpoint, not a database
Tool & Tool calling — giving the brain hands
Two ideas, one critical line: the model requests; your code runs.
Is A function the model may request (name + param schema); calling = it asks, runtime executes.
Why it exists Bridge text-prediction to real side effects — read a DB, hit an API, send mail — while keeping the model sandboxed.
Like (world) The amnesiac writes a work order; a runner does it and brings back the result.
Like (code) An API endpoint with an OpenAPI schema; the model emits a typed RPC your dispatcher routes.
🛠️ Memory rule: A tool is a typed function the model may request but never run; calling is the model asking, your runtime doing.
Memory check
- Who executes a tool call? → the runtime, never the model
- What two things define a tool? → a name and a parameter schema
- Why is "the LLM ran the SQL" wrong? → it only requested; code ran it
Agent — brain + hands + a goal
What you get when you let the model drive many tool calls toward an objective.
Is An LLM in a loop with tools + a goal; the model chooses which tools, in what order, until done.
Why it exists You can’t pre-script open-ended work; steps depend on results. The agent decides the path at runtime.
Like (world) A capable employee handed an objective and systems access — no script.
Like (code) A long-running worker that orchestrates service calls dynamically, not a fixed cron job.
🤖 Memory rule: Agent = LLM + Tools + Loop + Goal — the model picks the path, the loop keeps it moving.
Memory check
- Four ingredients of an agent? → LLM, tools, loop, goal
- Is it a better brain than an LLM? → no; structure was added, not IQ
- Why not hardcode the dispute steps? → the path depends on what you find
Agent loop — Observe → Think → Act → Repeat
The heartbeat of every agent. You already run this loop in production.
Is Observe state → Think (LLM picks next step) → Act (tool) → observe → repeat, until goal or limit.
Why it exists The next action depends on the last result — you must react, not pre-plan.
Like (world) Debugging an outage: symptom → hypothesis → try one thing → observe → adjust.
Like (code) A K8s reconciliation loop / a REPL / an event loop.
🔁 Memory rule: The agent loop is a reconciliation loop for intent: observe, think, act, repeat until desired state.
Memory check
- Four phases in order? → observe, think, act, repeat
- Where does the loop live? → in the runtime code, not the model
- What plays "desired state"? → the goal
Agent runtime — the app server around the brain
Plain code that hosts the loop. The layer leaders skip — and where reliability lives.
Is The program running the loop: holds state, calls the LLM, runs tools, enforces guardrails.
Why it exists The stateless LLM can’t host a loop or stop itself; something must — and it’s code you own.
Like (world) The office around the employee: building, phones, badges, the manager who says “stop”.
Like (code) Laravel + web server + queue worker. Claude Code, Cursor, the Agent SDK are runtimes. 4
⚙️ Memory rule: The runtime is the app server hosting the loop — it holds state, runs tools, and enforces the guardrails the model can’t.
Memory check
- Three runtime jobs the LLM can't do? → hold state, run tools, enforce limits
- Laravel analogy mapping? → LLM = logic fn, runtime = framework+server+worker
- Agent loops forever — which layer failed? → the runtime (no max-steps)
Memory — because the brain forgets everything
Not a model feature — a runtime discipline. It’s just what gets re-injected.
SELECT pasted
into the prompt.
Is Whatever the runtime puts back into the prompt. Short-term = context window; long-term = external store.
Why it exists The model forgets between calls and the window is finite; relevant info must be re-injected.
Like (world) The employee’s notebook (today) + the company wiki (looked up on demand).
Like (code) Stateless HTTP + sessions + DB. Context = RAM payload; store = disk; RAG = a query injecting rows.
💾 Memory rule: The model is stateless; memory is what the runtime reloads into the prompt — context is RAM, the store is disk.
Memory check
- Short-term vs long-term? → context window vs database
- Why isn't a bigger window "more memory"? → still volatile, re-sent each call
- RAG in one backend line? → a query that pastes rows into the prompt
Workflow vs Agent — who writes the if/else?
The most important decision in the stack — and the one VPs over-engineer.
if/else you wrote · Agent = the if/else the model writes
at runtime.
| Dimension | Workflow | Agent |
|---|---|---|
| Controls flow | You (developer) | The model, at runtime |
| Predictability | High | Lower (path emerges) |
| Cost / latency | Low | Higher (many LLM calls) |
| Debuggability | Easy (fixed paths) | Harder (per-run traces) |
| Best for | Known, repeatable tasks | Open-ended, unpredictable tasks |
Agentic workflow = the middle: a fixed workflow with a few model-decided steps (a runbook with “use your judgment here”).
✓ Anthropic: start simple, use workflows, reach for agents only when flexibility pays 1
🧭 Memory rule: Workflow = you write the if/else; Agent = the model writes it; choose by how predictable the path is.
Memory check
- Who writes the control flow in each? → developer vs model
- What does a workflow buy you? → predictability, low cost, easy debugging
- Safe default, and why? → workflow; agents add cost + unpredictability
MCP — USB-C for tools
One standard so you don’t hand-write glue for every external system.
MCP An open standard to discover & call tools/data from external systems. “USB-C for AI.” 3
Why it exists Kills the N×M bespoke-glue mess: expose a server once, any MCP agent uses it → N+M.
Server / Client Server = exposes tools (device). Client = connects from the host app (port).
Tool registry The catalog advertised to the model = service discovery for tools.
✗ “MCP is a Claude feature / MCP is the tool”
✓ Open multi-vendor standard; it’s the protocol to reach tools (≈ JDBC)
🔌 Memory rule: MCP is USB-C for tools — server = device, client = port, registry = catalog of what’s plugged in.
Memory check
- MCP turns N×M into ___? → N+M
- Agent vs GitHub integration — which is which? → agent=client, GitHub=server
- Is a tool the same as MCP? → no; MCP is the protocol to reach tools
Single vs Multi-agent — monolith vs microservices
The same architecture call you’ve made a hundred times for services.
Single One loop, one context, one tool registry, end to end. The monolith.
Multi Orchestrator plans & delegates to worker subagents (own context+tools), then synthesizes.
Like (code) Monolith vs microservices / map-reduce. Orchestrator = the dispatcher.
The cost Coordination, latency, partial failure, observability — and ~15× tokens.
✓ Premature-microservices trap; split only when one context/role can’t cope
🧩 Memory rule: Single agent is a monolith; multi-agent is microservices — split only when one context/role can’t cope.
Memory check
- Map both to an architecture you use daily. → monolith vs microservices
- Orchestrator vs subagent? → plans/delegates vs scoped worker
- The cost of multi-agent? → coordination + ~15× tokens
Archetypes — one engine, many job descriptions
The payoff: every “AI agent product” is the same engine + a different toolset + a different prompt.
👔 Memory rule: Every archetype is the same engine + a different tool registry
- a different job description.
Memory check
- What changes vs stays between a coding and a billing agent? → tools+prompt change; engine same
- SRE loop in four words? → observe, diagnose, remediate, verify
- Three questions that cut through a pitch? → what tools? what loop? what guardrails?
Where each layer shows up — real use cases
Grounding for your hype filter: the concept, a concrete place it’s used, and the shape it usually takes (workflow / agent / infra).
| Concept | Real use case | Usual shape |
|---|---|---|
| LLM | Classify a ticket’s intent · draft a reply · summarise a PR | single call |
| Tool calling | ”Book 30 min with Sam Thursday” → model calls the calendar API | workflow / agent |
| Agent | Claude Code fixes a failing test across several files on its own | agent |
| Agent loop | Coding agent: edit → run tests → read failure → fix, until green | agent |
| Runtime | Claude Code · Cursor · the Agent SDK — the harness hosting the loop | infra |
| Memory | Support bot recalls a customer’s past tickets via RAG over the help centre | workflow + store |
| Workflow vs agent | Fixed “RAG Q&A over docs” pipeline vs open-ended “research this market” | both |
| MCP | Connect the agent to GitHub, Slack, and Postgres via MCP servers | integration |
| Single vs multi | One triage agent vs a “deep research” lead + parallel subagents | single / multi |
| Archetypes | SWE copilot · support copilot · SRE on-call copilot · billing automation | agent |
Pattern to notice: most shipped value is a workflow with one or two tool calls; the loud demos are full agents. Your job in a review is to tell which one a pitch actually needs. 1
Retrieval practice — mix the levels
Reading builds fluency (feels familiar). Recall builds storage (lasts). Answer from memory — instant feedback.
Q1. Who executes a tool call?
Q2. "The model remembers our last message" is wrong because…
Q3. The difference between a workflow and an agent is…
Q4. MCP exists primarily to…
Q5. The agent loop is best compared to…
Q6. Single vs multi-agent maps cleanly onto…
Reconstruct the stack from a blank page
Write the ten levels in order, one line each, with nothing on screen. Then reveal and compare — gaps are your next drill.
1 LLM stateless text→text · 2 Tool: model requests, runtime runs · 3 Agent = LLM+tools+loop+goal ·4 Loop: observe→think→act→repeat · 5 Runtime: app server + guardrails · 6 Memory: runtime reloads (RAM vs disk) ·7 Workflow vs Agent: who writes the if/else · 8 MCP: USB-C; server/client/registry; N×M→N+M · 9 Single vs Multi: monolith vs microservices · 10 Archetypes: same engine + different tools + job.
I’m your teacher — ask me anything. Say “grill me on the agent stack” for mixed no-clue questions, or drop a real product and I’ll place it on the workflow↔agent & single↔multi spectrums with you. Want the next lesson — spaced, interleaved drills? Just ask.
Interview — pick your bar
Answer out loud in ~60s, then reveal. Core = recall · Senior = trade-offs & failure modes · Staff = synthesis under ambiguity · System Design = open design round (a different axis, not a harder level).
What is an LLM, and what are the three things it can't do on its own?
f(text) → text, the reasoning model, the brain → it can't remember between calls, can't act on the world, and holds no state → a chatbot only "remembers" because the runtime re-sends the transcript every call.Walk me through exactly what happens when an agent "uses a tool".
Define an agent and its agent loop.
What is the agent runtime, and what is memory in this stack?
When would you NOT build an agent, and ship a workflow instead? Name the trade-off.
Your agent occasionally loops forever and burns huge cost. Where do you fix it, and why is it not "the model"?
A team wants to add a second agent to "go faster." Talk them into it — or out of it.
Explain MCP to a skeptical exec in one analogy, and name the problem it solves.
A vendor pitches "fully autonomous agentic AI." Place it on the workflow↔agent spectrum and name the trade-off the pitch bought.
How does a "coding agent" differ from a "support agent" architecturally — and what does that tell you about every agent product?
Build vs buy: a team wants to adopt an off-the-shelf agent runtime/SDK instead of writing their own loop. How do you reason about it?
- Goal & scope — what the agent is responsible for, and the explicit line where it must escalate to a human.
- Tools — the callable capabilities it needs (read vs write), each with a scoped permission boundary.
- Loop & runtime — observe→decide→act, with max-steps, timeouts, and token budgets in the runtime.
- Guardrails — approval thresholds, idempotency on writes, dry-run/rollback, and hard limits on destructive actions.
- Memory — per-task short-term context plus what's persisted to an external store and retrieved back.
- Workflow vs agent — script the common path, keep an agent escape-hatch only for the messy cases.
- Observability & eval — per-run traces, an audit log of every action, and how you'd measure success/regressions.
Design a support agent that's safe to ship for a SaaS billing product.
Design an SRE incident-triage agent. What can it touch, and where does it stop?
★ Cheat sheet — buzzword → engineering
Mental models: LLM = brain · Tool = hands · Agent = brain+hands+loop+goal · Runtime = the app server · Memory = what’s reloaded · Workflow = you choose the path · Agent = the model chooses · MCP = USB-C for tools · Single = monolith · Multi = microservices.
Translation table
| Buzzword | What it actually is |
|---|---|
| Agentic / autonomous AI | An LLM in a while-loop with tools + a goal |
| Function calling / tools | Typed RPC the model requests, you execute |
| Orchestration framework | The runtime (app server for the loop) |
| Context window | Bounded RAM, re-sent every call |
| Memory / RAG | External store + a query injecting text into the prompt |
| Workflow / chain | A hardcoded pipeline / DAG you wrote |
| MCP | Standard tool interface (USB-C / JDBC); N×M → N+M |
| Multi-agent / swarm | Orchestrator-worker microservices for agents |
| Copilot / AI teammate | An archetype: the engine + one role’s toolset |
Three rules for the VP chair
① Default to workflows; agents only when the path can’t be predetermined. ② Start single-agent; split like microservices — with evidence. ③ Judge any pitch by: what tools? what loop? what guardrails?
📄 Full printable version → agents-cheat-sheet.html
★ Review guides & what to read next
5-min (weekly) Don’t re-read — recall. Say the one sentence; redraw the request path
- the loop from memory; recite the ten rules; translate three buzzwords blind.
30-min (when stalled) Blank-page reconstruct all ten levels; re-derive why each layer forces the next; then place one real product (workflow/agent? single/multi? which archetype? which tools?).
Read next, in order:①
Building effective agents — Anthropic
(Levels 1–7, read first) · ② Model Context Protocol docs (Level 8) · ③
Multi-agent research system — Anthropic
(Level 9) · ④ Claude Agent SDK (the loop as code). Full list → Resources.
📖 Primary source:
“Building effective agents” — Anthropic Engineering
— the highest-trust grounding for this lesson.
These notes reflect my current understanding and are updated as I learn, build, and discover better explanations.