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

Patterns for Building AI Agents stacked on a shelf.

32,500 Books Printed

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

Principles of Building AI Agents displayed on an event.

Principles

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

Sam Bhagwat introducing Patterns for Building AI Agents.

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.

  • Whiteboard Agent Capabilities
  • Evolve Your Agent Architecture
  • Dynamic Agents
  • Human-in-the-Loop
  • Parallelize Carefully
  • Share Context Between Subagents
  • Avoid Context Failure Modes
  • Compress Context
  • Feed Errors Into Context
  • List Failure Modes
  • List Critical Business Metrics
  • Cross-Reference Failure Modes and Success Metrics
  • Iterate Against Your Evals
  • Create an Eval Test Suite
  • Have SMEs Label Data
  • Create Datasets from Production Data
  • Evaluate Production Data
  • Prevent the Lethal Trifecta
  • Sandbox Code Execution
  • Granular Agent Access Control
  • Agent Guardrails

5. What's Next(ish)

Frequently asked questions