Introduction
As Large Language Models (LLMs) evolve from simple chatbots into autonomous agents capable of interacting with thousands of specialized APIs, a new bottleneck has emerged: tool retrieval. Identifying the correct tool within a massive library of functions is critical for agentic performance. This paper demonstrates that using an LLM to "rewrite" vague user requests into descriptive search queries—and refining this process through iterative alignment learning—significantly boosts retrieval accuracy, particularly for tools the system has never encountered before.
The Retrieval Bottleneck
Standard tool-use pipelines typically employ a "retriever-generator" architecture. A retriever (such as BM25 or dense vector search) selects relevant APIs from a library, which the LLM then uses to solve a task. However, standard retrievers often fail on complex or ambiguous requests. For example, if a user says, "I’m bored and tired of staying home," a keyword-based search might suggest home-based activities. A human understands the latent desire for outdoor activities, but retrievers lack this common-sense reasoning. Furthermore, complex requests often require multiple tools, and a single user utterance may lack the specific technical keywords found in API documentation.
Methodology: LLM-Based Query Generation
The authors propose replacing raw user utterances with LLM-generated descriptions of the required tools.
They explored three primary training strategies using LLaMA-13B:
- Zero-Shot Prompting: Asking the LLM to describe necessary APIs without specific training.
- Supervised Fine-Tuning (SFT): Training the LLM on pairs of user utterances and ground-truth API descriptions.
- Alignment Learning: This core innovation uses a rejection sampling loop. The model generates multiple "draft" queries for a request, which are then run through the retriever. Results are scored using a retrieval metric (like Recall@k), and the model is fine-tuned only on the drafts that led to the most successful retrievals. This process is repeated iteratively to align the LLM's generation with the specific retrieval engine.
Experimental Setup and Datasets
The study utilized a dataset based on ToolLLM, containing complex, multi-tool scenarios. After quality filtering, the set included 1,831 APIs. To test generalization, the authors split the data into:
- In-Domain: 1,458 APIs seen during training.
- Out-of-Domain: 373 APIs entirely unseen during training, used to evaluate how the system handles novel tools.
Key Results
The researchers compared LLM-generated queries against a baseline of raw user utterances.
- In-Domain (Seen Tools): SFT was the strongest performer, increasing Recall@5 from a baseline of 63.82% to 87.29%.
- Out-of-Domain (Unseen Tools): In this more challenging and realistic scenario, Alignment Learning achieved the best results, reaching a Recall@5 of 78.53% (compared to 75.26% for the baseline and 76.18% for SFT).
- Iterative Improvement: Performance consistently improved over multiple iterations of the alignment loop before plateauing, suggesting the model successfully learned a generalizable retrieval strategy.
Insights and Discussion
- Decomposition: For multi-step tasks, the LLM naturally breaks a single request into multiple distinct queries (e.g., "find a restaurant" and "book a taxi"), which standard retrievers cannot do effectively with a single utterance.
- Common-Sense Bridge: The LLM acts as a translator between human intent ("I'm bored") and technical utility ("outdoor recreational activities").
- Strategic Hallucination: Interestingly, the LLM sometimes "hallucinates" API names. While the names are fake, the generated descriptions often contain the exact semantic keywords needed to find the real, similarly-named API in the index.
Limitations and Future Work
While effective, the authors note that hallucinations can still lead to inconsistencies. Additionally, iterative alignment learning is computationally intensive compared to standard SFT. Future research will focus on grounding these generations more strictly and exploring the combination of "user intent" and "API description" generation to further refine retrieval performance.
Summary updated