liveBook · Manning

What you will learn in Build an AI Agent (From Scratch)

Agents that reason, plan, and act autonomously

by Jungjun Hur and Younghee Song

Chapter by chapter

Chapter 1: What is an AI agent?

The introduction explains why the book builds agents from scratch rather than relying on frameworks from the outset.

1.1 The age of AI agents · 1.2 Understanding LLM agents · 1.2.1 What is an LLM? · 1.2.2 What is an LLM agent? · 1.3 Workflow vs. agent · 1.3.1 Workflow: Developer-defined flow · 1.3.2 Agent: LLM-directed flow · 1.3.3 Combining workflows and agents in practice · 1.4 Tasks that require agents · 1.4.1 Tasks that require an LLM · 1.4.2 Conditions for using agents · 1.4.3 GAIA: An agent gym · 1.5 Context engineering · 1.5.1 Why agents fail · 1.5.2 From prompt engineering to context engineering · 1.5.3 Bigger context isn’t always better · 1.5.4 Five context-engineering strategies · 1.5.5 From context engineering to harness engineering · 1.5.6 The journey of this book · 1.6 Prerequisites for reading this book · 1.7 Summary

What you learn in chapter 1 →

Chapter 2: The brain of AI agents: LLMs

Introduces the research agent built throughout the book and identifies the LLM as its decision-making brain.

2.1 Choosing LLMs for agents · 2.1.1 Starting with closed LLMs · 2.1.2 Expanding to open LLMs · 2.1.3 Essential LLM capabilities for agents · 2.2 LLM API basics for building agents · 2.2.1 Setting up the development environment · 2.2.2 Getting started with the OpenAI API · 2.2.3 Unifying providers with LiteLLM · 2.2.4 Conversation management: Handling stateless APIs · 2.2.5 Generating structured output · 2.2.6 Asynchronous calls · 2.3 Enhancing agent intelligence: Prompt engineering · 2.3.1 The role of system prompts · 2.3.2 Guidelines for agent prompts · 2.4 Experiencing LLM limitations with GAIA · 2.4.1 Why GAIA: Setting goals for agent development · 2.4.2 Experiment setup · 2.4.3 Results and analysis: Why LLMs need tools · 2.5 Summary

What you learn in chapter 2 →

Chapter 3: Enabling actions: Tool use

The chapter introduction explains why agents need tools and sketches how an LLM uses a tool result to produce an answer.

3.1 LLM tools · 3.1.1 Why do we need LLM tools? · 3.1.2 Types of LLM tools · 3.2 How LLMs use tools · 3.2.1 How tool calling works · 3.2.2 How an LLM chooses tools · 3.2.3 Guidelines for effective tool calling · 3.3 Building tools and tool definitions for LLMs · 3.3.1 Implementing a web search tool · 3.3.2 Converting to tool definitions · 3.3.3 End-to-end tool execution · 3.3.4 The challenges of custom tools · 3.4 MCP: Standardizing tools · 3.4.1 The core of MCP: Server–client architecture · 3.4.2 Hands-on: Running an MCP server · 3.4.3 Understanding the MCP client · 3.4.4 Hands-on: Implementing an MCP server · 3.5 Summary

What you learn in chapter 3 →

Chapter 4: Implementing a basic ReAct agent

This introduction presents ReAct as the repeating reasoning-and-action pattern that combines an LLM with tools to solve problems.

4.1 How ReAct agents work · 4.1.1 The think-act cycle · 4.1.2 From text parsing to tool calling · 4.2 Agent architecture overview · 4.2.1 The completed agent · 4.2.2 Information flow: The core design · 4.2.3 Components we have to build · 4.3 ExecutionContext: The agent’s central storage · 4.3.1 What happens during agent execution · 4.3.2 ExecutionContext implementation · 4.4 Tool abstraction · 4.4.1 Why we need a unified tool interface · 4.4.2 BaseTool: The foundation · 4.4.3 FunctionTool: Wrapping functions · 4.4.4 Integrating MCP tools · 4.5 LLM communication layer · 4.5.1 Reasons for adding a communication layer · 4.5.2 LlmRequest: Selecting what to send · 4.5.3 LlmResponse: Standardizing what we receive · 4.5.4 LlmClient: The provider adapter · 4.5.5 Putting it together · 4.6 Implementing the agent · 4.6.1 Agent class structure · 4.6.2 The run() method · 4.6.3 The step() method · 4.6.4 The think() and act() methods · 4.7 Adding structured output · 4.7.1 The approach: Tools as output formatters · 4.7.2 Modifying the agent · 4.7.3 Using structured output in practice · 4.8 Testing with the GAIA benchmark · 4.8.1 From LLM to agent · 4.8.2 Results · 4.9 Summary

What you learn in chapter 4 →

Chapter 5: Building knowledge bases with RAG

Introduces knowledge bases with RAG as the next context-engineering enhancement to the basic agent and previews the chapter’s focus on vector and structure-based search.

5.1 The problem of using internal data · 5.1.1 A simple case: Single file · 5.1.2 Multiple files · 5.1.3 Large or extensive data · 5.2 Types of search methods · 5.2.1 Keyword search · 5.2.2 Vector search · 5.2.3 Graph search · 5.2.4 Structure-based search · 5.3 Practicing vector search · 5.3.1 Embedding: Converting text to vectors · 5.3.2 Chunking: Dividing long text into search units · 5.3.3 Implementing vector search · 5.3.4 Why vector databases are necessary · 5.3.5 Exercise: Finding relevant information from web search results · 5.4 Structure-based search · 5.4.1 Preparing the GAIA dataset · 5.4.2 Implementing filesystem tools · 5.4.3 Connecting tools to the agent · 5.4.4 Solving GAIA zip file problems · 5.5 Extending agents with callbacks · 5.5.1 The need for agent extension · 5.5.2 Implementing tool callbacks · 5.5.3 Human-in-the-loop tool-execution approval · 5.5.4 Compressing search results · 5.6 Summary

What you learn in chapter 5 →

Chapter 6: Adding memory to your agent

The chapter introduces why agents need memory and defines the context-growth problem that memory management must address.

6.1 The anatomy of agent memory · 6.1.1 Limitations of the current memory architecture · 6.1.2 Three challenges of the current memory architecture · 6.1.3 Context engineering and memory · 6.2 Managing context during execution · 6.2.1 Separating storage from presentation · 6.2.2 Sliding-window strategy · 6.2.3 Token counting · 6.2.4 Compaction strategy · 6.2.5 Summarization strategy · 6.2.6 Hierarchical context management · 6.3 Continuous execution: Session and state management · 6.3.1 The Session class · 6.3.2 Managing sessions with SessionManager · 6.3.3 Integrating sessions into the agent · 6.3.4 Basic example: Multiturn conversation · 6.3.5 Data structures for tool confirmation · 6.3.6 Extending tools for confirmation · 6.3.7 Implementing pause and resume in the agent · 6.3.8 Complete example: HITL workflow · 6.4 Long-term memory: Accumulating knowledge across sessions · 6.4.1 The structure of long-term memory · 6.4.2 Information extraction: Structured output · 6.4.3 Building a vector store with ChromaDB · 6.4.4 Implementing TaskMemoryManager · 6.4.5 Retrieving memories · 6.5 Summary

What you learn in chapter 6 →

Chapter 7: Planning and reflection for complex tasks

Introduces why a reactive agent can struggle with multistep tasks and how planning and reflection address different parts of that problem.

7.1 Giving agents time to think · 7.1.1 The limitations of ReAct · 7.1.2 How human experts work · 7.1.3 Why time to think matters · 7.2 Planning: Setting direction · 7.2.1 When planning is necessary · 7.2.2 Implementing the planning tool · 7.2.3 Planning-tool example · 7.2.4 Extension directions · 7.3 Reflection: Checking and correcting · 7.3.1 When reflection is necessary · 7.3.2 Implementing the reflection tool · 7.3.3 The real value of reflection: Failure recovery · 7.3.4 Running an agent that uses reflection for research synthesis · 7.4 Integrating planning and reflection · 7.5 Summary

What you learn in chapter 7 →

Chapter 8: Empowering agents with code execution

The introduction contrasts predefined tools with giving an agent an environment where its LLM can write and run code.

8.1 Giving agents a computer · 8.1.1 Limitations of the predefined-tool approach · 8.1.2 What code execution brings · 8.1.3 The effectiveness of code-based actions · 8.2 Connecting code environments · 8.2.1 Why sandboxes are necessary · 8.2.2 Introduction to E2B · 8.2.3 Connecting the sandbox to the agent · 8.2.4 Testing the code-execution agent · 8.3 Porting tools to sandboxes · 8.3.1 The need for tool portability · 8.3.2 Extending FunctionTool · 8.3.3 Implementing the Wikipedia revision tool · 8.3.4 Handling sandbox tools in the Agent · 8.3.5 Practical testing · 8.4 Workspace: Using filesystems and the CLI · 8.4.1 The workspace concept · 8.4.2 Implementing workspace tools · 8.4.3 Practical example: Analyzing an Excel file · 8.5 Agent skills · 8.5.1 The agent skills concept · 8.5.2 Progressive tool-information disclosure · 8.5.3 Implementation · 8.5.4 Practical example: PDF merge skill · 8.5.5 Hierarchical tool structure · 8.6 Summary

What you learn in chapter 8 →

Chapter 9: Orchestrating multi-agent systems

The introduction explains why growing task complexity motivates specialist agents and shows that the multi-agent system builds on the book’s existing Agent foundation.

9.1 Why multi-agent? · 9.2 Three collaboration patterns · 9.3 Agent workflow: Defining order in code · 9.3.1 Workflow design principles · 9.3.2 Sequential: Step-by-step execution · 9.3.3 Parallel: Concurrent execution · 9.3.4 Loop: Iterative execution · 9.3.5 Composing workflows · 9.4 Agent as Tool: Calling agents as tools · 9.4.1 Making agents into tools · 9.4.2 Implementing AgentTool · 9.4.3 Context isolation · 9.4.4 Practical example: Researcher and coder collaboration · 9.5 Agent Transfer pattern · 9.5.1 Differences between Agent as Tool and Transfer · 9.5.2 Transfer is also a tool · 9.5.3 Agent tree · 9.5.4 Implementing the transfer tool · 9.5.5 Implementing agent transfer · 9.6 A2A: Collaborating across networks · 9.6.1 The core of A2A: Agent card and task request/response · 9.6.2 Server: Exposing an agent to the network · 9.6.3 Client: Calling remote agents · 9.7 Summary

What you learn in chapter 9 →

Chapter 10: Evaluating agents

This introduction explains why agent autonomy makes rigorous, automated evaluation necessary and why defining success can be difficult.

10.1 Observing an agent · 10.1.1 Pillars of observability: Metrics, traces, and logs · 10.1.2 Generating, collecting, and exporting telemetry: OpenTelemetry · 10.2 Building datasets and establishing evaluation criteria · 10.2.1 What should we evaluate? · 10.2.2 Creating a dataset · 10.2.3 Analyzing errors · 10.2.4 Designing rubrics and metrics · 10.3 Evaluating with LLM-as-a-judge · 10.3.1 Types of LLM-as-a-judge · 10.3.2 Building a rubric-based evaluation system · 10.4 Operations: CI/CD · 10.4.1 Evaluation-gated deployment · 10.4.2 Improving the test set and evaluator: Agent quality flywheel · 10.5 Summary

What you learn in chapter 10 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.