Mastering Agents
Mastering Agents
Preface
In our previous e-book, “Mastering RAG,” our goal was clear: building enterprise-grade
RAG systems, productionizing them, monitoring their performance, and improving them.
At the core of it, we understood how RAG systems enhance an LLM’s ability to work with
specific knowledge by providing relevant context.
In this e-book, we’re taking a step further and asking, “How do we use LLMs to
accomplish end-to-end tasks?” This singular question opens up a door: AI agents. A RAG
system helps an LLM provide accurate answers based on given context. An AI agent
takes that answer and actually does something with it — makes decisions, executes
tasks, or coordinates multiple steps to achieve a goal.
A RAG-enhanced LLM could help answer questions about policy details by pulling relevant
information. But an AI agent could actually process the claim end-to-end by analyzing the
documentation, checking policy compliance, calculating payments, and even coordinating
with other systems or agents when needed.
The ideas behind agents has existed for years. It can be a software program or another
computational entity that can accept input from its environment and take actions based
on rules. With AI agents, you’re getting what has never been there before: the ability to
understand the context without predefined rules, the capacity to tune decisions based on
context, and learning from every interaction. What you’re getting is not just a bot working
with a fixed set of rules but a system capable of making advanced decisions in real-time.
Companies have quickly adapted, adopted, and integrated AI agents into their workflows.
Capgemini’s research found that “10% of organizations already use AI agents, more than
half plan to use them in 2025 and 82% plan to integrate them within the next three years.”
2
Mastering AI Agents
This e-book aims to be your go-to guide for all things AI agents. If you’re a leader looking
to guide your company to build successful agentic applications, this e-book can serve
as a great guide to get you started. We also explore approaches to measuring how well
your AI agents perform, as well as common pitfalls you may encounter when designing,
measuring, and improving them.
Chapter 1 introduces AI agents, their optimal applications, and scenarios where they
might be excessive. It covers various agent types and includes three real-world use cases
to illustrate their potential.
Chapter 4 explores how to measure agent performance across systems, task completion,
quality control, and tool interaction, supported by five detailed use cases.
Chapter 5 addresses why many AI agents fail and offers practical solutions for successful
AI deployment.
We hope this book will be a great stepping stone in your journey to build trustworthy
agentic systems.
- Pratik Bhavsar
3
Contents
Chapter 1: Chapter 2:
What are AI agents Frameworks for
Building Agents
7/27 28/43
Chapter 3: Chapter 4:
How to Evaluate Agents Metrics for Evaluating
AI Agents
44/61 62/79
5
Mastering AI Agents
Chapter 5:
Why Most AI Agents Fail &
How to Fix Them
80/95
Development Issues 81
LLM Issues 82
Production Issues 86
6
01
CHAPTER
WHAT ARE AI
AGENTS?
Mastering AI Agents
AI agents are software applications that use large language models (LLMs) to
autonomously perform specific tasks, ranging from answering research questions to
handling backend services. They’re incredibly useful for tasks that demand complex
decision-making, autonomy, and adaptability. You might find them especially helpful in
dynamic environments where the workflow involves multiple steps or interactions that
could benefit from automation.
Salesforce estimates that salespersons spend 71% of their time on non-selling tasks (like
administrative tasks and manually entering data). Imagine the time that could have gone
into directly engaging with customers, developing deeper relationships, and ultimately
closing more sales. This is true across multiple domains and applications: finance, health
care, tech, marketing, sales, and more.
Let’s use an example to understand this better. Imagine you run an online retail business
and receive hundreds of customer inquiries every day about order statuses, product
details, and shipping information. Instead of answering each and every query yourself, you
can integrate an AI agent into your solution to handle these queries.
1. Customer Interaction
A customer messages your service asking, “When will my order ship?”
2. Data Retrieval
The AI agent accesses the order management system to find the specific order details.
3. Response Generation
Based on the data retrieved, the agent automatically provides an updates to the customer,
such as sending “Your order will ship tomorrow and you’ll receive a tracking link via email
once it’s on its way.”
8
Mastering AI Agents
Fig 1.1 is an example of how agents are leveraged for code generation.
Conversation
Repository
Content result
Run test
Success
9
Mastering AI Agents
Types of AI Agents
Now that we’re familiar with what AI agents are, let’s look at different types of AI
agents along with their characteristics, examples, and when you can use them.
See Table 1.1 below to get a quick idea of the types of AI agents and where and
when you can use them.
High-stakes decisions,
External knowledge Legal research tools,
ReAct + RAG: domain-specific tasks,
access, low hallucinations, medical assistants,
Grounded Intelligence real-time knowledge
real-time data technical support
needs
10
Mastering AI Agents
Fixed Automation –
The Digital Assembly Line
This level of AI agents represents the simplest and most rigid form of automation. These
agents don’t adapt or think—they just execute pre-programmed instructions. They are
like assembly-line workers in a digital factory: efficient but inflexible. Great for repetitive
tasks, but throw them a curveball, and they’ll freeze faster than Internet Explorer.
(See Table 1.2 below)
Feature Description
Best Use Cases Routine tasks, structured data, situations with minimal need for adaptability.
RPA for invoice processing, email autoresponders, basic scripting tools (Bash,
Examples
PowerShell).
The fixed automation workflow (See Fig 1.2) follows a simple, linear path. It begins when
a specific input (like a file or data) triggers the system, which consults its predefined
rulebook to determine what to do. Based on these rules, it executes the required action
and finally sends out the result or output. Think of it as a digital assembly line where
each step must be completed in exact order, without deviation.
11
Mastering AI Agents
LLM-Enhanced –
Smarter, but Not Exactly Einstein
These agents leverage LLMs to provide contextual understanding and handle
ambiguous tasks while operating within strict boundaries. LLM-Enhanced Agents
balance intelligence and simplicity, making them highly efficient for low-complexity,
high-volume tasks. Take a look at their features below in Table 1.3.
Feature Description
The workflow below (Fig 1.3) shows how these smarter agents process information:
starting with the input, the agent uses LLM capabilities to analyze and understand
the input context. This analysis then passes through rule-based constraints that keep
the agent within defined boundaries, producing an appropriate output. It’s like having
a smart assistant who understands context but still follows company policy before
making decisions.
LLM-Enhanced Agent
12
Mastering AI Agents
ReAct –
Reasoning Meets Action
ReAct agents combine Reasoning and Action to perform tasks that involve strategic
thinking and multi-step decision-making. They break complex tasks into manageable
steps, reasoning through problems dynamically and acting based on their analysis.
These agents are like your type-A friend who plans their weekend down to the minute.
Table 1.4 lists their characteristics.
Feature Description
Scope Assists with basic open-ended problem-solving, even without a direct solution path.
The ReAct workflow starts with an Input Query and then enters a dynamic cycle between
the Reasoning and Action Phase, as you’ll see in Fig 1.4. Unlike simpler agents, it can
loop between thinking and acting repeatedly until the desired outcome is achieved before
producing the final Output/Action. Think of it as a problem solver that keeps adjusting its
approach - analyzing, trying something, checking if it worked, and trying again if needed.
Reasoning
Output /
Input Trigge repeat until desired outcome achieved
Action
Action Phase
13
Mastering AI Agents
Feature Description
Starting with an Input Query, this advanced workflow combines ReAct’s reasoning-action
loop with an additional Knowledge Retrieval step. The agent cycles between Reasoning,
Action Phase, and Knowledge Retrieval (See Fig 1.5) — consulting external sources as
needed — until it reaches the desired outcome and produces an Output/Action. It’s like
having a problem solver who not only thinks and acts but also fact-checks against reliable
sources along the way.
Reasoning
Output /
Input Query repeat until desired outcome achieved
Action
Knowledge
Action Phase
Retrieval
14
Mastering AI Agents
Feature Description
Leverages APIs, databases, and software tools to perform tasks, acting as a multi-
Intelligence
tool integrator.
Handles multi-step workflows, dynamically switching between tools based on task
Behavior
requirements.
Automates repetitive or multi-stage processes by integrating and utilizing diverse
Scope
tools.
Jobs requiring diverse tools and APIs in tandem for complex or multi-stage
Best Use Cases
automation.
Code generation tools (GitHub CoPilot, Sourcegraph's Cody, Warp Terminal), data
Examples
analysis bots combining multiple APIs.
Starting with an Input Query, the agent combines reasoning with a specialized tool loop.
After the initial reasoning phase, it selects the appropriate tool for the task (Tool Selection)
and then executes it (Tool Execution). This cycle repeats until the desired outcome is
achieved, leading to the final Output/Action. (See Fig 1.6)
Reasoning
Output /
Input Query repeat until desired outcome achieved
Action
15
Mastering AI Agents
Feature Description
Starting with an Input Query, the agent goes through a cycle of Reasoning and Execution,
but with a crucial additional step: Reflection. After each execution, it reflects on its
performance and feeds those insights back into its reasoning process. This continuous
loop of thinking, doing, and learning continues until the desired outcome is achieved,
producing the final Output/Action. This is evident in Fig 1.7.
Execution
When
desired Output /
Input Query Reasoning Reflection
outcome Action
achived
Feedback Loop
16
Download the Full ebook