liveBook · Manning

Chapter 3: Enabling actions: Tool use

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

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

After this chapter you will be able to

What it builds on

Section by section

Introduction

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

Key terms: LLMs, tools, agent, next action, Tool info, tool execution, context, final answer

3.1 LLM tools

This section explains why LLMs need tools by identifying three limitations that prevent them from acting as fully autonomous agents.

Key terms: temporal, interaction, functional, tools

3.1.1 Why do we need LLM tools?

This section explains why agents need three kinds of tools: to obtain current information, act on the world, and perform specialized tasks reliably.

Key terms: information-augmenting tools, temporal gap, training cutoff, agent’s context, action-executing tools, interaction limitation, observations, feedback loop, domain-specialized tools, functional limitations

3.1.2 Types of LLM tools

This section contrasts developer-built and provider-supplied LLM tools and explains why custom tools remain valuable despite convenient built-in options.

Key terms: custom tools, noncustom tools, built-in tools, LLM provider, tool selection, domain-specific logic

3.2 How LLMs use tools

Introduces how a text-generating LLM uses tool definitions to request actions that an external executor performs.

Key terms: tool calling, tool definition, tool call, external executor, arguments

3.2.1 How tool calling works

This section explains how an LLM requests a tool call, how the host application executes it, and how the result returns to the LLM for a final answer.

Key terms: tool definitions, type, function, name, description, parameters, tool_calls, content, tool call, host system

3.2.2 How an LLM chooses tools

This section explains how training on tool-use examples enables an LLM to choose a tool and produce a structured call with the right inputs.

Key terms: tool definitions, tool calls, parameter values, structured data, function names and arguments

3.2.3 Guidelines for effective tool calling

The section gives practical schema-design guidelines that make LLM tool calls clearer, less error-prone, and easier for application code to handle.

Key terms: tool schema, function names, parameter descriptions, required and optional parameters, mutually exclusive Booleans, enum, schema, validate ranges and formats, order_id, decision input

3.3 Building tools and tool definitions for LLMs

Introduces the upcoming exercise of building a web search tool from scratch.

3.3.1 Implementing a web search tool

This section builds a Tavily-backed web search function, then adds search options and basic error handling.

Key terms: TavilyClient, load_dotenv(), TAVILY_API_KEY, search_web, max_results, topic, time_range, tool definition, try-except, list | str

3.3.2 Converting to tool definitions

This section explains why Python tools need standardized definitions for LLM access and how to generate those definitions automatically from function metadata.

Key terms: tool definition, standardized tool-definition format, utility function, inspect, __name__, __doc__, inspect.signature, parameter types, required arguments

3.3.3 End-to-end tool execution

This section connects LLM tool calls to registered functions, then uses a conversation loop to return tool results to the LLM until it can answer.

Key terms: toolbox, tool call, tool name, arguments, control loop, tool definitions, conversation history, tool message, current information, search_web

3.3.4 The challenges of custom tools

This section explains why custom LLM tools become difficult to build, share, and maintain at scale, motivating a common standard for tools.

Key terms: Tavily, API conventions, response formats, error handling, rate limits, backoff strategies, input validation, tool definitions, synchronous, asynchronous

3.4 MCP: Standardizing tools

This section explains how MCP standardizes tool integration so agents can reuse third-party tools without custom wrappers.

Key terms: MCP, MCP-compatible agent, MCP-compatible tool, custom tool wrappers

3.4.1 The core of MCP: Server–client architecture

This section explains how MCP separates an LLM-powered host from tool servers through clients, standardizes tool discovery and execution, and supports local or remote communication.

Key terms: host, MCP client, MCP server, tool discovery, tool execution, tool definitions, schema, stdio, standard I/O, streamable HTTP

3.4.2 Hands-on: Running an MCP server

Walks through running the ready-made Tavily MCP server, testing its tools in MCP Inspector, and showing the benefit of standardized tools.

Key terms: Node.js, Tavily API key, npx, MCP Inspector, tavily-mcp@latest, Connect, Tools, List Tools, tavily_search, parameter schema

3.4.3 Understanding the MCP client

This section shows how an MCP client connects to a server, discovers and invokes its tools, and converts their definitions for an LLM provider.

Key terms: MCP client, stdio_client, ClientSession, initialize(), list_tools(), call_tool(), MCP schema format, inputSchema, JSON schema, format_tool_definition

3.4.4 Hands-on: Implementing an MCP server

Shows how to expose an existing search function through a custom MCP server, connect to it with a familiar client, and see how MCP separates tool implementation from tool use.

Key terms: FastMCP, search_web, @mcp.tool(), tool schema, docstring, stdio, StdioServerParameters, tool discovery, tool execution, MCP

3.5 Summary

Summarizes how tools extend LLMs, how tool calls become externally executed actions, and why MCP helps standardize tools.

Where this is used later

Concepts explained in this chapter

← Chapter 2: The brain of AI agents: LLMs Chapter 4: Implementing a basic ReAct agent →

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.