Announcing our second book: Patterns for Building AI Agents

·

Nov 12, 2025

Most AI teams can build an impressive demo. Far fewer can ship a reliable system. The gap between prototype and production is where even strong engineering organizations stumble — not for lack of ambition, but for lack of established patterns.

Our newest book, Patterns for Building AI Agents, captures the emerging practices that are defining the agentic era: how to actually take agents from prototype to production. This includes how to design modular architectures, engineer context, build evals, and secure agents against failure and abuse.

Patterns is the practical guide to building agents that work — not just in notebooks, but in production.

We hope you enjoy it. Keep reading for an excerpt from the foreward...

Foreward

Here at Mastra, the open source Typescript framework for building AI agents, we’ve had a front-row seat to how people are building agents. Back in February 2025 (practically ancient times, in AI world), we published the popular guide Principles of Building AI Agents. In May, we updated the guide to include MCP, agentic RAG, and a few other emerging principles. But our work was far from finished.

2025 is the year of agents and, over the summer, we began to see a set of stories and guides emerging from prominent AI companies, model labs, and early-stage AI startups. The people pushing agents into production were publicly describing their successes (and failures). Principles was textbook-style knowledge. This was messier and rough, expressed in ah-ha! moments, lessons learned, and retrospectives — knowledge that sprawled across social media posts, Substacks, eng blogs, and Git repos.

Collecting and wrangling these lessons for our users eventually led to this book: Patterns for Building AI Agents. Now Volume 2 of an eventual trilogy. Principles are conceptual, patterns are pragmatic. While Principles of Building AI Agents covered what to build, Patterns covers how to build. Principles will get you through the first few weeks of building, but Patterns should be on your desk until its contents are imprinted in your mind.

We start off by sharing patterns for agent design and architecture, then dive into the art and science of context engineering. Next, we dig into the discipline of evals, the standard way for iterating on and refining agent quality. Finally, we talk about agent security, a field evolving in response to novel attack patterns. Agents are in the hands of early adopters — and attackers are enthusiastic early adopters!

Thanks for coming along as we all learn together. This book is a work in progress and a living document.

Perhaps as you build, you'll discover a new pattern that makes it into our next edition!

Stay up to date