Advanced Tool Filtering for Tool Selection
Issue: #1002
Current
Currently tool selection only uses embedding similarity, similarity threshold, and top-k. When embeddings are similar but intent is inconsistent, tools from incorrect domains may be selected.
#1002 proposes the need to introduce advanced tool filtering capabilities to reduce these misselections through sophisticated relevance filtering, while maintaining default behavior unchanged.
Solution
After embedding candidate set retrieval, add an optional advanced filtering stage. This stage applies deterministic filtering (allow/block lists, optional category gating, lexical overlap thresholds) and a combined score reranker that fuses embedding similarity with lexical, tag, name, and category signals. If advanced_filtering.enabled=false, existing behavior remains unchanged.
Solution advantages: maintains controllable latency, introduces no new model dependencies, and is fully explainable through configuration.
Comparative Test Results
Test configuration:
- Query set: 20 queries (17 positive examples, 3 negative examples), covering weather, email, search, calculation, calendar, and other scenarios
- Tool library: 5 tools (get_weather, search_web, calculate, send_email, create_calendar_event)
- Iterations: 10
- Advanced filtering configuration:
min_lexical_overlap=1,min_combined_score=0.35,weights={embed:0.7, lexical:0.2, tag:0.05, name:0.05}
Evaluation results:

| Metric | Baseline | Advanced | Delta |
|---|---|---|---|
| Accuracy | 55.00% | 90.00% | +35.00% |
| Precision | 78.57% | 94.12% | +15.55% |
| Recall | 64.71% | 94.12% | +29.41% |
| False Positive Rate | 100.00% | 33.33% | -66.67% |
| Avg Latency | 0.0162 ms | 0.0197 ms | +0.0036 ms |
| P95 Latency | 0.0256 ms | 0.0288 ms | +0.0032 ms |