liveBook · Manning

Tool description

As explained in Context Engineering

A tool definition specifies a tool's name, purpose, and expected arguments so a system can determine how to invoke it.

A tool definition is an operational contract between an LLM and the code that executes its actions. Its name, purpose, and argument schema help the model decide when and how to invoke the tool. The definition enters the context window; a tool call and its execution output can then add further context. section 4.2.1 section 1.5.3

A robust definition specifies:

  • A unique, stable name and a description that states when, why, and under what conditions to use the tool. section 4.2.1
  • A strictly typed parameter schema with clear field names and explicit constraints. section 4.2.1
  • The expected output structure and actionable error responses that help the agent recover from invalid arguments. section 4.2.1

Keep the definition distinct from the tool call—the structured request the model emits—and from the output returned after execution. Definitions guide selection and argument formation; calls and outputs usually join the working context, while only relevant outputs may later be persisted as memory. section 1.5.3

Weather lookup

A function definition can name get_weather, describe its purpose, and require a location string. The model requests the function; code executes it and returns the weather value to the context for the final response. section 4.6.1

Listing 4.1 Python script using an OpenAI model and a mock weather tool
from openai import OpenAI
import json

client = OpenAI()

TOOLS = [{ #1
    "type": "function",
    "name": "get_weather", #2
    "description": "Get the current weather in a location",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {
                "type": "string",
                "description": "City or place name"
            }
        },
        "required": ["location"]
    }
}]

def query_model(prompt, model="gpt-4o-mini"):
    response = client.responses.create( #3
        model=model,
        input=prompt,
        tools=TOOLS,
        tool_choice="required",
    )
    input_items = list(response.output)
    for item in response.output: #4
        if item.type != "function_call":
            continue
        function_name = item.name
        function_args = json.loads(item.arguments)
        result = route_function_call(function_name, function_args) #5
        input_items.append({
            "type": "function_call_output",
            "call_id": item.call_id,
            "output": json.dumps(result),
        })
    final_response = client.responses.create( #6
        model=model,
        input=input_items,
        tools=TOOLS,
    )
    return final_response.output_text

Inspect the Python example to see a function schema passed to the OpenAI API and the requested function executed in an agent loop. section 4.6.1

How Context Engineering covers it

How deep it goes
Specifies five contract elements, from naming and parameter constraints to output and error schemas.
Examples
Uses a weather lookup and a bug investigation combining a function call, shell command, and MCP documentation.
What you can do after
Build a function-calling loop that sends a definition, executes the requested function, and returns its result to the model.
How it connects
Connects tool definitions to function calling, tool calls, execution outputs, and context windows.

Also explained in

Compare how 4 books explain tool description →

Related concepts

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