Overview

3 Enabling actions: Tool use

LLMs are powerful at generating language, but they cannot reliably access fresh information, act on the outside world, or handle every specialized task on their own. This chapter explains why agents need tools to overcome those temporal, interaction, and functional limits, and it distinguishes among tools that add current information, tools that execute actions, and tools that handle domain-specific work like calculations or code execution. It also contrasts custom tools with provider-built tools, noting that built-in options are convenient for quick use, while custom tools are essential when you need specialized behavior, deeper debugging insight, or integration with proprietary systems.

The chapter then shows how tool use works in practice through tool calling. The LLM is given structured tool definitions describing each function, its purpose, and its parameters, and it responds with a tool call when it decides an external function is needed. The host application, not the model itself, executes the tool, captures the result, and feeds that result back into the conversation so the LLM can produce a final answer. Along the way, the chapter emphasizes design principles for reliable tool calling: make schemas explicit, avoid ambiguity and contradictory inputs, reduce unnecessary model burden, and keep the number of tools manageable so selection remains accurate.

After that foundation, the chapter builds a web search tool from scratch and wraps it in a tool schema, then automates schema generation from Python functions using introspection. It also presents an end-to-end agent loop that repeatedly asks the model whether it needs a tool, executes any requested tool, and returns the result until a final response is ready. Finally, the chapter introduces the Model Context Protocol as a standard way to discover and execute tools across systems, showing how MCP separates the agent host from tool servers, supports multiple transports, and makes tool reuse far easier. By the end, the reader sees how custom tools, tool calling, and MCP fit together to turn an LLM into a practical agent.

Book structure overview - Chapter 3 in focus.
The LLM receives user input, reasons about it, selects the necessary tool, receives the execution result, and produces a final response.
Key steps in tool calling–tool definition, delivery, and LLM tool selection, source: https://platform.openai.com/docs/guides/function-calling?api-mode=responses.
MCP makes it easy to extend an agent’s toolset by integrating third-party tools.
MCP server-client architecture. The Host contains the LLM for reasoning and user interaction, connecting through MCP Clients that manage server communication. MCP Servers expose tool definitions and handle execution, optionally integrating with external services like databases and APIs.
MCP Inspector startup log showing the server initialization and connection URL.
MCP Inspector interface showing the official Tavily MCP server, which provides a richer set of tools, including tavily-search, tavily-extract, tavily-crawl, and tavily-map.

Summary

  • Tools extend LLM capabilities, enabling them to access APIs, perform calculations, and retrieve external information. Tools fall into three categories: information-augmenting, action-executing, and domain-specialized.
  • Tool calling is the mechanism by which LLMs generate structured outputs specifying which tool to use and with what parameters. The LLM acts as a mediator between user requests and available tools, but does not execute tools itself.
  • Tool execution is handled externally. The LLM generates specifications that a separate system executes, with results fed back into the LLM's context for further reasoning.
  • Tool definitions are structured schemas that describe available tools, their parameters, and expected outputs. Clear and explicit definitions are essential for reliable tool selection by the LLM.
  • Building custom tools involves implementing the tool function, creating tool definitions, and building execution infrastructure. While straightforward for simple cases, custom tools create a maintenance burden and inconsistency as projects scale.
  • MCP (Model Context Protocol) standardizes tool development through a server-client architecture. Servers host and execute tools, while clients discover and invoke them. This separation enables tool reuse across projects and providers.

FAQ

Why do LLMs need tools to become agents?LLMs on their own cannot access fresh external information or directly act on the world. Tools let them retrieve current data, perform actions, and handle specialized tasks, which is what enables agent-like behavior.
What are the three main limitations of LLMs discussed in this chapter?The chapter describes three limitations: temporal limitations, meaning they cannot access information beyond their training data; interaction limitations, meaning they cannot directly affect external systems; and functional limitations, meaning they are weak at tasks like precise computation or code execution.
What is the difference between information-augmenting tools and action-executing tools?Information-augmenting tools bring up-to-date knowledge into the LLM’s context, such as search engines or live APIs. Action-executing tools actually perform operations in the external world, such as sending emails, booking flights, or controlling devices.
Why does the book focus on custom tools instead of only provider-built tools?Custom tools are important because they can be tailored to specific needs like internal databases or proprietary APIs, and understanding them helps with debugging. Provider tools are useful too, but they are often black boxes and cannot always be modified to fit specialized workflows.
How does tool calling work in an LLM application?The application sends the model both the user request and the tool definitions. The LLM then chooses whether a tool is needed and outputs a structured tool call. The host system executes the tool, returns the result to the LLM, and the model uses that result to produce a final answer.
What should a good tool definition include?A good tool definition should clearly specify the tool name, a description of when to use it, and a JSON Schema for its parameters. The schema should make required inputs, allowed values, and data types explicit so the LLM can call the tool reliably.
How does the calculator tool example demonstrate tool selection?When asked a question the model already knows, such as a capital city, it answers directly without calling a tool. When asked a computation like 1234 × 5678, it generates a tool call for the calculator with the correct operator and numbers.
How can Python functions be converted into tool definitions automatically?The chapter shows that you can use Python’s inspect module to read a function’s name, docstring, signature, and parameter types. A helper function can then transform that metadata into a standard tool schema automatically.
What is MCP and why is it useful for tool standardization?MCP, the Model Context Protocol, is a standard that makes tools easier to discover, share, and execute across different LLM applications. It reduces duplicated work, improves reuse, and lets agents connect to compatible tools without custom integration logic every time.
What is the difference between an MCP Host, Client, and Server?The Host is the agent application that reasons with the LLM and talks to the user. The MCP Client bridges the Host and a server by requesting tool definitions and forwarding execution requests. The MCP Server hosts and runs the actual tools, returning results in a standardized format.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build an AI Agent (From Scratch) ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build an AI Agent (From Scratch) ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build an AI Agent (From Scratch) ebook for free