Example: Adding a Calculator to Our Agent › Common Pitfalls and Solutions

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 › Common Pitfalls and Solutions
Reading section 13 of 16 · Common Pitfalls and Solutions · 1 minSection 13 of 16 · 1 min

Book contents

Section 13 of 16 · 1 min read

Example: Adding a Calculator to Our Agent › Common Pitfalls and SolutionsOne section · Sections in this chapter13 / 16 ↓

As you build your own tools, watch out for these common issues:

Pitfall: Tool descriptions are too vague

❌ Bad: "description": "Does math stuff"

✅ Good: "description": "Perform precise mathematical calculations including addition, subtraction, multiplication, division, and exponentiation"

The agent uses the description to decide when to use the tool. Be specific.

Pitfall: Parameter examples are missing

❌ Bad: "expression": {"type": "string", "description": "A math expression"}

✅ Good: "expression": {"type": "string", "description": "Math expression using +, -, *, /, **. Examples: '1234 * 5678', '100 + 50 - 25'"}

Examples help the agent format inputs correctly.

Pitfall: Error handling is missing

❌ Bad: Let exceptions crash the program

✅ Good: Catch exceptions and return structured error information

The agent can work with error messages. It can't work with crashes.

Pitfall: Outputs are unstructured

❌ Bad: return "The answer is 42"

✅ Good: return {"success": True, "result": 42}

Structured outputs give the agent flexibility in how it presents information.