Blog
Principles of Building AI Agents: what's in Sam Bhagwat's free Mastra book, and who should read it
It's the agent book you keep seeing on desks and conference tables, and it's free. Here's what Principles of Building AI Agents actually covers, where it shines, what it can't give you, and the reading path we'd pair it with.
Some technical books become objects. You see them on desks in photos, in conference swag bags, in a teammate's hand at standup. Principles of Building AI Agents is one of those, and a fan on Mastra's own page jokes that it's "basically a meme in SF at this point, but for good reason."
It's also free, which explains part of the search spike. Here's what's in it, and whether it's worth your evenings.
The basics
- Author: Sam Bhagwat, CEO of Mastra, the open-source TypeScript agent framework
- Price: free, for an email address, on Mastra's book page
- Format: downloadable PDF; printed copies circulate at Mastra events
- Current edition: the model-provider chapter is dated March 2026
- Sequel: Patterns of Building AI Agents, the second book in the series
Some context on the author's vantage point: Mastra's GitHub repo had 29,908 stars and @mastra/core logged about 3.2 million npm downloads in the week to November 28, 2026. The book comes from people shipping a widely used framework, not from the sidelines. You can follow Mastra's numbers on our Mastra star tracker and downloads tracker.
What's inside, part by part
The table of contents runs from first principles to production. Grouped by theme:
| Theme | Chapters cover |
|---|---|
| Foundations | Choosing a provider and model (hosted vs open, size, context, reasoning models), writing great prompts |
| Agents | Levels of autonomy, model routing, structured output, tool design, memory (observational memory, processors, prompt caching), dynamic agents, middleware, guardrails, auth |
| Connecting tools | MCP primitives, the ecosystem, when to use it, building a server and client; popular third-party tools including web scraping and computer use |
| Workflows | Branching, chaining, merging, conditions, streaming updates |
| Knowledge | Setting up a RAG pipeline (chunking to reranking) and alternatives to RAG |
| Many agents | Multi-agent systems, with a note on A2A |
| Quality | Tracing, observability and a long evals chapter: datasets, LLM-as-judge, tool-calling evals, multi-turn, A/B tests, human review |
| Shipping | Local development, deployment, sandboxes and filesystems |
| Beyond text | Multimodal: images, voice, video |
Where it shines
Tool design gets the respect it deserves. The tool-calling chapter frames designing your tools as "the most important step." That echoes Anthropic's engineering advice that its SWE-bench agent work spent more time on tools than prompts (Building effective agents). If you take one idea from the book into your next project, make it this one.
It doesn't treat RAG as a religion. A whole chapter covers alternatives: give the agent search tools, let it run code, feed full context, extract entities. In 2026, with million-token context windows, that's the right instinct.
Evals and tracing aren't an afterthought. The book's own heading says "observability and evals are even more important than you think." We agree; it's where most agent projects quietly fail.
What it can't give you
- Freshness. Agent tooling moves monthly. A March 2026 model chapter predates November's launches; check current pricing and models elsewhere.
- Your context. No book can tell you which of your workflows deserve an agent. That takes experiments.
- Framework neutrality, entirely. It's a conceptual guide, but it comes from a framework company and its examples lean TypeScript. That's fine; just know it.
Who should read it
- Developers new to agents: yes, start to finish. It opens with fundamentals.
- Experienced builders: skim to the memory, MCP, evals and sandbox chapters.
- Managers and non-developers: read the first third and the evals chapter; skip the rest.
A reading path we'd pair with it
- Start with our plain-English types of AI agents for the map.
- Read the book, Foundations through Workflows.
- Read Anthropic's Building effective agents for a second voice on simplicity.
- Build something small: how to build an agent with Claude or the LiveKit voice agent quickstart.
- Return for the evals chapter, then build an eval harness.
If you want a credential at the end of it, our guide to agentic AI certifications covers what's worth taking. And to compare Mastra with other frameworks by real adoption, see AI agent frameworks.
FAQ
Who wrote Principles of Building AI Agents?
Sam Bhagwat, the CEO of Mastra, the open-source TypeScript framework for building AI agents. Mastra publishes the book and a follow-up, Patterns of Building AI Agents.
Is Principles of Building AI Agents free?
Yes. Mastra offers it free in exchange for an email address on its website, with no payment required. Printed copies are also handed out at Mastra events.
What does Principles of Building AI Agents cover?
It starts with LLM fundamentals, choosing models and prompting, then covers agents and levels of autonomy, tool calling, memory, dynamic agents, middleware and guardrails, MCP, workflows (branching, chaining, streaming), RAG and its alternatives, multi-agent systems, tracing and evals, local development and deployment, sandboxes and filesystems, and multimodal agents.
Is Principles of Building AI Agents only about Mastra?
No. Mastra describes it as a conceptual guide to the patterns and principles of agentic systems, while its framework docs cover Mastra-specific implementation. Code examples lean TypeScript, but the concepts apply to any stack.
Is it good for beginners?
Yes for developers new to agents: it begins with LLM fundamentals and prompt engineering before moving to agents, memory and workflows. Non-developers may find the later chapters on evals, deployment and sandboxes technical.