Part 7 · 7 chapters

The Core of AI Agents

This is the heart of the book. You will learn the building blocks every agent shares: the reasoning-and-acting loop, tools, memory, planning, and retrieval-augmented generation.

Chapter 31The Core of AI Agents

Anatomy of an Agent: Perception, Reasoning, and Action

Welcome to the heart of the book. Everything so far — how models work, how they are trained, how to use them, and the tool calling of Chapter 29 — was preparation for this part, where we finally build agents in earnest. We begin by laying out the complete anatomy of an agent, expanding the tiny loop from Chapter 1 into a full architecture and naming every component you will build in the chapters ahead. By the end you will have a clear mental blueprint of what an agent *is*, made of parts you already understand, and a working loop in code. This chapter is the map for all of Part VII.

Chapter 32The Core of AI Agents

The ReAct Pattern: Reasoning + Acting

In the last chapter we built the agent loop. Now we sharpen the reasoning-and-acting cycle into a specific, powerful pattern called **ReAct** — short for Reasoning + Acting — which was the breakthrough that first made tool-using agents genuinely reliable. The idea is simple to state and surprisingly deep: instead of thinking everything through up front or acting blindly, the agent alternates between thinking and acting, one step at a time. We will implement it from scratch and trace it in detail, so you understand not just how it works but why it works so well.

Chapter 33The Core of AI Agents

Tool Use: Giving Agents Hands

Tools are how an agent reaches out and affects the world — the hands attached to the model's brain. Chapter 29 introduced the mechanism of tool calling; this chapter is about the craft of *building* tools well: designing them so the model uses them correctly, validating what the model sends, handling the inevitable failures, and keeping everything safe. Good tools are the difference between an agent that reliably gets things done and one that flails. We will build several real tools and cover the practices that make them dependable.

Chapter 34The Core of AI Agents

Memory: Short-Term, Long-Term, and Episodic

An agent that forgets everything the moment it finishes a step cannot pursue a goal, hold a conversation, or learn from experience. Memory is what gives an agent continuity — the ability to carry context across steps and across sessions. This chapter builds the main kinds of agent memory from the ground up, explains when each is needed, and reveals a satisfying connection: long-term memory for agents turns out to be the retrieval you already learned, applied to the agent's own past. By the end you will know how to give an agent a working memory and a lasting one.

Chapter 35The Core of AI Agents

Planning and Task Decomposition

Some goals are too big to accomplish in a single step. "Research a topic and write a report" is not one action but dozens, and an agent that tries to do it all at once will flounder. Planning is how an agent tackles such goals: by breaking them into smaller, achievable pieces and working through them. This chapter covers task decomposition, the two broad styles of planning, and the crucial tension between planning ahead and adapting as you go — a tension you have already glimpsed in ReAct. Planning is where the components of Part VII come together to handle real complexity.

Chapter 36The Core of AI Agents

Retrieval-Augmented Generation (RAG)

A language model is a brilliant mind locked in a room with no library. It knows nothing about your company's documents, last week's meeting notes, or the PDF sitting on your desktop — and when you ask it about something it has not seen, it will sometimes invent a confident, fluent, and completely wrong answer. *Retrieval-Augmented Generation*, or RAG, is the single most important technique for fixing both problems at once. In this chapter we build a complete RAG pipeline from scratch, one stage at a time, so that you understand every moving part before any framework hides them from you.

Chapter 37The Core of AI Agents

Vector Databases and Semantic Search

We close the core of agents with the storage layer that quietly powers two of its most important capabilities. Both the RAG of Chapter 36 and the agent memory of Chapter 34 work by storing embeddings and finding the most similar ones — and when you have more than a handful of items, you need a specialized tool to do that quickly: a vector database. This chapter explains what one is, why a plain list does not scale, how vector databases achieve their speed, and how to use one in practice. It is the infrastructure beneath retrieval and memory, and it completes Part VII.

← Part 6Part 8