liveBook · Manning

Tool description

As explained in Build an AI Agent (From Scratch)

A tool definition is a structured declaration of a callable tool's name, description, parameters, types, and required arguments for access by a language model.

A tool description tells a language model what a callable tool does, when to use it, and which inputs it needs. It is part of a structured tool definition sent with a request—not the code that performs the action. Clear descriptions improve tool selection; vague ones can cause a tool to be called at the wrong time or ignored. System-prompt guidance about tool use is a separate, complementary task. section 2.3.2 section 3.2

For a callable function, define:

  • A name the model can put in a tool call, plus a description of the tool’s purpose and appropriate use. section 3.2.1
  • A parameters object with each input’s name, type, and description; use constraints such as an enum where appropriate. section 3.2.1
  • A required list for inputs that must appear in the call. section 3.2.1
Listing 3.1 Calculator tool definition schema
calculator_tool_definition = { 
    "type": "function",
    "function": {
        "name": "calculator", 
        "description": "Perform basic arithmetic operations.",
        "parameters": {
            "type": "object",
            "properties": {
                "operator": {
                    "type": "string",
                    "description": "Arithmetic operation to perform",
                    "enum": ["add", "subtract", "multiply", "divide"]
                },
                "first_number": {
                    "type": "number",
                    "description": "First number for the calculation"
                },
                "second_number": {
                    "type": "number",
                    "description": "Second number for the calculation"
                }
            },
            "required": ["operator", "first_number", "second_number"],
        }
    }
}

The calculator definition shows the outer function declaration, its name and purpose, and a JSON-schema-style parameters object. section 3.2.1

From definition to execution

Given a calculator definition, a capital-city question can receive a direct answer, while “What is 1234 x 5678?” produces a calculator call with `operator="multiply"` and two numbers. The model generates the call; application code executes the function and returns its result to the model for the final answer. Supplying a definition alone does not execute anything. section 3.2.1 section 3.2

Definitions can be generated from Python functions rather than maintained by hand. Read `__name__` and `__doc__` for the name and description; use `inspect.signature` to map annotated parameters to schema types and defaults to optional arguments. Check the generated definition when functions change: a stale manual schema can misrepresent the callable function. section 3.3.2

Listing 3.18 Converting functions to tool definitions
def format_tool_definition(name: str, description: str, parameters: dict) -> dict:
    return {
        "type": "function",
        "function": {
            "name": name,
            "description": description,
            "parameters": parameters,
        },
    }

def function_to_tool_definition(func) -> dict:
    return format_tool_definition(
        func.__name__,
        func.__doc__ or "",
        function_to_input_schema(func)
    )

function_to_tool_definition(search_web)
# {'type': 'function', 'function': {'name': 'search_web', 
# ➥'description': 'Search the web for the given query.', 
# ➥'parameters': {'type': 'object', 'properties': 
# ➥{'query': {'type': 'string'}}, 'required': ['query']}}}

The conversion utility assembles a callable function’s name, docstring, and generated input schema into one tool definition. section 3.3.2

A definition also controls exposure. An MCP client can discover names, descriptions, and input schemas from a server, then convert them to an LLM provider’s format. In an agent, a tool whose `tool_definition` is `None` stays off the model’s callable-tool list while still being able to inject memories before a request. section 3.4.3 section 6.4.5

How Build an AI Agent (From Scratch) covers it

How deep it goes
Works through schema fields, Python-based generation, external execution, and MCP conversion rather than stopping at a definition.
Examples
Uses a calculator schema and multiplication trace, a generated web-search definition, and MCP tool discovery.
What it assumes
Assumes basic Python functions and LLM requests while explaining tool calling and structured definitions from the ground up.
What you can do after
Build it from scratch by declaring a function schema or generating one from Python metadata, then passing it into a tool-calling workflow.
How it connects
Connects tool calling, JSON Schema, Python introspection, MCP, and agent memory retrieval.

Also explained in

Compare how 2 books explain tool description →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build an AI Agent (From Scratch). The section links point to the parts of the book it draws on.