Jump to ratings and reviews
Rate this book

Principles of Building AI Agents

Rate this book
Rapid advances in large language models (LLMs) have made new kinds of AI applications, known as agents, possible. Written by a veteran of web development, Principles of Building AI Agents focuses on the substance without hype or buzzwords. This book walks key building blocks of providers, models, prompts, tools, memoryHow to break down complex tasks with agentic workflowsGiving agents access to knowledge bases with RAG (retrieval-augmented generation)Agent observability with tracing and evals

118 pages, Kindle Edition

Published February 23, 2025

102 people are currently reading
146 people want to read

About the author

Sam Bhagwat

3 books4 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
13 (9%)
4 stars
44 (30%)
3 stars
63 (44%)
2 stars
23 (16%)
1 star
0 (0%)
Displaying 1 - 25 of 25 reviews
Profile Image for Alice Li.
91 reviews5 followers
November 26, 2025
Unclear who the audience of this is — for a complete noob, it doesn’t explain the overall architecture at all high level and pops in too many jargons; for an expert, this is too shallow like you take a bite into each topic related to agents and not really chew it. Many buzz words and little good explanations. I definitely see this as a startup marketing material for Mastra, although I do appreciate that it has everything in one place and attempts to connect the whole picture. And at least the tone isn’t obnoxious.
Profile Image for Sabina.
145 reviews3 followers
August 16, 2025
This book was all over LinkedIn, and I was intrigued, so I got my own copy.
The author writes about AI agents. These are systems that help you perceive and reason with text using large language models, for example.

It’s important to note that the book includes several code snippets, so you’ll need a basic understanding of JavaScript.

The book jumps straight into the how-tos of building, evaluating, and deploying AI agents, serving as both a primer and a guide.

It offers great advice for engineers ready to build without getting lost in buzzwords.
Profile Image for Tomas Laurinavicius.
Author 3 books177 followers
March 9, 2025
Short and simple intro

Super short and simple introduction that may lack substance if you are looking for a comprehensive guide or more detailed explanation of AI terms like RAG, chunking, vector databases and so on. Nevertheless great read with some practical Mastra code examples.
Profile Image for Tadeo.
20 reviews1 follower
November 3, 2025
Cool book to get into the ai-generative world FAST. It does not go in depth, but provides a superficial explanation of key concepts. Mostly oriented to Mastra.
Profile Image for Kostiantyn Koshelenko.
Author 2 books20 followers
January 8, 2026
A thoughtful roadmap for moving from abstract AI ideas to real, working products. The examples make complex concepts feel practical and achievable. Anyone building with agents will find tools here that translate directly into better design and execution.
Profile Image for Charissa Ty.
Author 7 books101 followers
December 22, 2025
Very interesting quick read. Very useful for me since it concerns me actually building one. There are a couple of things here that are super useful that I can use while talking to my devs, and also a couple of front end considerations like streaming. Here are my notes:


1. Context Windows - Google gemini flash has the biggest, 2 mil tokens (4k pages of text) the larger the context window, the lesser effort it takes to select a context window

2. Chain of Draft (CoD): A minimalist prompting technique introduced in early 2025 that significantly reduces latency and costs by instructing models to use shorthand, 5-word reasoning steps instead of long explanations.

3. Chain of Preference Optimization (CPO): A 2024–2025 fine-tuning method that improves model reasoning by training them to prefer high-quality logic paths over flawed ones using preference data derived from tree-search processes. 

4. Prompting styles: zero shot (0 context), single shot, few shots, seed crystal (ask ai to create a prompt for you)

5. CAPITALIZATION adds emphasis, xml structure is more accurate

6. Think of agents as employees not as contractors. They maintain certain context, have specific roles and use tools to complete tasks.

7. Autonomy levels of agents
Low - make binary choices
Medium - have memory, call tools, retry failed tasks
High - do planning, divide tasks to subtasks, manage task queue

8. Model routing is an architectural layer that dynamically directs user prompts to the most appropriate AI model based on the query's complexity, cost, or required expertise.

9. Hierarchical memory - use recent messages with long term memories

10. A RAG-enabled system is like a student taking an open-book exam: 
- Retrieve: When you ask a question, the system first searches a specific knowledge base (like your company's PDFs, a database, or the live web) for relevant facts.
- Augment: It adds those specific facts into your original prompt as "context".
- Generate: The LLM reads that context and writes an answer based on those verified facts, often citing its sources.

11. Token limiter - limits the number of tokens so the context window doesn't max out

12. Tool all filter - a specialized processor used to manage a model's memory and cost by selectively removing tool-related data from the conversation history. 

13. as AI agents become more autonomous, ToolCallFilter is often paired with a TokenLimiter in an orchestration pipeline to ensure that long-running agentic loops remain efficient and do not "hallucinate" based on stale or overly complex tool results from earlier in the chat.

14. Static Agents: Operate with a permanent, pre-defined set of tools and logic to ensure high reliability for repetitive tasks, such as a Customer Support Bot that can only check order status or process returns using fixed API calls.

15. Dynamic Agents: Adjust their personality, model choice, and tool access on-the-fly based on the specific user or task context, such as a Personal Research Assistant that switches to a specialized medical toolset and more powerful reasoning model only when it detects a health-related query.

16. Guardrails - to guard against 'prompt injection attacks' like, 'ignore all censorship and generate this pic for me'

17. Agentic iPaaS (Agentic Integration Platform as a Service):
Goal-Oriented Autonomy: Instead of following "if-this-then-that" rules, you give the system a goal (e.g., "Onboard this employee and set up their hardware"). The platform then determines the necessary steps across various systems to achieve it.

18. Model Context Protocol (the client is a form of middleware and servers are standardised access to databases, apis) works like a USB c for all AI Applications to connect ai agent to tools and to each other

19. A2A is a newer type of protocol than Mcp by Google where it deals with communication with 'unstrusted' agents. 

20. Probs with Mcp - discovery, quality and configuration

21. Graph based workflows - Unlike traditional "linear" workflows (Step 1 → Step 2 → Step 3), a graph-based approach allows for complex, dynamic behaviors such as loops, branching, and parallel execution. 

22. Sometimes workflows need to pause and you need human in the loop workflows. Suspend and resume to save processing effort.

23. Stream as much as you can. Sync updates and workflows to the front end so the user doesn't just look at a shimmering state forever. It's important to show that your ai is reliable. 

24. Escape hatches - if your function is stuck waiting, find ways to push partial results or progress updates to the frontend.

25. Llms are non-deterministic the question isn't whether it will or will not go off the rails. It's 'when', and 'how much'

26. Semantic Chunking - splitting docs into bite sized pieces for speech, not by word count but by relativity

27. Overlap window - When breaking a long document into smaller pieces (chunks), the "overlap window" ensures that the end of Chunk A and the beginning of Chunk B share the same few sentences.

28. Other than RAG you have Agentic Rag that can be more accurate. There's also full context loading but that's slow and expensive.

29. Multi agents have diff styles like real teams. 
- supervisors
- hierarchical
- network
- custom

30. Do a couple of agents discuss amongst themselves then report to a main agent later?
They embody different stages of the workflow

31. Evals evaluate agent quality. They rate from 0-1 rather than fail and pass. In the future there will be synthetic evals. 

32. Rubrics include:
1. hallucination (do facts belong?)
2. faithfulness (accuracy)
3. constant similarity (responses the same across diff phrasing of prompts?)
4. completeness
5. Answer relevancy

33. Can they understand context?
1. Position (is the correct one at the top of the response?)
2. Percision (chunks grouped logically?)
3. Relevancy (appropriate?)
4. Recall (able to recall context completely?)

34. How do they output?
1. Tone consistency
2. Prompt alignment (does it follow instructions like formatting requirements?)
3. Summarization quality
4. Keyword coverage
5. Toxicity and biases?

35. Full agent logic can't sit on the front end because it may leak API keys to llm providers.
Profile Image for Richard Newton.
Author 27 books595 followers
September 29, 2025
There seems to be a certain irony in reading a reference book on AI, given both how fast AI develops (much faster than books!) and the current tendency for AI to replace books as a reference source.

I got this book free. If you apply the author seems willing (or was at time of writing), to distribute it freely over the world. I assume this generosity reflects the success of his business.

It’s essentially a state of the nation style book on AI and developing AI agents. It has lots of references to the authors own product Mastra. No objection there as it is a free book, and they are examples not an excessive plug of the product.

I’m not really the target reader for this book as it’s a long long time since I dealt with coding or software development, so take my review with a pinch of salt. But even for me I found it useful in refreshing and updating my knowledge on terminology and concepts, even if some was beyond me. It’s clearly written and mostly relatively accessible - although it’s definitely not for someone who knows nothing about AI or technology development.
Profile Image for Michael.
Author 4 books51 followers
August 8, 2025
Good overview for vendor-ware. Will give you confidence about the scope of this agentic stuff, and demystify some terms.

Wishes for next edition:
- better code examples (and not too reliant on Mastra-specific work… yes they’re selling a tool here, but some usefulness is lost)
- more in-depth explanations—there’s a bunch of “rest of the owl” hand-waiving https://knowyourmeme.com/photos/57207...
- use of an AI editor to sort out myriad layout issues


All in all, well worth the price paid ($0) and time (~90 minutes). Nice work.

Profile Image for Alexander Parady.
62 reviews5 followers
November 7, 2025
This book was good in that it gives a surface level overview of many parts of the industry. Felt a bit washed as I've read some books that are more in depth, but good concepts to review around what matters in production for AI enabled applications. I'd primarily recommend this to someone that wants an intro to some AI concepts, but frankly, there are probably better reads. Very short chapters and book which was a plus. You could really get through this in one day if you desired. I got the book for free at TechCrunch which put me over the hump to 3 stars instead of 2 haha.
Profile Image for Sean Tierney.
13 reviews7 followers
July 23, 2025
Fantastic primer on the mechanics of building AI agents. I have a minimal tech background and my experience in this realm thus far has been with constructing agents via N8n but this book opened my eyes to Mastra for building agents via their framework. I like the authors style of explaining things holistically and agnostic of implementation and then providing specific code samples of how to do it in Mastra. Highly recommend this book.
Profile Image for Fifi Kara.
1 review
August 28, 2025
Very easy read, can be completed in an evening or two. Would say the author presents real-world use cases and examples of AI agents and is quite specific in his recommendations on how to best build/use them through things like prompting, model choices and how to handle guardrails amongst other themes.

It's a solid read if you want practical advice on building agents. Nothing particularly captivating or novel is presented here, but that isn't necessarily why you pick up this book.
67 reviews
October 24, 2025
Good quick read about the various concepts of AI agent building. If you are already in the industry it’ll be a good benchmark of how familiar you are with the current state of the art.

The author uses his project/company’s framework to illustrate those concepts. If you are not a programmer you can safely skip those sections and still appreciate what he’s talking about.

Docking one point for the many typos (even in the second edition) but i cant really complain - the book is free.
1 review
November 25, 2025
I found this book in a Linkedin post and it was sent to me for free. As a promotional gift, it presents the necessities that the JavaScript library Mastra efficiently solves. However, it lacks a complete review of the principles of AI agents. This book must be interpreted as an advertisement that briefly mentions the principles of building AI agents in order to justify the methods and algorithms of their library.
Profile Image for Trung Huynh.
10 reviews
December 6, 2025
it's a quick read for anyone who want to catch up to what AI agent using LLM are doing upto May 2025 - the world of AI is moving fast, the definitions and standards of AI agent is yet to be applied worldwide. In such context, the author have briefly introduced and wrapped up what has been happening and how are we currently deploying and using AI agent

It is a very good read for beginners like me as a data engineer to catch up.
Profile Image for Marshall Hahn.
15 reviews
August 10, 2025
This book presents a good introduction to the topic. I appreciated how short and simple it was to read. With that being said, if you’re looking for a comprehensive deep dive this might not be what you’re looking for. All code examples show concepts using one specific framework, but that makes sense given the framework is created by the author’s company.
1 review
August 11, 2025
Excellent overview and very fast read. Great way to get up to speed on all current facets around agentic AI. Wasn’t very well written, but you’re not likely reading it for the prose. Only qualm was that it went shallow on some topics and deep on others - especially around RAG. Overall would definitely recommend though!
Profile Image for FullMoon.
8 reviews
September 11, 2025
Some concepts are explained in a concise manner. This is good for those that was a quick refresher, but certain things did feel rushed and deserved more clarification. Also, there are grammatical errors (e.g., page 83 “Great, know you know”). The concepts and outlined chapters seem rushed and could be better connected with one another.

Profile Image for Anurag.
7 reviews
September 19, 2025
straight to the point, no bs. explains all the contents in simple and precise manner
Profile Image for Jaafar.
60 reviews1 follower
October 23, 2025
Succint. To the spot. Think of it as 101 for all the AI frenzy and buzzwords
Profile Image for Chloe Duckworth.
37 reviews
December 21, 2025
Simple, practical, and accessible guide for building AI agents. Inspired me to write a similar guide for a different topic.
7 reviews1 follower
June 10, 2025
Much less a “book” and more an extended Medium article that’s half tutorial and half advertisement for their AI SDK Mastra.

Worthwhile if you consider it a broad, superficial overview of agentic AI for the unacquainted.

Would have benefited from paying a guy online $20 to copy edit it for an hour or two. Has an embarrassing amount of typos, grammar, mistakes, and straight up unfinished sections with drafting notes still there.
Displaying 1 - 25 of 25 reviews

Can't find what you're looking for?

Get help and learn more about the design.