Principles of Building AI Agents
By Sam Bhagwat
Synopsis
Sam Bhagwat, chief executive of the open-source TypeScript agent framework Mastra, wrote this short book to give software developers a working vocabulary for agentic AI applications. It moves quickly through the stack: choosing model providers and writing prompts; giving agents tools, memory and structured output; connecting external services through the Model Context Protocol; and breaking complex jobs into graph-based workflows that can branch, pause for human input and stream results. Later chapters cover retrieval-augmented generation and its alternatives, multi-agent systems, tracing, evaluations, local development and deployment.
The approach is conceptual first, with brief code samples that use Mastra and diagrams that show how the pieces connect. Bhagwat repeatedly advises starting with the simplest design that works, measuring quality with evals, and adding complexity only when results demand it. Successive editions have added material on agent-to-agent protocols, voice, computer use, sandboxes and agents that build other agents, reflecting how fast the field moves. Readers gain a fast, structured overview of the decisions involved in shipping an agent, enough to compare frameworks and plan a first project. Because the author's company builds agent infrastructure and gives the book away as outreach, readers should treat its framework examples as one option among several.
Scorecard
Editorial score
How it scored
Editorial score: 71.6 / 1005 weighted criteria
- 19.5/30
Influence30%
- 16.3/25
Authority25%
- 15.0/20
Practical value20%
- 12.8/15
Currency15%
- 8.0/10
Readability10%
- 71.6/100
Editorial score
How the rank was computed
Rank No. 290 of 500 comes from a composite of 53.4: observable signals 21.2 of 55 points plus editorial review 32.2 of 45 points.
All 11 inputs
| Input | Points |
|---|---|
| Observable signals | 21.2/55 |
| Reach (Amazon ratings volume) | 7.5/16.5 |
| Consensus across best-of lists | 2.8/13.8 |
| Awards and bestseller evidence | 3.3/8.3 |
| Reader rating, sample-adjusted | 3.9/8.3 |
| Amazon sales rank | 0.9/5.5 |
| Recency | 2.8/2.8 |
| Editorial review | 32.2/45 |
| Author authority | 7.3/11.3 |
| Influence | 8.8/13.5 |
| Practical value | 6.8/9.0 |
| Readability | 3.6/4.5 |
| Currency | 5.7/6.8 |
Each criterion is scored from 1 to 10 and weighted, and the points add up to the editorial score. The rank combines observable signals (55 percent) with this score (45 percent). Read the methodology.
Verdict
A brisk, practical primer on agent building blocks from a framework founder, best used as an orientation map rather than a reference.
Strengths
- Covers the full agent stack in brief
- Plainspoken, hype-free explanations for working developers
- Updated editions track MCP and A2A protocols
Keep in mind
Brevity limits depth on every topic, and the code examples rely on the author's TypeScript framework, so Python developers will need to translate the patterns.
Key takeaways
- Agents sit on a spectrum, from simple decision trees to autonomous planners, and most production systems should start at the simpler end.
- Sketching the task as a flowchart before coding clarifies which steps need a model call, a tool or deterministic logic.
- Structured workflows with branching, suspend-and-resume and streaming make agent behavior more predictable than a single open-ended loop.
- Evals and tracing belong in a project from the start, because agent quality cannot be judged reliably by spot-checking outputs.
Notable facts
- Mastra's book page lists the current version as the third edition and reports 189,500 printed copies. Source (opens in a new tab)
- A second edition released in June 2025 added material on MCP, image generation, voice, A2A, web browsing and computer use, workflow streaming, code generation and agentic RAG. Source (opens in a new tab)
About the author
Questions
What is Principles of Building AI Agents about?
Is Principles of Building AI Agents free?
Who should read Principles of Building AI Agents?
Related books
- Agentic Design Patterns Antonio Gullí
- Building Applications with AI Agents Michael Albada
- An Illustrated Guide to AI Agents Maarten Grootendorst and Jay Alammar
- HBR Guide to Generative AI for Managers Elisa Farri and Gabriele Rosani
- Designing Multi-Agent Systems Victor Dibia
- Building LLMs for Production Louis-François Bouchard and Louie Peters
Sources
- Mastra: Principles of Building AI Agents (opens in a new tab)
- Mastra blog: Announcing the second edition of Principles of Building AI Agents (opens in a new tab)
- Y Combinator: Mastra company profile (opens in a new tab)
- Boye & Company: The year of agents, a new book shares the principles of how to build them (opens in a new tab)
As an Amazon Associate, Best AI Books earns from qualifying purchases. Best AI Books is sponsored by Iternal.ai, whose founder and CEO, John Byron Hanby IV, wrote The AI Strategy Blueprint, our #1 ranked book. How we rank books.






