Principles
of Building
AI Agents
Principles of Building AI Agents is the world's leading guide to getting started with AI agents. Written by Sam Bhagwat, CEO of Mastra, it covers the core concepts, tools and patterns developers need to build agents that reason, use tools, manage memory and orchestrate workflows in production.
- Agents
- Memory
- Workflows
- RAG
- Tools
- Traces
The Complete Handbook for Building Production AI Agents

189,500 Books Printed
Principles of Building AI Agents has been distributed to people across the globe.

Patterns
Explore the second book in agentic series that builds on Principles

Sam Bhagwat
Sam Bhagwat is the CEO of Mastra and the author of Principles of Building AI Agents. Watch him go over a few chapters of his book.
Read and shared worldwide.
What's inside?
Principles of Building AI Agents gives you a clear overview of how modern AI agents work and the core concepts, tools and patterns you will use to build real agentic systems. The book opens with LLM fundamentals and prompt engineering before moving into agents, tool calling, memory, workflows and RAG. Later chapters cover multi-agent systems, observability and evals, deployment, coding agents and multimodal capabilities. Each chapter includes code examples and real-world patterns.
12. Workflows 101
14. Suspend and Resume
16. RAG 101
17. Choosing a Vector Database
20. Multi-Agent 101
21. Agent Supervisor & Subagents
22. Control Flow
23. Workflows as Tools
24. Parallelized Tool Calls
33. What’s Next
Frequently asked questions
Who is Principles of Building AI Agents for?
Principles of Building AI Agents is written for developers who want to build real agentic systems. The book starts with LLM fundamentals and prompt engineering before progressing to agents, memory, workflows, RAG and multi-agent systems.
Is Principles of Building AI Agents really free?
Principles of Building AI Agents is free. Enter your email to get your copy. The book has been distributed to 119,500 people across the globe with no payment required.
What does Principles of Building AI Agents cover?
Principles of Building AI Agents covers 34 chapters across agents, memory, workflows, RAG, tool calling, MCP, multi-agent systems, evals, observability, deployment and multimodal capabilities. Each chapter includes code examples and real-world patterns. The book is a practical reference for developers building real agentic systems.
How is Principles of Building AI Agents different from the Mastra docs?
Principles of Building AI Agents is a conceptual guide to building agentic systems. The Mastra docs cover implementation details specific to the Mastra framework. The book explains the underlying patterns and principles.
What is the Patterns book?
Patterns of Building AI Agents is the second book in the agentic series that builds on Principles.