Designing Simple Tool Interfaces › The Anatomy of a Tool

Michael BrenndoerferJune 25, 20252 min read
AI Agent HandbookAll chapters
Part 5 of 15Tool Use - Extending the Agent's Abilities
Chapter 13Designing Simple Tool Interfaces › The Anatomy of a Tool
Reading section 3 of 12 · The Anatomy of a Tool · 2 minSection 3 of 12 · 2 min

Book contents

Section 3 of 12 · 2 min read

Designing Simple Tool Interfaces › The Anatomy of a ToolOne section · Sections in this chapter3 / 12 ↓

Let's break down what a tool actually consists of. We'll use a simple weather tool as our example:

The Tool Function

At its most basic, a tool is just a Python function:

In[3]:
Code
def get_weather(city: str) -> dict:
    """Get current weather for a city."""
    # In reality, this would call a weather API
    # For now, we'll return mock data
    return {
        "city": city,
        "temperature": 72,
        "conditions": "partly cloudy",
        "humidity": 65
    }

This function takes a city name and returns weather information. Simple enough. But how does the agent know this function exists? How does it know what parameter to pass? That's where tool descriptions come in.

The Tool Description

The agent needs metadata about the tool. Think of this as the function's documentation, but in a format the agent can understand:

In[4]:
Code
weather_tool = {
    "name": "get_weather",
    "description": "Get current weather conditions for a specified city",
    "parameters": {
        "city": {
            "type": "string",
            "description": "The name of the city (e.g., 'Tokyo', 'New York', 'London')"
        }
    }
}

This description tells the agent:

  • What the tool does: "Get current weather conditions"
  • What it's called: get_weather
  • What inputs it needs: A city name (string)
  • What the parameter means: Examples help the agent understand the format

With this information, the agent can decide whether this tool is appropriate for a given question and extract the necessary parameters.

The Tool Registry

If you have multiple tools, you need a way to organize them. A simple registry is just a dictionary mapping tool names to their functions:

In[6]:
Code
tool_registry = {
    "get_weather": get_weather,
    "calculate": calculate,
    "search_web": search_web
}

When the agent decides to use a tool, it looks up the function in this registry and calls it with the appropriate parameters.