Patterns
for Building
AI Agents
Patterns of Building AI Agents is a practical guide to taking AI agents from prototype to production. Written by Sam Bhagwat, CEO of Mastra, it covers design patterns, context engineering, eval workflows and security emerging from teams pushing agents into production at prominent AI companies.
- Design Patterns
- Context Engineering
- Eval Workflows
- Security
The Practitioner's Guide to Taking AI Agents to Production

32,500 Books Printed
Combined across both books, 32,500 copies have been distributed to people across the globe.

Principles
Start with the first book in the agentic series to learn the fundamentals

Sam Bhagwat
Sam Bhagwat is the CEO of Mastra and the author of Patterns of Building AI Agents. Watch him go over a few chapters of his book.
Read and shared worldwide.
Get your free copy of “Patterns”
What's inside?
Patterns of Building AI Agents covers practical patterns for taking AI agents from prototype to production. Learn strategies emerging from teams pushing agents into production at prominent AI companies. Chapter topics include human-in-the-loop patterns and dynamic agent architecture, context engineering techniques for parallelizing and compressing context, eval workflows for moving from MVP to production, and security patterns including guardrails, sandboxing and granular access controls.