This book is licensed for the personal use of the buyer. Please do not share or resell the file. Short quotations with attribution are welcome.
The information in this book is provided for education. It is not legal, financial or other professional advice. Product and company names are used only to describe them and belong to their owners.
This is a free sample: the introduction and first chapter.
IntroductionIntroduction
A chatbot answers. An agent acts. Ask an agent to "find the three invoices that are overdue, draft reminder emails and put them in my outbox for review", and it decides which steps to take, calls tools to search the accounting system and the email client, inspects what comes back, recovers when something fails, and stops when the job is done.
That shift from producing text to taking actions is powerful. It is also where most of the new risk lives. An agent that misreads an instruction does not just write a wrong sentence; it may send the wrong email, delete the wrong file, spend money, or loop for an hour accumulating costs. Text that the agent reads along the way, from web pages, documents or emails, may even try to steer it.
This book is a practical design guide for building agents that are genuinely useful and safely bounded. It assumes you are comfortable with language models and basic programming, and uses language-neutral pseudocode.
Chapter 1 defines agents precisely and helps you decide whether you need one.
Chapters 2–5 cover the core mechanics: tools, the agent loop, planning and memory.
Chapters 6 to 8 widen the design space: workflows and state machines, systems of several agents, and agents that operate computers and browsers.
Chapters 9 and 10 are about safety: guardrails and human oversight, then a worked threat model for a realistic agent.
Chapters 11 and 12 cover testing and monitoring, and the arithmetic of cost, latency and reliability.
Chapter 13 follows a complete case study, an invoice-chasing assistant, from first idea to steady operation.
Chapters 14 and 15 cover coding agents, the most mature use today, and the organisational side of introducing agents to a team.
Chapter 16 offers durable criteria for choosing models, frameworks and tool protocols.
Chapter 17 collects proven patterns, and the warning signs that a simpler design would serve you better.
A design review worksheet, exercises with answers and a glossary close the book.
Chapter 1What Makes Something an Agent
A spectrum, not a switch
It helps to think of AI systems on a spectrum of autonomy:
Level
Description
Example
0. Single call
One prompt, one response
Summarise this document
1. Fixed workflow
Code calls the model in predefined steps
Extract fields → validate → write to database
2. Router
The model chooses one of several predefined paths
Classify a ticket and send it to the right workflow
3. Tool-using agent
The model decides which tools to call, in what order, how many times
Research a question across search, documents and a calculator
4. Long-running autonomous agent
Works for long periods on open-ended goals, with many tools
Investigate and fix a software bug across a codebase
The defining feature of an agent (levels 3–4) is that the model controls the flow: it decides the next step based on what it has observed so far. In a workflow, your code controls the flow.
The essential ingredients
A model capable of reasoning about goals and tool results.
Tools: functions the model can request, which your code executes.
A loop that feeds tool results back to the model until it finishes.
Instructions: the goal, constraints and policies.
State and memory: what has been done so far, and what persists.
Guardrails: limits on what can happen, and when a human must approve.
Do you need an agent?
Agents pay off when the path to the goal genuinely varies from case to case, and when steps depend on information discovered along the way. They are a poor fit when the steps are known in advance, since a fixed workflow is cheaper, faster, more predictable and easier to test.
Ask:
Could I write the steps as a flowchart that covers 90% of cases? → Build a workflow, with a model inside particular steps.
Do the steps depend heavily on what is found along the way? → An agent may be justified.
What is the worst action the system could take, and how would we undo it? → This determines how many guardrails you need before anything else.
You have reached the end of the free sample. The full book continues with 16 more chapters, plus everything else in its 81 pages.