Overview
As AI agents connect to more services—Slack, GitHub, Jira, MCP servers—tool libraries grow rapidly. A typical multi-server setup can easily have 50+ tools consuming 55,000+ tokens before any conversation starts. Tool selection accuracy also degrades when models face 30+ similarly-named tools. Tool Search Tool implements Anthropic’s Tool Search Tool pattern for Spring AI:- Model receives only a search tool initially (minimal tokens)
- When capabilities are needed, model searches for relevant tools
- Matching tool definitions are dynamically expanded into context
- Model invokes discovered tools to complete the task
Version: 1.0.0-SNAPSHOT
Maven snapshot artifacts are available from Maven Central Snapshots
Key Benefits
Token Efficiency
Reduced context windows with 80-90% token savings
Better Accuracy
Models select the right tool when focused on fewer options
Portable
Works with any LLM supported by Spring AI
Observable
Leverages Spring AI’s advisor chain for logging and monitoring
Project Structure
Search Strategies
| Strategy | Module | Best For |
|---|---|---|
| Semantic | tool-searcher-vectorstore | Natural language queries, fuzzy matching |
| Keyword | tool-searcher-lucene | Exact term matching, known tool names |
| Regex | tool-searcher-regex | Tool name patterns (get_*, *_api) |
How It Works
- Indexing: Tools are indexed in the
ToolSearcher(not sent to LLM) - Initial Request: Only
toolSearchTooldefinition is sent to LLM - Discovery: LLM calls
toolSearchTool(query="weather")to find relevant tools - Expansion: Discovered tools are added to next request
- Execution: LLM calls discovered tools to complete the task
- Response: Final answer generated
Quick Start
1. Add Dependencies
Add the snapshot repository to yourpom.xml:
2. Configure the Advisor
Examples
Tool Search Tool Demo (Recommended)
LLM actively discovers tools on-demand:Pre-Select Tool Demo (Alternative)
Pre-selects tools based on conversation context:Requirements
- Java 17+
- Spring AI 1.1.0-M4+
- Maven 3.6+
Resources
GitHub Repository
View source code and contribute
Anthropic's Tool Search Tool
Original pattern documentation
Spring AI Tool Calling
Spring AI’s tool calling docs
Spring AI Advisors
Recursive advisors documentation