Lesson 8 of 9 · Doing It Well
Tool Selection With Many Tools
When a model has dozens of tools: higher costs and wrong picks. Keep tool sets small with grouping, routing and tool search, and use tool_choice wisely.
- 5 min read
- Intermediate
- Reviewed
- Explain why large tool sets cause cost and accuracy problems
- Send only the relevant tools for each request with tool search
- Use grouping, routing and tool choice settings
- Measure how well a model picks tools
More tools, more problems
It's tempting to give a model every tool you have. But every tool definition is sent with every request, and every extra option is another chance to pick the wrong one. As tool lists grow into the dozens:
- Cost and speed rise: definitions can add thousands of tokens to each request.
- Accuracy drops: similar tools get confused, and rarely used ones are forgotten.
- Risk grows: a model that doesn't need a powerful tool for a task shouldn't have access to it.
Send only what's relevant
import re
TOOLS = {
"orders_lookup": "Look up an order's status, items and delivery date by order ID.",
"orders_cancel": "Cancel an order that has not shipped yet.",
"orders_refund": "Refund all or part of a delivered order's payment.",
"account_reset_password": "Send a password reset link to the user's email.",
"account_update_address": "Change the delivery address saved on the account.",
"account_delete": "Permanently delete the user's account and data.",
"products_search": "Search products by keyword, category and maximum price.",
"products_stock": "Check whether a product is in stock in a given size.",
"shipping_track": "Track a parcel with the courier's tracking number.",
"shipping_rates": "Get delivery prices and times for a postcode.",
"loyalty_points": "Show the user's loyalty points balance and history.",
"store_hours": "Opening hours of a physical store by city.",
}
STOP = {"the", "and", "for", "with", "has", "not", "yet", "all", "want", "user", "its", "that", "this"}
def words(text):
return {w[:5] for w in re.findall(r"[a-z]+", text.lower()) if len(w) > 2 and w not in STOP} # crude stemming
def pick_tools(request, k=3):
"""Send the model only the k tools whose descriptions best match the request."""
scores = {name: len(words(request) & words(name.replace("_", " ") + " " + desc)) for name, desc in TOOLS.items()}
matching = [n for n in scores if scores[n] > 0]
return sorted(matching, key=lambda n: (-scores[n], n))[:k]
for request in ["I want my money back for order A-1034",
"I forgot my password",
"Is the blue raincoat in stock in size M?"]:
print(f"{request!r}\n -> {pick_tools(request)}")
all_chars = sum(len(n) + len(d) + 120 for n, d in TOOLS.items()) # ~120 characters of schema each
print(f"\nAll {len(TOOLS)} tools: about {all_chars // 4} tokens per request; 3 tools: about {3 * all_chars // len(TOOLS) // 4}")The password request gets exactly one tool; the stock question gets one; the refund request gets the three order tools, including the right one. Notice that “money back” doesn't share a word with “refund”, and only got there because “order” matched. Embeddings (from the Embeddings course) would match by meaning, which is how production tool search usually works.
Other ways to keep choices clear
| Technique | How it works | Good for |
|---|---|---|
| Grouping | Prefixes like orders_, account_, products_ | Making related tools easy to tell apart |
| Routing | Classify the request first, then load that area's tools | Large systems with distinct areas |
| Fewer, broader tools | One orders tool with an action enum instead of six tools | Closely related operations |
| Tool choice | Force a specific tool, require some tool, or forbid tools | Extraction, or steps where tools aren't wanted |
| Sub-agents | A specialist agent with its own small tool set | Complex domains |
Common mistakes
Estimate how many tokens tool definitions use per day, with and without sending only the relevant tools.
tools_available = 40 tokens_per_tool = 150 # name + description + schema requests_per_day = 20_000 tools_sent_with_search = 5 # after picking only the relevant tools # Print the tool-definition tokens sent per day in each case, with thousands separators: # All tools: 1,234,567 tokens/day # Tool search: 1,234 tokens/day
An assistant has 50 tools and often picks the wrong one. Which approach helps most?
Summary
- Large tool sets raise cost, lower accuracy and increase risk.
- Tool search and routing send only the relevant tools for each request.
- Grouping, broader tools with an action enum, tool choice and sub-agents keep choices clear.
- Measure tool selection with a test set, including requests that need no tool.
Next: the course project, an agent connected to real external APIs.
Finished reading? Tick it off to track your progress.