Agents
Models that take actions: tools, loops, memory, multi-agent systems and keeping them safe.
Sections
Interview questions answered at staff level
Agent fundamentals
What makes something an agent, tool use, the agent loop, and when a workflow is better.
10 questions02Agents in production
Reliability, cost, evaluation, security and human oversight for agents that run for real.
10 questionsRead first
Blog posts for this volume, easiest first
What is an AI agent, really?
A chatbot tells you how; an AI agent goes and does it, deciding each next step from what it just found. A plain-English tour of the loop, the tools, and why limits are part of the design.
Build your first tool-using agent (offline, in pure Python)
A minimal agent loop that speaks the real Messages API shape: tool calls linked to results by id, several calls per turn, argument validation that does not swallow your bugs, a step budget, pytest, and the same loop against Claude.
Workflows before agents: pick the simplest pattern that works
Seven patterns from Anthropic’s taxonomy, from one call to a fully autonomous AI agent, with the cost and latency spread of each and the failure that justifies climbing to the next.
Securing agents: assume the model will be fooled
Prompt injection has no reliable filter, so agent security is architecture: break the lethal trifecta, constrain what a fooled model can do, and test it like any other regression.
Build your first MCP server
What the Model Context Protocol actually standardises, a 30-line Python server with one tool and one resource, how to plug it into a client, and the security rules that matter before anyone else installs it.
Tool design for agents: the interface is the product
Names, schemas, error messages the model can act on, pagination, idempotency keys and confirmation for side effects, with runnable examples of a bad tool, a good one and an idempotent write.
Durable agents: checkpoints, idempotent tools and approvals that wait for days
An agent run is a long-lived workflow that will be interrupted. How to checkpoint each step, make every side effect safe to replay, resume at step 7 after a crash, and park a run for a human without holding a worker, with a runnable stdlib example.
Key terms
31 pages with diagrams and quizzes
An AI that is allowed to act, not just write: it picks a tool, reads the result, picks again — until the goal is met or a limit stops it.
In a workflow, you write the steps and the model fills them in. In an agent, the model picks the steps. Predictability versus flexibility.
The model asks for something it can't do alone — 'call get_order_status with order 48213' — and your code decides whether to actually do it.
The cycle at the heart of every agent: the model decides, your code runs a tool, the result goes back in, repeat — until done or stopped.
Having the agent write out its steps before acting — and rewrite them when a result contradicts the plan.
The model reviews its own work and tries again. Works well when the review has something real to check against — tests, a validator — and much less without.
A fixed sequence of model calls, each feeding the next, with your own checks between the steps.
Several agents with their own contexts, instructions and tools working one task. Strong for parallel breadth, and roughly 15× the tokens of a chat.
One model looks at the task, decides what pieces are needed, farms them out to workers, and merges what comes back.
One agent passes a task to another — or to a person — with a structured briefing, and the tools and permissions change with it.
Model Context Protocol: an open standard for plugging tools and data into AI apps. Rather like USB, but for AI.
How an agent keeps anything beyond one request: working memory in the context, plus a long-term store it writes to and searches later.
Deciding exactly what goes into the model's context at each step — and what stays out — to get the most signal per token.
An agent working a screen the way a person does — look at a screenshot, click, type, repeat. The fallback when there is no API.
A walled-off space where an agent's code and actions run, with only the files, network and credentials it genuinely needs.
Checks around a model or agent that block, fix or escalate unsafe inputs, outputs and actions — layered, with the important ones in code.
A person reviews, approves or corrects the AI's work at chosen moments — usually just before anything irreversible.
The rules that end an agent's run: task done, or a cap on turns, tokens, time, spend, repeats or errors — each logged with a reason.
Running agent workflows so progress is saved step by step, and a crash, a deploy or a two-day wait doesn't redo what already happened.
Judging an agent's whole path — which tools, in what order, how safely, how cheaply — and not just whether the final answer was right.
Designing an agent's tools — names, descriptions, inputs, outputs, errors — so the model picks the right one and uses it well.
What a run costs in tokens, money and time. Because the whole history is re-sent each turn, it grows faster than you'd guess.
Serving many customers from shared infrastructure while keeping their data, quotas and performance apart. How far you isolate is a cost-versus-risk call.
One customer's heavy load — a bulk import, a runaway agent — making everyone else on the same infrastructure slow.
Who is allowed to see a document. In RAG this has to be checked while searching, or the model will quote files the user cannot open.
If you cannot confirm something is allowed, treat it as not allowed. Fail-open is the opposite: keep serving and skip the check.
Text the model reads as instructions — typed by a user, or hidden in a page, email or document an agent fetches. No filter fully fixes it.
Getting data out of a system without permission. For agents: a tool call, a fetched URL, or a rendered image whose address carries the data.
Give every user, service and agent only the permissions this task needs, only for as long as it needs them.
How much breaks when one thing fails: how many users, customers, records or actions. Keep it small and known.
Stacking independent safeguards so that one failing — and each will, sometimes — is not the whole story.