Example: Adding a Calculator to Our Agent › Step 2: Define the Tool Description

Michael BrenndoerferJune 29, 20251 min read
AI Agent HandbookAll chapters
Part 5 of 15Tool Use - Extending the Agent's Abilities
Chapter 14Example: Adding a Calculator to Our Agent › Step 2: Define the Tool Description
Reading section 4 of 16 · Step 2: Define the Tool Description · 1 minSection 4 of 16 · 1 min

Book contents

Section 4 of 16 · 1 min read

Example: Adding a Calculator to Our Agent › Step 2: Define the Tool DescriptionOne section · Sections in this chapter4 / 16 ↓

The agent needs to understand what this tool does and how to use it. We create a tool description following the format we learned in the previous chapter:

In[5]:
Code
calculator_tool = {
    "name": "calculate",
    "description": "Perform precise mathematical calculations. Use this for any arithmetic operations including addition, subtraction, multiplication, division, and exponentiation.",
    "input_schema": {
        "type": "object",
        "properties": {
            "expression": {
                "type": "string",
                "description": "The mathematical expression to evaluate. Use standard operators: + (add), - (subtract), * (multiply), / (divide), ** (power). Examples: '1234 * 5678', '100 + 50 - 25', '2 ** 8'"
            }
        },
        "required": ["expression"]
    }
}

This description tells the agent:

  • What the tool does: Perform precise mathematical calculations
  • When to use it: For any arithmetic operations
  • What input it needs: A mathematical expression as a string
  • How to format the input: Examples of valid expressions

The examples are crucial. They help the agent understand how to extract the math problem from the user's question and format it correctly.