Notebooks
A
Anthropic
Tool Search Alternate Approaches

Tool Search Alternate Approaches

tool_useclaude-cookbooks

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:

  1. 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.
  2. Tools do not have to be passed in the request's tools list 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

[ ]
[ ]

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:

  1. Start with only describe_tool in the tools list
  2. When Claude calls describe_tool, return a tool_reference AND add the tool to active_tools with defer_loading=True
  3. defer_loading=True is 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:

  1. Sees get_weather in the system prompt's tool list
  2. Calls describe_tool("get_weather") to load it
  3. Receives the tool_reference and 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:

  1. Return tool_reference when a tool is discovered
  2. Add the tool with defer_loading=True to preserve caching
  3. Claude can then use the tool immediately

See Tool Search with Embeddings for the embeddings-based approach.