liveBook · Manning

Tool

As explained in AI Agents in Action, Second Edition

A software tool is a capability or utility that enables a person or system to perform a defined task or operation.

A tool is a capability an agent can use to perform a task: think of it as the agent’s hands or senses. A tool is the capability; an action is what the agent does with it. Tools can be local functions, external services, or even handoffs to other agents. section 2.4.1 section 11.1.2

Unlike a model that only generates text, a tool-using assistant can search the web or create an image. An agent can go further: it plans several tasks, selects tools, observes their results, and decides what to do next. A tool’s output can also become input to another tool, a pattern called tool chaining. section 1.1.1 section 1.1.2

Tools serve different purposes in an agent’s workflow:

  • Context retrieval tools fetch information, such as search results or file contents, without changing external state. section 1.3.2
  • Knowledge and memory tools read and write the agent’s persistent stores; task completion tools act in the world. section 1.3.2
  • Other tools can support reasoning, planning, evaluation, and feedback. section 1.3.2

A tool often wraps a function that calls an API, database, or external application. To use it, an agent needs a description of what it does, its inputs, and how to handle its output. Frameworks can generate a tool description from an annotated function. Instructions can also say when to use it. section 1.1.3 section 2.4.1

Planning research with a tool

A research planning agent can call get_research_sources to obtain a list of available sources, then produce tasks constrained to those sources. A simple implementation returns a static list; the function can later be extended to query available resources. section 2.4.1

Model Context Protocol (MCP) offers another way to discover and use tools hosted locally or remotely. In MCP, tools are actionable capabilities the model can choose to invoke; resources provide data, while prompts provide reusable templates. section 2.4.1 section 3.1.3

Design tools for reliable use:

  • Give each tool a focused responsibility, a clear name and description, and typed inputs. Tell the agent when to use it. section 11.1.2
  • Keep the tool set small: each registered tool description adds context and token overhead, even when unused. section 2.4.1 section 11.1.2
  • Treat failures as normal control flow. Return useful errors, limit retries, and allow the agent to fall back, ask the user, or abandon the task. section 1.1.3
  • Set approval boundaries for consequential actions. For example, sending email, purchasing, or deleting records may require explicit approval even in an otherwise autonomous agent. section 1.1.1
Listing 11.2 02_tool_action_tips.py
from agents import (
    Agent, 
    Runner, 
    function_tool, 
    ModelSettings
)
import json

def _failure_error_function(context, e) -> str:        #1
    return json.dumps({"status": "error", "message": str(e)})

@function_tool(
    failure_error_function=_failure_error_function)    #1
def lookup_order(order_id: str) -> dict:   #2
    """Check order status by ID. Use when the user asks about their order."""         #2
    if not order_id.startswith("ORD-"):
        raise ValueError("Invalid order id format")
    return {"status": "shipped", "eta_days": 3}


tooling_agent = Agent(
    name="ToolingAgent",
    instructions="Use tools when needed; respond with JSON.",    #3
    tools=[lookup_order],
    model_settings=ModelSettings(
        tool_choice="auto",    #3
        parallel_tool_calls=True,     #3
    )
)
print(Runner.run_sync(
    tooling_agent, 
    "What's the status of order ORD-123?"
).final_output)

Inspect a focused order-lookup tool with a typed parameter, input validation, and an error handler. section 11.1.2

How AI Agents in Action, Second Edition covers it

How deep it goes
Explains tool registration, categories, chaining, and design guidelines, including failure handling and tool-set size.
Examples
Uses research-source lookup, order-status validation, and image generation to illustrate tool use.
What you can do after
Apply it via the OpenAI Agents SDK to register a function tool and handle its failures.
How it connects
Connects tools to agentic loops, planning, memory, tool chaining, and Model Context Protocol.

Also explained in

Compare how 14 books explain tool →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.