Engineering AI Agents
How to build an agent you can trust when you did not see every step
134 short video lessons, with the full text, quizzes and runnable notebooks, on building an agent you can trust when you did not see every step. Patterns, not one product's settings, so it stays useful as the tools change.
Minimum price
$149
$199
You pay
Author earns
About
About the Course
An agent is a program that decides its own next step. It looks something up, calls a tool, reads the result and decides again, until the job is done or it gives up. That is what makes it useful, and it is also the problem: by the end of a run you have not seen most of what it did. So the question this course keeps asking is a practical one. I didn't see every step, so how much of this can I trust?
The answer is never the model's own word for it. A model sounds just as sure when it is wrong as when it is right, so trust has to come from a signal outside it: a test that passes, output that matches a schema, a citation you can open, a trace you can read, a person who signs off. Each module builds one more of those signals into the agent you are designing.
The course runs in four stretches. First you understand what an agent is and the engine at its center. Then you build one: planning, tools, context, retrieval, memory, workflows, several agents working together. Then you learn to trust it, by observing it, evaluating it, securing it and making it reliable. Finally you run it: cost, speed, deployment, and the same patterns applied to coding, classification, research and business work.
It is written for engineers who build software but are not machine-learning specialists. You need to read code and be comfortable running it. You do not need a background in how models are trained. Every idea is taught as a pattern, not as one product's settings, so it stays useful as the tools change.
The first module is free to watch: module 1 on YouTube, eight lessons. The rest of the course, the written lessons, the quizzes and the notebooks come with the course.
What you get
- 134 short video lessons, 7.7 hours in all, each with English captions.
- The full text of every lesson, with every slide, for reading instead of watching.
- A quiz at the end of each module, 134 questions in all, and a certificate of completion.
- A notebook for each module: short explanations and code you run one step at a time, predicting what each step will do before you run it.
- For most modules, a build handout with a starter and automatic checks, for when you would rather write the code yourself or hand it to a coding agent.
What you will be able to do
- Tell an agent from a chatbot or a workflow by who owns the control flow, and decide whether a task needs an agent at all.
- Work out how reliable a whole run is from the reliability of each step, and which of three levers to pull when the number is too low.
- Design tools, descriptions and error messages a model can use without help, and give it the right context at each step: what to write down, select, compress and keep apart.
- Choose between retrieval, a long context and fine-tuning, and between a chain, branches, parallel calls and a loop.
- Decide when to split work between several agents, and where a person must sign off.
- Trace a failing run back to its first wrong step, and keep the fix as a test.
- Build an evaluation set from real failures, put an interval on a pass rate, and calibrate a model that grades other models.
- Audit a design for the combination that lets an attacker steal data, and cut it.
- Make a run survive retries, crashes and restarts without doing anything twice.
- Estimate what a run costs and how long it takes, and roll a change out safely.
The course stands on its own. If you want the same ideas in depth on the page, they are in the book AI Agents, Engineered.
Instructor
About the Instructor
Enrique Gutiérrez is an Associate Professor in the Department of Applied Mathematics for ICT at the Universidad Politécnica de Madrid (UPM) and a research affiliate at the Massachusetts Institute of Technology (MIT). He works on natural language processing, algorithm design, and AI agents. His recent work turns large language models into dependable instruments: agents that classify and score real-world language, including clinical text, using explicit rubrics, carefully chosen examples, and outputs that can be checked rather than merely trusted. That habit of asking *what signal verifies this system?* before granting it autonomy is the thread that runs through this book. He writes for engineers who want to build with agents without either the hype or the dread.
The book's companion site, with free interactive tools, the glossary and the first chapters to read online, is at https://aiagentsengineered.com
Material
Course Material
1.1 The question this course is about
Four things you will be able to do
Two halves that meet at the end
1.2 What an agent is
“Agent” is used for both of these
Who picks the next step?
Fluency was never the missing piece
Sources
1.3 Chatbot, workflow, agent
Which one is the agent?
Who decides what happens next?
Drawn before, or only after?
The augmented LLM
A dial, not three boxes
This module’s notebook
Sources
1.4 The compass, and why reliability multiplies
Four bearings
One design fork per bearing
Reliability multiplies
1.5 Do you even need an agent?
Do you even need an agent?
Workflow or agent?
Should this be an agent?
This module’s notebook
1.6 The engine underneath
Three questions about the engine
“The capital of France is ___”
The model’s world has a grain
Training and inference
1.7 The desk, the dice, and why identical runs differ
Everything has to fit on one desk
By default, the model rolls dice
Sources
1.8 What to keep, and what to try
Five things to keep
One experiment, and what comes next
Module 1 quiz
Quiz 1
2 attempts allowed
2.1 The engine goes to work
Now put it in a loop
Four things you will be able to do
Two halves that meet at the end
2.2 From text to a contract
From text to action
In an agent, no one types the final prompt
Three runs, three correct answers
Asking, or constrained decoding
2.3 The model proposes, your code disposes
Where does anything happen?
Name, description, argument shape
2.4 Six ways the engine fails
Hallucination: fluent, confident, wrong
The jagged frontier
Six failure modes, six remedies
Sources
2.5 Three levers against compounding error
Reliability multiplies: p n
Three levers
How reliable must each step be?
This module’s notebook
2.6 The loop
The loop
Four moves to a pass
It fits on an index card
Why one small step at a time?
Sources
2.7 A minimal agent from scratch
Four parts inside a harness
Everything becomes a result
Watch the history grow
2.8 Stopping, testing, and frameworks
Three exits, ranked by trust
Replace the model with a script
Shouldn’t I just use a framework?
2.9 What to keep, and what to try
Five things to keep
Run it yourself, and what comes next
This module’s notebook
Module 2 quiz
Quiz 2
2 attempts allowed
3.1 Building starts here
“Migrate this service off the old payments interface.”
Four things you will be able to do
Inside the model, then what it can reach
3.2 Turning a goal into steps
Planning, reasoning, self-correction
The list you would write on Monday
Interleaved, or plan-then-execute
Replan on surprise
Sources
3.3 How much planning?
What does a wrong step cost to undo?
3.4 Thinking is writing
Thinking is writing
Reasoning effort is a setting
Ask several times, take the majority
Sources
3.5 Can a model check its own work?
The answer has two columns
Sources
3.6 Let the world find, let the model fix
Finding is hard; fixing is easy
A ladder of checks
Sources
3.7 The action space
Tools and the action space
Your tools are everything your agent can ever do
Wrap the endpoints, or shape the task?
3.8 Every channel is a prompt
Too many tools confuse the model
Every channel is a prompt
Sources
3.9 Errors, retries, and programs built for agents
The most useful message a tool sends
Make explicit what a person used to supply
Assume every call will be retried
Lint seven flawed tools, then the repaired set
This module’s notebook
Sources
3.10 Code, and the screen
Discretion outside, determinism inside
Descend only as far as you are forced
Sources
3.11 What to keep, and what to try
Five things to keep
Run it yourself, and what comes next
This module’s notebook
Module 3 quiz
Quiz 3
2 attempts allowed
4.1 Every call succeeded
Every tool call succeeds
Four things you will be able to do
The workshop, then the desk
4.2 Expertise in a folder
Skills, protocols, and interoperability
A named folder of know-how
4.3 Loading in layers
A table of contents, then one section
The description decides whether it loads
4.4 Skills that earn their place
Three caveats
Shapes for what goes inside
Where good skills come from
This module’s notebook
Sources
4.5 Tool, protocol, or skill?
Tool, protocol, or skill
Which layer is missing?
4.6 From multiplication to addition
A multiplication becomes an addition
Two kinds of protocol
What a protocol costs
4.7 A fuller desk is a duller model
Managing the context window
Context engineering
Context rot
Sources
4.8 How a context fails
The soft limit
Name each failure
Five failures, and one test
Sources
4.9 Write, select, compress, isolate
Write, select, compress, isolate
What each one buys, and costs
All four in one run
Sources
4.10 What to keep, and what to try
Budget a desk
Five things to keep
Run it yourself, and what comes next
This module’s notebook
Module 4 quiz
Quiz 4
2 attempts allowed
5.1 A fact that was never fetched
Four things you will be able to do
A library, an office, and arrows
5.2 Look it up
Retrieval and knowledge
Look it up
Chunk, place, store; ask, fetch, answer
Sources
5.3 When the lookup misses
Five symptoms, five fixes
The agent can search again
5.4 Three roads to knowledge
Three ways to give a model knowledge
Choose the road
5.5 Nothing about yesterday
Memory: working state across long runs
Two lifetimes, three kinds
Sort five memories
Sources
5.6 Where memory waits
Three mornings
Hot, warm and cold
The life of one remembered thing
Sources
5.7 A long run, and a sealed room
Keeping a long run healthy
Quarantine: two doors
Quarantine, and its rule
5.8 A chain with gates
Workflows and composition patterns
Three overloads, three shapes
The gates are the pattern
What a gate can and cannot do
Sources
5.9 Branch, or fan out
The first step is a classifier
Split, or vote
Sources
5.10 The loop that points backward
The evaluator–optimizer loop
Four ways the loop fails
Sources
5.11 What to keep, and what to try
A support pipeline: chain, then branches
Five things to keep
Run it yourself, and what comes next
This module’s notebook
Module 5 quiz
Quiz 5
2 attempts allowed
6.1 Who writes the list?
The orchestrator–worker pattern
Four things you will be able to do
Split it, sign it, loop it, price it
Sources
6.2 A brief for a stranger
Several agents
One brief, three readings
The brief: four fields
Sources
6.3 The bugs live in the seams
Four seams, one rule
Sources
6.4 The merge wall, and one question
The merge wall
Past the merge wall
The verdict is a procedure
Sources
6.5 Signing limits
Oversight and autonomy
Which of the five wait for a signature?
Four consequence tiers
Sources
6.6 The gate lives in your code
An action at the gate
The gate lives in your code
Sources
6.7 Review the aim, and set the scale
Review the aim, not the lines
One scale, set per task
Sources
6.8 A line of shell, overnight
The outer loop
Three lessons from a line of shell
The goal function
Sources
6.9 Five verbs, and the brakes
Find, assign, check, record, decide
Two debts, five brakes
Sources
6.10 The cheapest thing that works
When not to build an agent
Four requests
The ladder, priced
Signs, both ways, and a trap
Sources
6.11 What to keep, and what to try
A gate policy, then a brief
Five things to keep
Run it yourself, and what comes next
This module’s notebook
Sources
Module 6 quiz
Quiz 6
2 attempts allowed
7.1 You cannot debug what you cannot see
Which one finds the bug?
Four things you will be able to do
See one run, watch all, replay, name
Sources
7.2 The flight recorder
Traces and spans
The trace is a flight recorder
A trace is a tree of spans
Sources
7.3 What every span carries
What every span carries
The rendered prompt
Testimony, a standard, and care
Sources
7.4 Green dashboards
Production monitoring
Drift is a trend; alert on trends
Three questions, and the tiles
Sample, distrust totals, read traces
Sources
7.5 It worked when I ran it again
Making a failure happen twice
Record and replay
Sources
7.6 Replay one call, and draw the seam
Replay one call
Test each side of the seam
Golden traces, and the limits
Sources
7.7 Six specimens
The bugs you will meet
Six specimens
Sources
7.8 The first wrong span
Which span is the bug?
Forward, to the first wrong span
The first wrong span
7.9 What to keep, and what to try
From trace to test
Four traces, the first wrong span
Five things to keep
Run it yourself, and what comes next
This module’s notebook
Module 7 quiz
Quiz 7
2 attempts allowed
8.1 The demo went well
Four things you will be able to do
Why, the set, the judge, the gate
Sources
8.2 Inspection gives way
Why evaluation is hard
Inspection gives way
Sources
8.3 Two honest numbers
pass@k, passᵏ and the envelope
Sources
8.4 Three runs and a criterion
Building an evaluation set
Three runs, read by hand
A criterion two experts agree on
Sources
8.5 The set, the state, and the ladder
The evaluation set
Grade the outcome, in the state
The grader ladder
Sources
8.6 How sure is a pass rate?
Read the failures
How sure is a pass rate?
Sources
8.7 A model grading a model
A model as the judge
A model grading a model
Two framings, four habits
Four ways a judge goes wrong
Sources
8.8 Calibrate it like an instrument
What accuracy hides
Calibrate it like an instrument
Sources
8.9 Every change reruns the suite
Every change, measured
Every change reruns the suite
Two suites
Sources
8.10 A gate that fails closed
A gate that fails closed
Offline and online
8.11 What to keep, and what to try
Measure the measurement
Five things to keep
Run it yourself, and what comes next
This module’s notebook
Module 8 quiz
Quiz 8
2 attempts allowed
9.1 Someone is making it happen
Four things you will be able to do
The way through this module
Sources
9.2 One stream, no boundary
Prompt injection
One stream, no boundary
Direct and indirect
Sources
9.3 The deputy, and the odds
A jailbreak is not an injection
The confused deputy
Every model-layer defense works on odds
Sources
9.4 Three legs, one theft
The lethal trifecta
Three legs, one theft
Egress is rarely a send button
Cut one leg; then the second audit
This module’s notebook
Sources
9.5 Checks that do not reason
Four families, by where they stand
9.6 Next to the side effect
Next to the side effect
A model as a guard, and the bill
9.7 Keys cut per errand
The blast radius
Three controls on the radius
The sandbox, and what “allow” means
Sources
9.8 Approval is scarce
Approval fatigue
Spend approval where a no is plausible
Sources
9.9 What you install
The supply chain
Two risks at once
Skills, settings, memory, and the discipline
Sources
9.10 What to keep, and what to try
Three passes over three designs
Five things to keep
Run it yourself, and what comes next
This module’s notebook
Module 9 quiz
Quiz 9
2 attempts allowed
10.1 The most common bad day
Four things you will be able to do
The way through this module
10.2 Show the model the failure
Failing well
Show the model the failure
Five classes, one mechanism each
10.3 Retry, and only so much
Backoff, jitter, one budget
10.4 Deadlines and the breaker
Every call gets a deadline
The circuit breaker
Price it by what it protects
10.5 Where the run lives
State and recovery
What a run carries
Two ways to checkpoint
10.6 Nothing twice
Keys and receipts
10.7 Sequences, and crashing on purpose
Sequences, approvals, the loop’s shape
Crash on purpose
10.8 Degrading honestly
Degrading honestly
The fallback ladder
Words degrade; deeds do not
An escalation a person can act on
10.9 The harness grid
The harness
Which harness is yours?
The harness grid
Sensors that speak, and the loop that grows them
What a harness cannot see
10.10 How much harness
A scaling rule, not a verdict
10.11 What to keep, and what to try
Break it on purpose, then map the harness
Six things to keep
Run it yourself, and what comes next
This module’s notebook
Module 10 quiz
Quiz 10
2 attempts allowed
11.1 Out of the room
Four things you will be able to do
The way through this module
11.2 The staircase
The invoice
The staircase
What the napkin leaves out
This module’s notebook
11.3 Yield, and five levers
Yield, not abstinence
Five levers
Sources
11.4 Stable first, variable last
Stable first, variable last
11.5 First token, last token
The clock, and the triangle
First token, last token
Is a person watching?
11.6 Where the seconds went
Where the seconds went
Pick two
With numbers, on purpose
11.7 Take a number
Serving strangers
The thirty-second wall
Take a number
11.8 A row, not a process
A row, not a process
Sandboxes by the thousand
11.9 The door
Two limits, one division
The door
11.10 The rollout ladder
The rollout ladder
Tuesday’s edit
Five rungs, a way down from each
The canary
A flag and one artifact
11.11 What to keep, and what to try
Price it, cache it, admit it, ship it
Five things to keep
Run it yourself, and what comes next
This module’s notebook
Module 11 quiz
Quiz 11
2 attempts allowed
12.1 The verdict comes back
Four things you will be able to do
The way through this module
12.2 The domain grades its own work
Why coding went first
The domain grades its own work
The loop, and what it covers
12.3 Vibe or augmented
A spectrum of intent
Agent-legible code
Sources
12.4 The ground-truth loop
The ground-truth loop
Briefs down, receipts up
Brainstorm, spec, plan, execute
Sources
12.5 Specs and red tests
Spec-driven development
Tests first, one at a time
12.6 Revert, record, understand
Test, then keep or revert
Savepoints and recorded proof
The debt nobody bills
Sources
12.7 A classifier you can read
A classifier you can read
An apprentice, or an examiner
Anatomy of a definition
12.8 Examples, the worksheet, and scores
A textbook, not a database
The worksheet before the verdict
Where a wrong label went wrong
From labels to scores
12.9 Measurement you cannot fool
Measurement you cannot fool
Three sets, one envelope
Counting it honestly
12.10 Ship it, and screen it
Ship it as a folder
Screen, then detail
12.11 What to keep, and what to try
Split it, score it, price it
Five things to keep
Run it yourself, and what comes next
This module’s notebook
Module 12 quiz
Quiz 12
2 attempts allowed
13.1 Words without a compiler
Five things you will be able to do
The way through this module
13.2 Two hires
Words without a compiler
Two hires, two nouns
The verification gap
13.3 Four partial substitutes
Four partial substitutes
Grounding is not truth
Sources
13.4 The clerk, and the budget
The privileged-employee rule
Return against risk, checking first
13.5 Appropriate reliance
The control room
Appropriate reliance
13.6 A board, not a scroll
A board, not a scroll
A wheel, not an ejector seat
Directing, and staying in
13.7 Recipes on the slider
A catalog of patterns
Point-task or recipe?
The autonomy slider
Eight recipes on the slider
Three placements that teach
13.8 Generator and gate
The map and the weather
Generator and gate
Property-based tests as a gate
13.9 The map that outlasts the products
The map and the weather
Six durable layers, two rails
The portable core
Directions, and four habits
13.10 Show the evidence
Show the evidence
Three screens, in this order
What counts
13.11 One question
Price it, score it, place it
Five things to keep
Thirteen modules, one question
What is left to do
This module’s notebook
Module 13 quiz
Quiz 13
2 attempts allowed
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.