chapter eight

8 Empowering agents with code execution

 

This chapter covers

  • Limitations of predefined tool approaches and benefits of code execution
  • Connecting code execution environments to agents
  • Porting tools to sandboxes for efficient execution
  • Providing complete workspaces with file systems and CLI
  • Agent skills for hierarchical tool management

So far, we've built agents that register tools and have the LLM select and call appropriate tools. This approach is predictable and easy to control, but it reveals clear limitations when faced with complex real-world problems. Let’s explore a completely new approach: instead of creating individual functions as tools, we provide an "execution environment" where the LLM can directly write and run code. This is what it means to give an agent a "computer."

As shown in figure 8.1, we are now ready to enhance agents with context engineering strategies. We’ll focus on Agent Workspace, providing agents with the same working environment that human developers use.

Figure 8.1 Chapter 8 position in the book: providing agents with complete workspaces.

8.1 Giving agents a computer

8.1.1 Limitations of predefined tool approaches

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 and basic usage

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 file systems and CLI

8.4.1 The concept of Workspace

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