TL;DR
Traditional tool retrieval methods treat API documentation as flat text, ignoring the structural constraints and multi-aspect nature of software tools. This paper introduces Multi-Field Tool Retrieval (MFTR), a framework that standardizes tool documentation and user queries into aligned, fine-grained fields, utilizing an adaptive weighting mechanism and a missing parameter penalty to achieve state-of-the-art retrieval performance across multiple benchmarks.
What Problem Does This Paper Address?
To build effective LLM-powered agents, models must be able to call external APIs and tools. However, as tool repositories grow to contain thousands or millions of options, we cannot simply stuff every API description into an LLM's context window. We need a tool retrieval system to find the right tool for the job.
Existing approaches treat tool retrieval as a standard ad-hoc text retrieval task: they match a user's high-level query against raw, unstructured tool documentation. The authors identify three critical flaws in this paradigm:
- Inconsistent Documentation: API docs from different sources vary wildly in format, granularity, and terminology.
- Granularity Mismatch: User queries are often ambiguous and high-level (e.g., "analyze sales trends"), whereas tools are technically precise and atomic (e.g., a specific SQL execution function).
- Multi-Aspect Utility: A tool's relevance isn't just about semantic similarity; it depends on strict execution logic, such as whether the user can provide the required input parameters or if the tool's output format satisfies downstream tasks.
Methods
To bridge the gap between user intent and tool utility, the authors propose the Multi-Field Tool Retrieval (MFTR) framework, which breaks retrieval down into three main phases:
- Tool Documentation Standardization: MFTR uses an LLM to restructure messy, heterogeneous API documentation into a clean, four-field schema:
description(high-level purpose),parameters(inputs),response(outputs), andexamples(typical user intents). - Query Rewriting and Alignment: To fix the granularity mismatch, the user query is rewritten into the same structured format. To prevent the LLM from hallucinating or using incorrect terminology during this rewrite, MFTR employs Tool-Aware Pseudo-Relevance Feedback. It runs a quick initial BM25 retrieval to give the rewriting LLM a "preview" of relevant tools and terminology in the repository.
- Adaptive Weighting & Missing Parameter Penalty: MFTR scores the descriptive fields (
description,response,examples) using standard semantic retrievers. For theparametersfield, it performs set-to-set matching. Crucially, it introduces a Missing Penalty mechanism using a learnable sigmoid threshold. If a tool requires parameters that the user's query cannot provide, its ranking score is heavily penalized. The final score is a learned linear combination of all field scores, optimized via a pairwise ranking loss.
Datasets
The framework was evaluated on five distinct tool learning datasets adapted for retrieval:
- ToolBench: Real-world REST APIs from RapidAPI.
- APIGen: Cleaned REST APIs and Python functions.
- APIBank: Manually crafted Python functions paired with human-authored dialogues.
- Gorilla (HuggingFace subset): Queries describing machine learning tasks paired with HuggingFace model APIs.
- Toolink: LLM-generated code snippets.
Additionally, the authors created a new Mixed benchmark by merging all five datasets into a single pool of 20,476 tools to simulate a realistic, large-scale, heterogeneous environment.
Key Insights and Ideas
- Flat Text is Suboptimal: The authors conducted a preliminary "field masking" experiment where they hid specific parts of tool documentation during retrieval. Masking different fields caused unpredictable performance swings across different datasets and retrievers, proving that treating documentation as a single flat string forces retrievers to rely on noisy, inconsistent signals.
- Naïve LLM Augmentation Fails: Simply using an LLM to expand or rewrite text without enforcing a strict multi-field structure actually degrades performance because it introduces semantic noise. Alignment and structured field matching are prerequisites for success.
- The Power of the Penalty: Enforcing a penalty for missing parameters is vital. A tool can be semantically perfect, but if it lacks a required parameter, it is practically useless to the agent.
Key Results
MFTR consistently achieved state-of-the-art (SOTA) performance across all datasets and retriever backbones (including BM25, MiniLM, Contriever, E5, GTE, and BGE).
- Massive Gains on Noisy Data: On the Gorilla dataset—where documentation is notoriously redundant—MFTR boosted MiniLM-L6's Recall@10 from 39.60% to 58.60% (a 47.98% relative improvement).
- Superior Generalizability: On the challenging Mixed benchmark, MFTR outperformed the closest runner-up baseline by 28.61% in NDCG@10 and 18.98% in Recall@10.
- Model-Agnostic Efficiency: A lightweight retriever like MiniLM-L6 equipped with MFTR was able to match or outperform dense models with 10× more parameters using standard retrieval methods.
Limitations and Future Work
The primary trade-off of MFTR is the online computational cost of query rewriting, which requires a single LLM call (averaging 1.02 seconds under 4-way parallelism). While this is significantly faster than multi-call agent baselines like PLUTo (which averages 15.35 seconds), it still introduces minor latency compared to raw embedding lookups. The authors note that this marginal delay is a highly acceptable trade-off given the substantial accuracy gains. Future work could explore optimizing this rewriting step to minimize latency.
Summary updated