liveBook · Manning

Tool

As explained in Hugging Face in Action

A tool is an executable capability that an agent or language-model application can invoke to perform a task or access external functionality.

A tool is an executable capability that an agent or language-model application invokes to perform actions or access external functionality. Standardized interfaces let agents use search services, calculators, databases, files, and APIs without embedding each integration in the agent itself. section 9.3.1 section 13.1.4

from langchain_core.tools import Tool
from langchain_community.utilities import SerpAPIWrapper

os.environ["SERPAPI_API_KEY"] = "<SERPAPI_KEY>"          #1
serpapi = SerpAPIWrapper()                               #2
search_tool = Tool(
    name = "SerpAPI",                                    #3
    func = serpapi.run,                                  #4
description = "A search engine tool to query real-time information
                   from the web."
)

Wrap a SerpAPIWrapper in a LangChain Tool, give it a name, connect its run function, and describe its purpose and expected input. section 9.4.3

Utility wrappers are not directly available to agents: embed each wrapper in a Tool instance before adding it to an agent’s toolset. The description matters because the language model uses it to decide whether and how to call the tool. section 9.3.1 section 9.4.3

A useful tool integration specifies:

  • A callable function that performs one focused action and returns usable data or an error. section 13.2.7
  • A name and description that identify the capability, its purpose, and the input it expects. section 9.3.1 section 9.4.3
  • An execution path in which the agent decides whether to call the tool, receives its result, and produces a final response. section 9.4.3
  • A protocol boundary when using MCP, where tools are distinct from resources and prompts and use standardized JSON-RPC requests. section 13.1.4

Search-enabled agent

Configure SerpAPI and OpenAI credentials, create a Search Tool from SerpAPIWrapper, and pass it to initialize_agent(). For a question about current events or a person, the agent can issue a search query, inspect the returned observation, and formulate an answer. The same pattern supports current-weather queries and structured weather results. section 9.3.1

MCP tools extend the pattern beyond LangChain. Register functions with @mcp.tool(); examples fetch weather, convert temperature, and retrieve PDF or text-file contents. The MCP Inspector can list and run these tools to validate their behavior. section 13.2.7 section 13.2.9

How Hugging Face in Action covers it

How deep it goes
Defines interfaces, wrapping, descriptions, execution flow, MCP registration, and testing, but stops short of implementation internals.
Examples
Demonstrates SerpAPI search, weather retrieval, temperature conversion, PDF and text access, and election lookup.
What it assumes
Assumes Python and service credentials; teaches utility wrapping, tool descriptions, and MCP registration explicitly.
What you can do after
Build it from scratch by registering MCP functions, or apply it through LangChain and LangGraph agent APIs.
How it connects
Connects agents, LLMs, LangChain, LangGraph, MCP servers, resources, prompts, APIs, and JSON-RPC 2.0.

Also explained in

Compare how 14 books explain tool →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Hugging Face in Action. The section links point to the parts of the book it draws on.