Preface
We are living in a time of accelerated change in artificial intelligence (AI), where models are no longer passive tools but active decision-makers. Since the release of ChatGPT in November 2022, the world has witnessed a seismic shift: not only in the capabilities of large language models (LLMs) but also in the way AI is architected, integrated, and operationalized within real-world systems.
A new paradigm has emerged-AI agents. Unlike traditional AI workflows, agents bring persistence, autonomy, and goal-oriented reasoning to applications. They can plan, remember, use tools, and interact with other agents or humans to complete complex tasks. From customer service to R&D, from orchestrating APIs to driving personalized workflows, AI agents are reshaping how we think about software and intelligence.
This book serves as a hands-on guide to understanding and building AI agents, covering their architecture, key components, and real-world use cases. Whether you are a developer, architect, product manager, or AI enthusiast, this book aims to give you the foundational knowledge and practical skills to harness the power of autonomous agents.
The book is structured into three parts:
- Part 1, Foundations of AI Workflows and the Rise of AI Agents, explores how AI workflows have evolved since the rise of generative models, tracing the shift from simple API calls to more intelligent, autonomous behaviors. It introduces the concept of AI agents, their ingredients-LLMs, tools, memory, and context-and highlights the growing need for agentic systems across industries.
- Part 2, Designing, Building, and Scaling AI Agents, dives into the practical aspects of agent development. It covers AI orchestration tools, memory and context handling, tool integration, and agent observability. This part also walks you through building single-agent and multi-agent applications using frameworks such as LangChain and LangGraph, with hands-on examples such as e-commerce assistants and customer support agents.
- Part 3, Road to an Open, Agentic Ecosystem, looks ahead to the protocols, platforms, and principles shaping the future of intelligent software. It covers emerging open standards such as MCP, A2A, and NLWeb, and discusses how to build responsible, secure, and cost-effective agent systems for enterprise-scale deployment. It will also cover responsible AI practices, including evaluation, safety mechanisms, and human oversight.
Who this book is for
This book is for developers, architects, innovation leaders, and researchers who want to unlock the full potential of AI agents. Whether you're a software engineer building agent-based workflows, a product owner designing intelligent assistants, or a business strategist looking to embed autonomous decision-making into your systems, this book offers the frameworks, examples, and tools you need to get started-and scale.
What this book covers
Chapter 1, Evolution of GenAI Workflows, traces the transformation of AI workflows since late 2022, from simple API interactions to retrieval-augmented generation (RAG). It explores recent breakthroughs such as fine-tuning, model distillation, and reinforcement learning from human feedback (RLHF), and introduces the need for more autonomous, agentic behaviors.
Chapter 2, The Rise of AI Agents, defines what AI agents are and how they differ from previous automation paradigms such as RPA. It introduces different types of agents and the key components that make up their architecture, including system messages, tools, memory, and data.
Chapter 3, The Need for an AI Orchestrator, examines the emerging role of orchestration layers in LLM-based applications. It compares popular orchestrators, describes their components, and provides guidance on selecting the right orchestrator for your needs.
Chapter 4, The Need for Memory and Context Management, dives into how agents can store, retrieve, and update information through various types of memory (short-term, long-term, episodic, and semantic), along with techniques to manage context windows and leverage vector databases.
Chapter 5, The Need for Tools and External Integrations, explores how agents use APIs, databases, and third-party services to interact with the world. It also discusses asynchronous versus synchronous calls and how to enable observability through monitoring and logging.
Chapter 6, Building Your First AI Agent with LangChain, walks you through building your own single-agent applications using LangChain, including two practical use cases: an e-commerce assistant and a customer support agent.
Chapter 7, Multi-Agent Applications, explores what happens when multiple agents work together. It covers design patterns such as group chat, hierarchical, and sequential coordination, introduces orchestrators such as LangGraph and AutoGen, and guides you in building your first multi-agent system.
Chapter 8, Orchestrating Intelligence: Blueprint for Next-Gen Agent Protocols, introduces emerging standards and protocols-such as MCP, A2A, ACP, and NLWeb-that aim to define the next layer of the intelligent web for interoperable agents.
Chapter 9, Navigating Ethical Challenges in Real-World AI, highlights the critical importance of designing agent systems responsibly. It covers evaluation strategies, security filters, cost control, and the implementation of guardrails and human-in-the-loop systems to ensure safe and ethical deployment of autonomous AI agents.
To get the most out of this book
Following along will be easier if you bear the following in mind:
- Learn through hands-on examples: Many chapters include real-world scenarios and practical exercises. Whenever possible, follow along by building your own AI agents using frameworks such as LangChain and LangGraph, and try deploying them using APIs, vector databases, and orchestrators.
- Experiment with different agent behaviors: Agent design is not one-size-fits-all. Modify tools, memory strategies, and workflows to see how they affect outcomes. Play with different architectures-single-agent, multi-agent, and hierarchical-to explore their strengths and trade-offs.
- Explore the open source tools and orchestration frameworks: This book covers a wide range of technologies. Take time to dive into the documentation for LangChain, LangGraph, and LangSmith to understand how to extend and fine-tune your own implementations.
- Think beyond the basics: The agentic paradigm is still evolving rapidly. Use this book as a launchpad, but stay current with the latest protocols, research papers, and advancements in LLM orchestration, tool use, and agent collaboration to deepen your expertise.
Here is a list of things you need to have:
Software/hardware covered in the book
System requirements
Python 3.10 or higher
Windows, macOS, or Linux
Node.js
Windows, macOS, or Linux
LLM chat and embedding models
Windows, macOS, or Linux
You can decide to leverage your LLM of choice. Throughout the book, we will be using GPT-4o from Azure OpenAI or OpenAI.
Other options include (but are not limited to) the following:
Hugging Face Hub
Anthropic
Gemini
Download the example code files
The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/AI-Agents-in-Practice. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://packt.link/gbp/9781805801351.
Conventions used
There are a number of text conventions used throughout this book.
CodeInText
: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and X handles. For example, "Launch a mock JSON server on localhost:3000
to enable the cart management tool."
A block of code is set as follows:
from langchain_huggingface import HuggingFacePipeline llm = HuggingFacePipeline.from_model_id( model_id="microsoft/Phi-3-mini-4k-instruct", ...