Tool Search Alternate Approaches
Tool Search: Alternate Approaches
Recommend first reading see the cookbook: Tool Search with Embeddings.
The goal of this cookbook is to show of some alternate approaches to using tool search (or really "tool discovery") with Claude. In this cookbook we'll demonstrate two useful techniques:
- Tools can be discovered without "Search". In this cookbook, we'll include all of the tool names in Claude's system prompt and provide Claude with decribe_tool_tool to load the tool fully into Claude's context.
- Tools do not have to be passed in the request's
toolslist if they have not been loaded into Claude's context yet. This can be a bit more application complexity to manage, but can allow your application to keep requests small, even while Claude has potential access to thousands of tools.
Users have a lot of flexibility to design tool search to keep Claude's context (and Messages requests) as focused as possible.
Prerequisites
Before following this guide, ensure you have:
Required Knowledge
- Python fundamentals - comfortable with functions, dictionaries, and basic data structures
- Basic understanding of Claude tool use - we recommend reading the Tool Use Guide first
Required Tools
- Python 3.11 or higher
- Anthropic API key (get one here)
Define Tool Library
We'll define 5 simple tools. In production, this could be hundreds or thousands of tools stored in a database or configuration file.
The describe_tool Tool
Instead of semantic search, we give Claude a simple describe_tool tool. Claude calls this with a tool name to load that tool into context.
The system prompt lists all available tool names, so Claude knows what's available without needing embeddings or search.
Mock Tool Execution
Simple mock responses for demonstration:
Conversation Loop with Dynamic Tool Loading
The key pattern here:
- Start with only
describe_toolin the tools list - When Claude calls
describe_tool, return atool_referenceAND add the tool toactive_toolswithdefer_loading=True defer_loading=Trueis critical - it keeps the tool definition out of the cached prompt prefix, avoiding cache invalidation when tools are discovered
Every time Claude sees a tool_reference in the conversation, the full tool definition is loaded into Claude's context at that point in the conversation.
Example: Weather Query
Watch how Claude:
- Sees
get_weatherin the system prompt's tool list - Calls
describe_tool("get_weather")to load it - Receives the
tool_referenceand can now use the tool
Example: Multi-Tool Query
Claude can load multiple tools as needed:
Why defer_loading=True Matters
When you add a tool to the tools list, the tool definition is normally loaded into the very beginning of Claude's context window. If you add new tools, you will lose most of the cache because the very beginning of the context window has changed.
With defer_loading=True:
- The tool definition is NOT included into the beginning of Claude's context window.
- Instead, it's loaded into context when Claude sees the
tool_reference - This means your system prompt and initial tools stay cached even as you discover new tools
The pattern:
# Initial request - only describe_tool, system prompt is cached
tools = [DESCRIBE_TOOL]
# After Claude calls describe_tool("get_weather")
# Add with defer_loading to preserve cache
tools.append({**TOOL_LIBRARY["get_weather"], "defer_loading": True})
# Return tool_reference so Claude knows it's available
tool_result = [{"type": "tool_reference", "tool_name": "get_weather"}]
This is essential for applications with hundreds or thousands of tools where you want to:
- Keep initial request size small
- Preserve prompt caching across tool discoveries
- Only load tools Claude actually needs
Conclusion
The key insight from this cookbook: tools don't need to be in the tools list until Claude needs them. Combined with defer_loading=True and tool_reference, this lets you scale to thousands of tools while keeping requests small and preserving prompt caching. However, in this case your client will need to provide a tool discovery mechanism.
The describe_tool approach shown here is just one flavor. Other patterns include:
list_tools- Returns tool names matching a category or keyword- Hierarchical discovery - Browse tool categories, then load specific tools
- Hybrid - Combine listing with semantic search for large catalogs
The core pattern is always:
- Return
tool_referencewhen a tool is discovered - Add the tool with
defer_loading=Trueto preserve caching - Claude can then use the tool immediately
See Tool Search with Embeddings for the embeddings-based approach.