Example: Adding a Calculator to Our Agent › Step 5: Test When Tools Aren't Needed

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 5: Test When Tools Aren't Needed
Reading section 7 of 16 · Step 5: Test When Tools Aren't Needed · 1 minSection 7 of 16 · 1 min

Book contents

Section 7 of 16 · 1 min read

Example: Adding a Calculator to Our Agent › Step 5: Test When Tools Aren't NeededOne section · Sections in this chapter7 / 16 ↓

An important part of tool use is knowing when not to use a tool. Let's test that:

In[8]:
Code
## Test 4: Simple math the agent can handle
print("Test 4: Simple math")
print(run_agent_with_calculator("What's 2 plus 2?"))
print()

## Test 5: General knowledge
print("Test 5: General knowledge")
print(run_agent_with_calculator("What's the capital of France?"))
Out[8]:
Console
Test 4: Simple math
Agent is using tool: calculate
Tool input: {'expression': '2 + 2'}
Tool result: {'success': True, 'result': 4, 'expression': '2 + 2'}
2 plus 2 equals **4**.

Test 5: General knowledge
The capital of France is **Paris**.

Paris is not only the capital but also the largest city in France, known for its iconic landmarks like the Eiffel Tower, the Louvre Museum, Notre-Dame Cathedral, and its rich history, culture, and cuisine.
Test 4: Simple math
2 plus 2 equals 4.

Test 5: General knowledge
The capital of France is Paris.

Notice that the agent didn't use the calculator for these questions. For "What's 2 plus 2?", it answered directly because this is trivial arithmetic. For "What's the capital of France?", it recognized this isn't a math problem at all.

This shows the agent's intelligence. It's not mechanically using tools for everything. It's reasoning about when tools are necessary.