From a language model to an agent
In Chapter 1 we hit the model's hard limit: it's a stateless function that turns text into more text and nothing else. It can't read a database, run code, or send an email. So how do we get from "autocomplete" to systems that fix codebases and resolve support tickets? We wrap the model in a loop and hand it tools. That's an agent — and by the end of this chapter you'll have stepped through one by hand and seen exactly how a text model "does things."
1 · What actually counts as an "agent"?
The word is thrown around loosely, so let's use the definition the labs use. OpenAI: an agent is a system that uses an LLM to control workflow execution — the model chooses the next step, notices when the task is done, self-corrects, and hands back to a human when stuck. Anthropic frames the same line as workflow vs agent: in a workflow, YOU wrote fixed code paths and the LLM just fills slots; in an agent, the LLM decides its own path and tool use at runtime. The whole distinction reduces to one question: who chooses what happens next — your code, or the model?
That boundary is slippery in practice, so test your intuition — click each system:
2 · The three parts of every agent
Strip any agent down and you find exactly three components. Keep this picture in your head for the rest of the book — every later complication (memory, RAG, guardrails) is an upgrade to one of these three.
Tools come in three practical kinds, and you'll design all three: data tools (read a DB, search the web, fetch a file), action tools (send email, issue a refund, open a PR), and orchestration tools (other agents, exposed as callable tools).
3 · The agent loop — step through it yourself
The engine is a loop, often called a run. Each turn the harness assembles context and calls the model; the model returns either a final answer or a tool call; if it's a tool call, your code executes it, appends the result, and loops. It exits on a final answer, an error, or a max-turn cap — Anthropic's shorthand: gather context → act → verify → repeat. Reading that is one thing; watching state accumulate is another. Step through a real run:
4 · Tool calling — the exact round-trip
This is the mechanism that lets a text model act, and the model's role is smaller than people think: it only ever emits an intention (structured JSON); your code does the doing. Watch the round-trip, then read the four steps:
Structured outputs — guarantee the JSON is valid
By default, tool arguments are best-effort: the model usually produces valid JSON, but "usually" breaks pipelines. Strict mode constrains generation to your schema so the output is always valid. Flip it and see:
5 · Design the tool interface like a product (ACI)
The model operates your system blind, through a keyhole of text. So the Agent–Computer Interface deserves as much care as a human UI: tools should be self-describing, hard to misuse, and fail loudly. This is error-proofing ("poka-yoke") — shape the signature so a mistake is nearly impossible. The same capability, designed two ways:
refund(amount, reason)
// amount: free string ("50", "$50", "fifty?")
// reason: free text
// no currency, no limit, no enumissue_refund(
order_id: string,
amount_cents: integer, // one unit
reason: enum[ "damaged",
"late", "wrong_item" ])The right column removes whole classes of model error: no ambiguous currency, no invented reasons, no unbounded amount. In practice, tightening tool schemas buys more reliability than any amount of prompt-tweaking.
6 · Start with one agent
A single model in a loop with well-designed tools solves a surprising share of real problems. Reach for multiple agents only when specialization removes a genuine bottleneck — because more agents is distributed-systems complexity, not maturity.
Anthropic's multi-agent setups beat a single agent on hard research tasks — but burn roughly 15× the tokens of a normal chat. Split work only to (1) protect context, (2) parallelize a wide search, or (3) use genuinely different tools/expertise. We'll build multi-agent systems properly in Chapter 4.
Recap
- An agent = model + tools + instructions, run in a loop the model controls (that's the agent-vs-not test).
- The model only reasons or emits tool calls; your harness executes and returns observations.
- Declare tools as JSON Schema; use strict mode; design the interface to be error-proof.
- Start single-agent — multi-agent costs ~15× tokens.
You have the loop. Next: what happens inside each turn — the reasoning patterns (CoT, ReAct, Reflection, Tree-of-Thoughts) that decide how well the agent plans, acts, and recovers.