Abstract
Large Language Models (LLMs) increasingly rely on external tools to perform complex tasks. However, retrieving the correct tool from a massive, evolving library remains a challenge due to ambiguous user queries and the semantic gap between retrievers and tool functionalities. This paper presents a framework that leverages LLMs as iterative critics to refine search queries. By progressively analyzing retrieved tools and identifying missing information, the system significantly enhances retrieval accuracy. Experimental results on the TR-bench benchmark demonstrate a 16.9% relative improvement in NDCG@1 over existing state-of-the-art methods, leading to higher success rates in downstream task completion.
Introduction
The integration of external tools—such as APIs, calculators, and databases—has significantly expanded the capabilities of Large Language Models (LLMs), enabling them to access real-time information and perform specialized computations. However, as the number of available tools grows into the thousands, two primary challenges emerge. First, the limited context window of LLMs prevents the inclusion of all tool descriptions in a single prompt (in-context learning), while the high frequency of tool updates makes constant fine-tuning impractical. Second, there exists a significant "retrieval gap": standard dense retrieval methods often fail to capture the functional nuances required for tool selection, leading to the retrieval of tools that appear semantically relevant but are functionally inadequate.
The Iterative Feedback Framework
To address these limitations, we propose an iterative feedback loop that utilizes the high-level reasoning capabilities of LLMs to guide the retrieval process. Instead of a single-shot search, the framework treats retrieval as a multi-step conversation between the LLM and the retriever. Each iteration consists of three stages:
- Comprehension: The LLM analyzes the user's initial instruction and the documentation of the currently retrieved top-$K$ tools. It identifies the core intent and the specific parameters required.
- Assessment: The LLM evaluates the utility of the retrieved tools. It checks for "invalid APIs," "missing details," or "invocation success" to determine if the current set can satisfy the user's request.
- Refinement: If the tools are found wanting, the LLM generates a refined instruction. This new query incorporates missing details, clarifies ambiguities, and adds scenario-specific context to help the retriever narrow its search in the subsequent iteration.
Training Strategy
The framework is not merely an inference-time heuristic; it includes an Iteration-Aware Feedback Training phase. To help the retriever distinguish between different stages of the loop, special tokens (e.g., "Iteration 1", "Iteration 2") are prepended to the queries. Furthermore, the training process employs Hard Negative Sampling. By specifically training the model to distinguish between a correct tool and a "hard negative"—a tool that was previously ranked highly by the retriever but rejected by the LLM—the retriever learns to recognize subtle functional differences that simple semantic matching would miss.
Evaluation and Results
We evaluated our approach on TR-bench, a comprehensive benchmark comprising ToolBench (in-domain) and T-Eval/UltraTools (out-of-domain). The results show that the iterative feedback mechanism leads to a steady climb in retrieval accuracy across iterations. On the ToolBench "All" category, our method achieved an NDCG@1 of 88.53, representing a 16.9% relative improvement over the previous state-of-the-art, ToolRetriever (75.73).
Crucially, the method demonstrates strong generalization. Even when tested on entirely unseen tools in the T-Eval and UltraTools datasets, the iterative approach outperformed baseline retrievers. This suggests that the LLM learns a general strategy for query refinement rather than just memorizing specific tool mappings. Furthermore, improved retrieval directly translates to better downstream performance, with a task completion pass rate of 75.6%, compared to 68.5% for the baseline.
Conclusion
By positioning the LLM as an iterative critic, we bridge the gap between abstract user intent and concrete tool functionality. While the current approach introduces additional inference latency (approximately 6 seconds per instruction), it provides a robust solution for large-scale, dynamic tool environments. Future work will focus on optimizing this latency through offline feedback generation and exploring the framework's utility in multi-turn conversational agents.
Summary updated