chapter four
4 Implementing a basic ReAct agent
This chapter covers
- Understanding ReAct, the core pattern behind modern AI agents
- Managing agent state with
ExecutionContext - Unifying local functions and MCP tools
- Building the LLM communication layer and implementing a
ToolCallingAgentwith the think-act loop - Adding structured output and testing agent performance against the GAIA benchmark
We’ve explored how LLMs work and given them the ability to use tools. Now it’s time to combine these pieces into something more powerful: an agent that can reason about what it needs, take action to get it, and continue until it solves the problem.
As shown in figure 4.1, we’ll complete the foundation of the basic agent loop by building an agent using the ReAct pattern, chaining multistep reasoning and actions to solve problems end to end, and adding robust error handling. ReAct (reasoning and acting) isn’t a framework but a way of designing agents that mirrors how humans solve problems: assess the situation, decide what information or action is required, execute that action, observe the results, and repeat.
Figure 4.1 Book structure overview: chapter 4