No. 290 of 500 No. 32 in Generative AI & LLMs

Principles of Building AI Agents

By Sam Bhagwat

Published
February 24, 2025
Print length
142 pages
Reading level
Intermediate
ISBN-13
979-8312004281
Publisher
Independently published
Written for
Software engineers and technical product managers starting their first LLM agent project.

Synopsis

Sam Bhagwat, chief executive of the open-source TypeScript agent framework Mastra, wrote this short book to give software developers a working vocabulary for agentic AI applications. It moves quickly through the stack: choosing model providers and writing prompts; giving agents tools, memory and structured output; connecting external services through the Model Context Protocol; and breaking complex jobs into graph-based workflows that can branch, pause for human input and stream results. Later chapters cover retrieval-augmented generation and its alternatives, multi-agent systems, tracing, evaluations, local development and deployment.

The approach is conceptual first, with brief code samples that use Mastra and diagrams that show how the pieces connect. Bhagwat repeatedly advises starting with the simplest design that works, measuring quality with evals, and adding complexity only when results demand it. Successive editions have added material on agent-to-agent protocols, voice, computer use, sandboxes and agents that build other agents, reflecting how fast the field moves. Readers gain a fast, structured overview of the decisions involved in shipping an agent, enough to compare frameworks and plan a first project. Because the author's company builds agent infrastructure and gives the book away as outreach, readers should treat its framework examples as one option among several.

Scorecard

Editorial score

How it scored

Editorial score: 71.6 / 1005 weighted criteria

  • Influence30%

    19.5/30
  • Authority25%

    16.3/25
  • Practical value20%

    15.0/20
  • Currency15%

    12.8/15
  • Readability10%

    8.0/10
  • Editorial score

    71.6/100

How the rank was computed

Rank No. 290 of 500 comes from a composite of 53.4: observable signals 21.2 of 55 points plus editorial review 32.2 of 45 points.

All 11 inputs
InputPoints
Observable signals21.2/55
Reach (Amazon ratings volume)7.5/16.5
Consensus across best-of lists2.8/13.8
Awards and bestseller evidence3.3/8.3
Reader rating, sample-adjusted3.9/8.3
Amazon sales rank0.9/5.5
Recency2.8/2.8
Editorial review32.2/45
Author authority7.3/11.3
Influence8.8/13.5
Practical value6.8/9.0
Readability3.6/4.5
Currency5.7/6.8

Each criterion is scored from 1 to 10 and weighted, and the points add up to the editorial score. The rank combines observable signals (55 percent) with this score (45 percent). Read the methodology.

Verdict

A brisk, practical primer on agent building blocks from a framework founder, best used as an orientation map rather than a reference.

Strengths

  • Covers the full agent stack in brief
  • Plainspoken, hype-free explanations for working developers
  • Updated editions track MCP and A2A protocols

Keep in mind

Brevity limits depth on every topic, and the code examples rely on the author's TypeScript framework, so Python developers will need to translate the patterns.

Key takeaways

  1. Agents sit on a spectrum, from simple decision trees to autonomous planners, and most production systems should start at the simpler end.
  2. Sketching the task as a flowchart before coding clarifies which steps need a model call, a tool or deterministic logic.
  3. Structured workflows with branching, suspend-and-resume and streaming make agent behavior more predictable than a single open-ended loop.
  4. Evals and tracing belong in a project from the start, because agent quality cannot be judged reliably by spot-checking outputs.

Notable facts

  • Mastra's book page lists the current version as the third edition and reports 189,500 printed copies. Source (opens in a new tab)
  • A second edition released in June 2025 added material on MCP, image generation, voice, A2A, web browsing and computer use, workflow streaming, code generation and agentic RAG. Source (opens in a new tab)

About the author

Sam Bhagwat

Sam Bhagwat is founder and CEO of Mastra, an open-source TypeScript framework for building AI agents that went through Y Combinator's Winter 2025 batch. He previously spent about eight years as a cofounder of Gatsby, the React website framework that was sold to Netlify, and earlier worked as an engineer at Zenefits and PlanGrid. He graduated from Stanford in 2011.

Questions

What is Principles of Building AI Agents about?
It is a short guide to the components of LLM-powered agents: model selection, prompting, tools, memory, the Model Context Protocol, graph-based workflows, retrieval-augmented generation, multi-agent systems, evals, tracing and deployment. Sam Bhagwat explains each concept briefly with diagrams and code samples, aiming to help developers move from curiosity to a working agent quickly.
Is Principles of Building AI Agents free?
Mastra, the company Bhagwat leads, offers the book as a free digital download on its website and has handed out printed copies at AI events. A paperback edition is also sold through Amazon. The free distribution doubles as outreach for Mastra's open-source framework, which the book's code examples use.
Who should read Principles of Building AI Agents?
Developers, engineering leads and technical product managers about to build their first agentic application will get the most from it. The book assumes basic programming familiarity but no machine learning background. Experienced agent builders will find much of it familiar and may prefer Mastra's companion volume on agent design patterns or deeper engineering texts.

Sources

As an Amazon Associate, Best AI Books earns from qualifying purchases. Best AI Books is sponsored by Iternal.ai, whose founder and CEO, John Byron Hanby IV, wrote The AI Strategy Blueprint, our #1 ranked book. How we rank books.