PORTS: Preference-Optimized Retrievers for Tool Selection
with Large Language Models

Lorenzo Molfetta    Giacomo Frisoni    Nicolò Monaldini    Gianluca Moro
Department of Computer Science and Engineering, University of Bologna
{lorenzo.molfetta, giacomo.frisoni, gianluca.moro}
unibo.it?,
nicolo.monaldini@studio.unibo.it


Abstract

Integrating external tools with Large Language Models (LLMs) has emerged as a promising paradigm for accomplishing complex tasks. Since LLMs still struggle to effectively manage large tool collections, researchers have begun exploring retrieval-based methods to pre-select the most relevant options, addressing input length and latency constraints. However, existing retrievers are often misaligned with tool-calling LLMs due to their separate training processes. This paper presents PORTS, a novel odds ratio preference optimization method for training retrievers aimed at tool selection. Using a perplexity-inspired preference signal from a frozen LLM, our approach fine-tunes a retriever to find helpful tools by optimizing the correlation between the selection probabilities and the downstream performances while jointly enforcing a contrastive semantic loss between documentation strings. The versatility of PORTS and its ability to significantly improve tool selection accuracy are demonstrated through extensive experiments on six datasets, two encoder models, and three LLMs with diverse prior knowledge. With low computational demands, our alignment process facilitates generalization to new queries and tools, proving valuable for practical applications with evolving toolsets.1

1 Introduction↩︎

“The right tool for the right job.”Proverb

Equipping Large Language Models (LLMs) with the capability to dynamically interact with external tools2 has garnered significant research attention. This integration not only improves the problem-solving potential of LLMs, but also dramatically expands their functional scope [2], [3]. When presented with a user query, tool-augmented LLMs can determine when and how to utilize specific tools to generate more accurate and informative responses. For example, tools can enable LLMs to use a calculator, set calendar events, and access real-time weather information. As the field continues to evolve, LLMs with tools are expected to play a pivotal role in shaping the future of Natural Language Processing (NLP) [1].

Figure 1: Results overview. Comparison between frozen, RePlug-tuned, and PORTS-tuned retrievers. Scores are averaged across Recall@{1,2,3} for three LLMs (if trained) and six datasets (test set).

Fine-tuning LLMs with tool usage examples is expensive and confines the acquired knowledge to a predefined set of tools [4], [5]. The in-context learning paradigm alleviates these issues, but the limitations in input length and noise for lengthy prompts make it impractical to manage many descriptions or demonstrations directly [6], [7], introducing efficiency and accuracy challenges in tool-selection tasks, mainly when precise parameter specification and schema typing are paramount. Furthermore, when faced with hundreds of tool docstrings in the prompt, the language model alone struggles to identify the most suitable one, often resulting in suboptimal performance [1], increased computational needs, and high costs. Recently, the focus has shifted towards the use of retrievers to effectively support LLMs in the tool selection process [8][10]. Retrieval-enhanced pipelines filter the top-\(K\) most suitable tools for a given query, aiming to reduce noise and enhance the LLM’s ability to select the right tool and configure the necessary parameters for calling.

Although several publications have explored retrievers for tool selection, optimization of the retrieval component itself has received little consideration. Clustering approaches have proven successful in multi-dimensional representation spaces [11], but current methods predominantly employ non-parametric indexing techniques [12] or standard encoder models trained with supervised signals [8]. Whereas these methodologies can be effective in isolation, they often falter when integrated into a broader pipeline, primarily due to misalignment between the training criteria used for the retrieval and generation modules. A significant challenge arises when tools with descriptions similar to the user query are ultimately irrelevant or potentially misleading for the LLM [13], [14]. Furthermore, tools can exhibit subtle differences, such as variations in the names, numbers, and types of input parameters, which complicate effective selection–an issue that is increasingly prevalent given the rapid proliferation of publicly available tools and Model Context Protocol servers. In such scenarios, conditioning the encoder on the LLM output may provide additional training signals that benefit the selection process. However, most existing retriever adaptation techniques require the LLM to be trained from scratch [15][17], which can be prohibitively costly or unfeasible with closed-source solutions characterized by no access to internal representations. Recent research has explored an alternative approach: training encoder models with the support of LLMs, using them as supervision signals to better align representations with task-specific objectives [18]. We focus on this emerging class of methods, investigating how LLMs can be effectively leveraged and optimized to guide encoder alignment through feedback incorporation for tool retrieval.

In this paper, we propose a new method to train preference-optimized retrievers for tool selection (PORTS), aligning them with the needs of the LLM responsible for tool usage. Our training scheme adapts a pre-trained encoder model with supervision signals from a black-box LLM, preferring retrieving tool docstrings that stimulate the downstream LLM to use the right tool. Introducing a novel contrastive preference loss enables a more accurate selection process in application domains where multiple tools might adequately serve the task and yield coherent yet inaccurate results. We conduct experiments on six public datasets. The results are analyzed with various classes of encoders and LLMs. To gauge generalizability, tests are carried out with in-domain and out-of-domain tools. We conclude that PORTS can effectively increase the tool selection performance of the baseline retriever, with low computational overhead. Figure 1 shows the averaged metric gains of our alignment method in retrieving tools seen during training.

2 Related Work↩︎

2.0.0.1 Tool Learning

Recent studies in language modeling have explored the use of non-differentiable tools to supplement the knowledge stored in the model weights, offloading tasks to external modules. They broadly fall into two categories. Tuning-based methods train models to use one or a few tools in specific domains. Example works include TALM [19], Toolformer [20], ToolLLaMA [8], Gorilla [12], ToolkenGPT [21], and Granite [22]. These models are trained on datasets where the input text is augmented with tool calls. During inference, when such invocations are identified, the decoding process is paused, the corresponding tool is executed, and the result is incorporated before resuming text generation. Specialized tool-calling models mostly rely on synthetic instruction-tuning data generated from proprietary models such as GPT-4 [23]. Among the few exceptions intended for commercial applications is the NexusRaven series [24]. However, LLM fine-tuning is only applicable to open-source models and is generally hindered by expensive data collection and computing infrastructure, as well as poor flexibility in accommodating emergent or updated tools. Conversely, tuning-free methods are compatible with all LLMs and capitalize on in-context learning abilities, showing tool descriptions and demonstrations directly in the prompt [25][27]. As the tool arsenal grows (e.g., 16.000+ [8]), a retriever becomes essential. Retrieval-based and fine-tuning methods can be combined to achieve better performance [9].

2.0.0.2 Tool Retrieval

Merging Retrieval-Augmented Generation (RAG) and tool calling enables LLMs to evaluate a small subset of retrieved tools and select the most suitable for response formulation. Tool retrieval approaches can be classified into two main types: term-based and semantic-based. Term-based techniques, exemplified by TF-IDF [28] and BM25 [29], rely on exact term matching and utilize sparse representations for both tool docstrings and queries. For instance, Gorilla [12] implements tool retrieval by combining BM25 with GPT-Index. In contrast, semantic-based methods utilize neural networks to learn the relationships between queries and tool descriptions. CRAFT [30], for example, instructs LLMs to generate fictitious tool descriptions conditioned on the input queries, then uses pre-trained SimCSE for similarity computation. Few studies focus on training the retriever itself, while iterative refinement with cosine similarity has proven effective for adapting representations [31][33]. TPTU [34], ToolLLaMA [8] and Confucius [9] fine-tune a SentenceBERT model using contrastive learning objectives. ProTIP [10] fine-tunes BERT-base with a contrastive loss optimized for progressive tool retrieval. COLT [7] models collaborative relationships among multiple tools using graphs and implements tool retrieval through cross-view graph contrastive learning. ToolRerank [35] addresses the re-ranking stage of tool retrieval, proposing an adaptive and hierarchy-aware method. However, these studies do not consider LLM preferences in specializing the retriever.

3 Methodology↩︎

In this section, we introduce PORTS and elaborate on its theoretical motivations, design, and training losses. Figure 2 illustrates our architecture.

Figure 2: PORTS training process. Simplified illustration of the PORTS’ training recipe with one positive and two negative tool docstrings from APIBench. Input tool documentation triplets are encoded independently and prompted separately to the frozen LLM. The retriever is fine-tuned to align tool selection probabilities with the correct answer likelihood while maximizing the ratio between the odds of selecting the right tool and the wrong ones.

3.1 Preliminary↩︎

RAG is a widely used framework for augmenting LLMs with external knowledge sources. While models like RETRO [36] and FiD [37] achieve significant improvements through separate training of retrieval and generation components, end-to-end training approaches offer potential for enhanced relevance, coherence, and contextual awareness [38], [39]. However, end-to-end training poses challenges, including high computational demands, complex data handling, and the difficulty of maintaining dynamic search indexes with accurate, up-to-date embeddings. Techniques like batch negative sampling [40] have improved efficiency, but require careful selection of diverse negatives. Adapting RAG systems to new domains often necessitates simultaneous retraining of both the retriever and generator, underscoring the importance of efficient data management [41]. To address these challenges, methods such as RePlug LSR [42] use frozen language models as references to optimize retrieval without costly full-model fine-tuning. We argue that reducing output uncertainties alone is insufficient for aligning with users’ goals when selecting tools for tasks. Retrieval models must effectively navigate reference corpora by distinguishing between semantically similar but irrelevant options. Inspired by techniques from LLM fine-tuning, such as RLHF [43], DPO [44], and ORPO [45], retrieval models can leverage comparative loss to prioritize relevant information, mirroring approaches like triplet learning.

3.2 Task Definition↩︎

Given an input query \(q\), we aim to pair it with a candidate tool \(t_i\) from a predefined set \(\mathbf{T} = \{t_1, t_2, \ldots, t_{\lvert \mathbf{T} \rvert}\}\) by maximizing their semantic alignment. PORTS is trained to prioritize the retrieval of tools’ docstrings \(d_{t_i}\) that most enhance tool calling accuracy when prompted to the LLM.

3.3 PORTS↩︎

Our approach optimizes a retrieval model \(\mathcal{R}\) through a dual training strategy accounting for query-docstring semantic similarity and tool support in correct answer prediction. We shape probabilities over available data by enforcing preferences on the top-\(K\) tools. An LLM serves as an indirect ranking agent, aligning selections with tool usage patterns, resulting in a context-aware algorithm tailored to downstream tasks.

3.3.0.1 Goal-Directed Retrieval

We formalize the retrieval process using an encoder \(\mathcal{E}\) and a generative LLM \(\mathcal{G}\). Each instance in the dataset \(\mathcal{D}\) comprises a user query \(q\), the target tool call \(y\), the tool required \(t\) to solve the request (positive), and a set of \(n\) tools irrelevant to the task (negatives). Each tool \(t_i\) is associated with a description \(d_{t_i}\), which includes its general characteristics, objectives, and parameters. PORTS first computes the alignment between \(q\) and the tool docstrings \(d_t\) using a cosine similarity function \(sim(q,d_t) = \mathcal{E}_\theta(q) \cdot \mathcal{E}_\theta(d_t)\), where \(\mathcal{E}: \mathbb{Z}^l \rightarrow \mathbb{R}^d\) denotes the retriever’s encoding function that maps input sequences of \(l\) tokens to a \(d\)-dimensional vector space, parameterized by weights \(\theta\). These similarities are then normalized and converted into retrieval probabilities using a softmax function with scaling factor \(\gamma\): \[\label{eq:retr-prob} P_\mathcal{R}^\theta(t \vert q, d_t) = \frac{\exp \left ( \frac{sim(q,d_t)}{\gamma} \right )}{\sum\limits_{t_i \in \mathcal{T}} \exp \left ( \frac{sim(q,d_{t_i})}{\gamma} \right )}\tag{1}\] The retrieval distribution over the corpus of tools in Eq. 1 is approximated by marginalizing over restricted triplet sets \(\mathcal{T} = (t_i^{+}, t_{i,1}^{-},\dots, t_{i,n}^{-}) \subseteq \mathbf{T}\) for efficiency. As in RePlug, we prompt each retrieved tool docstring independently with the query and then conduct \(K\) separate inferences. This enables a direct and noiseless correlation between tool selection quality and confidence in the generated output. The output probability distribution \(Q_\mathcal{G}\) of the LLM, reflecting confidence in the final prediction, is computed as in Eq. 2 . It applies a softmax function, parameterized by temperature \(\beta\), to the average log-likelihood \(P_\mathcal{G}\) of producing the correct tool call \(y\).

\[\label{eq:q95ppl} \begin{align} &Q_\mathcal{G}(t \vert q,d_t,y) = \frac{\exp \left ( \frac{P_\mathcal{G}(y \vert q,d_t)}{\beta} \right )}{\sum\limits_{t_i \in \mathcal{T}} \exp \left ( \frac{P_\mathcal{G}(y \vert q,d_{t_i})}{\beta} \right )} \\ & P_\mathcal{G}(y\vert q,d_t) = \frac{1}{l} \log \prod_{i=1}^l P_\mathcal{G}(y_i \vert q,d_t,y_{<i}) \end{align}\tag{2}\] The retriever is trained by optimizing the Kullback-Leibler divergence between the \(Q_\mathcal{G}(t \vert q,y)\) and \(P_\mathcal{R}^\theta(t \vert q)\) distributions: \[\begin{align} \label{eq:loss95replug} \mathcal{L}_\text{replug} = \mathop{\mathrm{\mathbb{E}}}\limits_{\mathcal{T},q,y \sim \mathcal{D}} \sum_{t_i \in \mathcal{T}} \mathrm{\small KL} \left( P_\mathcal{R}^\theta(t_i \vert q, d_{t_i}) \; \Vert \right. \\ \left. Q_\mathcal{G} (t_i\vert q,d_{t_i},y) \right) \end{align}\tag{3}\] During training, the model’s perplexity—which expresses the confidence in the prediction of the correct tool call—is leveraged by \(\mathcal{L}_\text{replug}\) in Eq. 3 to encourage the reshape of the retrieval distribution. As a result, the encoder model \(\mathcal{E}_\theta\) learns to assign lower ranks to tools that increase the probability of generating incorrect responses.

3.3.0.2 Preference-Aligned Retrieval

We introduce a contrastive loss signal that enforces a policy to favor selecting correct tools over incorrect ones (Eq. 4 ). \[\label{eq:orpo-pi} \pi_\theta (t\vert q, d_t) = \frac{P_\mathcal{R}^\theta(t \vert q, d_t)}{1 - P_\mathcal{R}^\theta(t \vert q,d_t)}\tag{4}\] For each positive-negative tool pair \((t_i^+, t^-_{i,j})\) in the input sample, we compute a ratio of their retrieval probabilities and apply the sigmoid function \(\sigma\) to derive a preference score (i.e., the relative likelihood of selecting one tool over the other). \[\label{eq:orpo-loss} \begin{align} &\mathcal{L}_\text{po} = - \sum_{i \in {1,n}} \log \sigma \left ( \log \pi_{+,-_i} \right) \\ &\pi_{+,-_i} = \frac{\pi_\theta(t^+ \vert q, d_{t^+})}{\pi_\theta (t_i^- \vert q, d_{t_i^-})} \end{align}\tag{5}\] The retriever incurs a penalty through the preference policies \(\pi\), as indicated in Eq. 5 , when it shows an increased likelihood of selecting erroneous tools.

3.3.0.3 Training Objective

PORTS combines the LLM-based retrieval proxy loss (\(\mathcal{L}_\text{replug}\)) and the preference optimization loss (\(\mathcal{L}_\text{po}\)) with a weighting factor \(\lambda\): \(\mathcal{L}_\texttt{PORTS}= \mathcal{L}_\text{replug} + \lambda \cdot \mathcal{L}_\text{po}\). Our method synchronizes the encoder selections with the LLM tool-calling patterns and imposes positive-negative embedding orientation constraints similar to deep metric learning [46].

3.3.0.4 Tool Triplets and Embeddings Asynchronous Update

The learning effectiveness in contrastive approaches is heavily influenced by the choice of negative examples [40]. We therefore implement a hard-negative sampling technique, choosing the \(n\) tools most semantically similar to the query as negative instances, where similarity is quantified using cosine similarity between embeddings computed by the encoder itself during training. To maintain computational efficiency while adapting to shifts in the embedding space during training, we periodically update both the tool embeddings and the selection of hard negatives every \(T\) training iterations [38].

3.3.0.5 Motivations for Contrastive Learning

We establish that, without fine-tuning, embeddings of tool docstrings are much more concentrated in space than traditional, general-domain text documents–due to recurring data types, keywords, and concise but distinctive functional signatures (see Appendix 13). Without targeted supervision, these properties can lead the retriever to rely on superficial cues or converge to trivial matches. Our contrastive loss is designed to counteract this by steering retrieval toward semantically relevant and challenging negatives, promoting fine-grained distinctions beyond what is captured by LLM likelihoods alone. More details about the theoretical foundations of PORTS are in Appendix 7.

4 Experimental Setup↩︎

4.1 Datasets↩︎

We evaluate PORTS on six popular tool-augmented datasets: ToolBench [8], API-Bank [47], APIBench [48], BFCL-v2 [49], ToolE [50], Octopus-v2 [51]. This collection offers a heterogeneous testing ground characterized by varying scales, applications, and input modalities. When necessary, we adapt dataset instances to tool selection, which is the core task of our contributions. Extensive dataset documentation is available in Appendix 9. Key information and statistics are reported in Table ¿tbl:tab:datasets?. For ToolBench, we focus on the most complex data split, G3, where queries demand the interplay of tools with dissimilar features, functions, and objectives. Only for training, we decompose multi-tool instances from BFCL, API-Bank, and ToolBench into separate examples, each targeting a single tool. When handling conversational inputs, we remove previous tool calls from the chat history of each fragment. We partition test-only benchmarks (Octopus-v2, ToolE, BFCL) into train and test sets using a 70/30 ratio. For Octopus-v2 and ToolE, which focus on single-tool selection without incorporating heterogeneous levels of complexity (e.g., difficulty levels or programming languages), we design in-domain and out-of-domain variants to evaluate generalization abilities to seen and unseen tools. Out-of-domain variants are created with an 80/20 tools split, avoiding overlap between training and test.

width=

4.2 Evaluation Metrics↩︎

We quantify the retrieval performance using Recall@\(K\) [52] and NDCG@\(K\) [53], with \(K=\{1,3,5\}\) following [8]. Recall@\(K\) measures the proportion of cases where the positive tool appears in the top-\(K\) results, while NDCG@\(K\) also considers its ranking position within the top-\(K\).

4.3 Implementation Details↩︎

4.3.0.1 Models

For the embedding function of \(\mathcal{R}\), we test two prominent encoders: the 125M-parameter RoBERTa-base [54], a widely adopted baseline, and the 109M-parameter BGE-base [55], a top performer on the MTEB leaderboard.3 We evaluate each encoder’s architectural compatibility and its impact on retrieval precision. For \(\mathcal{G}\), we examine three open-source LLMs. (1) Codestral-22B-v0.1,4 a model specialized for code generation tasks with native tool calling, motivated by [24]. (2) Llama3-8B[56], a foundational model, and (3) Llama3-Groq-8B-Tool-Use,5 its fine-tuned variant specifically designed for advanced tool use. We employ 4-bit quantization for efficiency. Larger models were excluded due to computational limits, focusing on a selection balancing performance and efficiency. Prompt templates are in Appendix 8.

4.3.0.2 Hyperparameters

In our experiments, we used 3 negatives sampled every \(T=50\) training steps upon recalculating embeddings. We adopted training and evaluation batch sizes of 2 and 4, respectively, and set maximum sequence lengths of 512 and 1024 for the encoder and LLM inputs. We applied a loss weight \(\lambda\) of 0.3, with \(\gamma\) and \(\beta\) set to 0.5. We set the random seed to 42 for reproducibility and trained each configuration for 2 epochs using the AdamW optimizer, coupled with a cosine learning rate scheduler starting at \(1e^{-5}\). We kept LLMs frozen during training. To simulate low-resource scenarios, we sampled \(10\)K unique instances per dataset, testing PORTS’ capacity to exploit few information more efficiently. Search spaces and hyperparameter insights are in Appendix 10.

4.3.0.3 Hardware Setup

Each run was performed on an internal workstation using a single Nvidia GeForce RTX3090 GPU with 24GB of dedicated memory, 64GB of RAM, and an Intel® Core™ i9-10900X1080 CPU @ 3.70GHz. The reference operating system is Ubuntu 20.04.3 LTS.

5 Results↩︎

We evaluate PORTS against RePlug, our primary baseline for goal-driven retrieval. Other training methodologies are omitted from direct comparison due to divergent optimization goals and architectural assumptions. Our core findings are in Table ¿tbl:tab:results?, showing metric scores for all models, datasets, and a comparison of different losses for ablation. Given space constraints, we list tool selection outcomes only for the top-performing LLM in each encoder-dataset-loss configuration. We refer the reader to Appendix 14 for exhaustive scores. We observe that PORTS consistently elevates baseline effectiveness in all datasets (cf. the color gradients for \(\Delta_{avg}\) columns linked to \(\mathcal{L}_\texttt{PORTS}\) entries in Table ¿tbl:tab:results?). For seen tools, PORTS yields substantial gains, boosting average Recall@\(\{1,2,3\}\) by up to 71.66 percentage points and average NDCG@\(\{1,3,5\}\) by 70.16. Even with unseen tools, the improvements remain remarkable, reaching +61.24 and +59.79 points in Recall and NDCG, respectively.

width=.995

Figure 3: Average Recall@K for each dataset (test set). Effectiveness of PORTS-tuned retrievers (\mathcal{L}_\texttt{PORTS}) against frozen baselines, utilizing guidance from different LLMs. Evaluated in both in-domain and out-of-domain settings.

5.0.0.1 Baseline Impact

Both RoBERTa and BGE fine-tuned with PORTS significantly outperform their respective base models, demonstrating the broad applicability of our framework. RoBERTa exhibits a more pronounced response to PORTS(\(\Delta_{avg}\) Recall of 47.28 compared to BGE’s 10.07), indicating that simpler and less specialized retrievers are more adaptable. Table ¿tbl:tab:results? clearly illustrate that BGE begins with a notable disparity between positive and negative instances (average frozen Recall of 62.92 vs. RoBERTa’s 18.45). This pre-existing imbalance in the retrieval distribution introduces a skew, which in turn attenuates the strength of our loss signal. Further robustness tests are reported in Appendix 12.

5.0.0.2 LLM Impact

The use of an LLM as a proxy during training requires careful scrutiny. Although the primary focus is not the direct accuracy of the downstream generative task, the distribution of perplexities between different generations raises questions about the optimal LLM to maximize learning influence. Empirical data did not elucidate a definitive model preference but instead accentuated PORTS’ potential to transcend its intended tool usage scope. The performance delta across all experiments ranged from +1 to +4 percentage points, with peaks attaining a +13 average recall improvement. Llama3-8B demonstrated superior performance when paired with RoBERTa, where–as previously discussed–there was markedly less resistance to adaptation. This improvement can be attributed to the heightened uncertainty this model experiences in technical domains not anticipated during its pre-training regimen. Although elevated perplexity is generally undesirable for downstream task optimization, it is advantageous in the PORTS framework due to the resultant richer and less skewed log-likelihood distribution, as elucidated in Eq. 2 .

5.0.0.3 Docstring Impact

The efficacy of contrastive retrieval is heavily contingent on docstring quality. APIBench illustrates this relationship, where vague descriptions result in smaller changes in the tool retrieval metrics. In fact, the tool documents in the dataset reference generic features of pre-trained models from HuggingFace, which often omit parameter names and types that could better guide the retriever at training time. Importantly, Llama3-8B tends to perform better in datasets with less technical tool documentation due to its superior management of perplexity scores. On the other hand, Llama3-Groq-8B-Tool-Use and Codestral-22B-v0.1, with their advanced tool usage capabilities, excel in datasets with more detailed docstrings (e.g., arguments, outputs, types, defaults), namely ToolBench and Octopus-v2.

5.0.0.4 Training Loss

Contrastive learning and RePlug have known simultaneous success in various application domains. Our assertions on the positive impact of preference-oriented learning have been substantiated through comprehensive ablations presented in Table ¿tbl:tab:results?. PORTS outperforms RePlug in all evaluated domains, with substantial disparities in recall performance, with +15.8 and +12.3 in ToolE and ApiBench, respectively. We underline that these datasets present unique challenges: ToolE necessitates precise tool decisions among similar options in complex scenarios, while ApiBench involves code generation primarily through pre-trained neural networks, described only in broad application contexts. Such unique characteristics are conducive to showcase the benefits of our comparative loss approach, which likely contributes to PORTS’s superior performance in these settings. Zooming out, the statistics outlined in Figure 1 reflect an average Recall@\(K\) improvement of 6.7 (RoBERTa) and 3.4 (BGE) across all datasets and LLMs, ultimately corroborating the greater efficacy of our method over RePlug in the context of tool retrieval.

5.0.0.5 Out-Of-Domain Analysis

For domains with limited resources and scarce data, retrieval systems must be capable of effectively managing unfamiliar tools. Although previous research has developed systems that can adapt to new data [9], these systems are susceptible to overfitting, potentially due to biases in the distribution and usage patterns of tools. To evaluate the robustness of our method in addressing these challenges, we investigated the performance of retrieval models trained with RePlug and PORTS when exposed to varying proportions of unseen tools from the ToolE dataset. Starting with a 90/10 ratio of seen to unseen tools, we progressively reduced the training dataset and assessed the performance of RoBERTa guided by Llama3-8B on a consistent test distribution. Figure 4 illustrates the superior generalization capabilities of PORTS. Employing preference optimization loss, our contrastive learning techniques effectively derive semantic insights into query-tool interactions without requiring extensive pairwise comparisons, thereby substantiating the enhanced low-resource capabilities of our solution and demonstrating its suitability for application areas with constantly evolving API documentation. Figure 3 reports the average recall across test datasets and encoder models for all PORTS’ variants fine-tuned with different LLMs.

Figure 4: Average out-of-domain Recall@K and NDGC@K with a progressive number of train tools (decreasing unseen). Reported results refer to RoBERTa on ToolE with RePlug and PORTS under Llama3-8B supervision.

6 Conclusion↩︎

We introduce PORTS, a novel training method to optimize encoders for tool retrieval tasks. Our goal is twofold: to align tool selection with the preferences of the calling LLM, and to maximize the odds ratio between correct and incorrect tools. PORTS emphasizes low cost by leveraging LLMs’ prior knowledge to navigate the latent space of tool document similarities, focusing on the impact of retrieved samples. Experiments across multiple models and diverse datasets show that PORTS achieves Recall@1 improvements of up to +72.5% and +58.7% over frozen baselines for in- and out-domain tools, with gains of +15.24% and +14.71% percentage points compared to RePlug.

To further assess retrieval effectiveness in code generation scenarios, metrics like Pass@\(K\) could reflect the downstream impact on generative components. Incorporating relevance signals based on actual output effects and message similarity may allow PORTS to integrate discounting mechanisms for more goal-directed retrieval. Future work could also investigate PORTS in biomedical discovery workflows [57]–e.g. helping an agent decide whether to use specialized function discovery models [58][60], call Gene Ontology tooling for term enrichment, query STRING for protein-protein interaction networks, or fetch data from the Unified Medical Language System–with dozens to hundreds of specialized data sources and tools with different formats, coverage, and update frequency.

Acknowledgment↩︎

Research partially supported by: AI-PACT (CUP B47H22004450008, B47H22004460001); National Plan PNC-I.1 DARE (PNC0000002, CUP B53C22006450001); PNRR Extended Partnership FAIR (PE00000013, Spoke 8); 2024 Scientific Research and High Technology Program, project “AI analysis for risk assessment of empty lymph nodes in endometrial cancer surgery”, the Fondazione Cassa di Risparmio in Bologna; Chips JU TRISTAN (G.A. 101095947). LG Solution Srl for partially funding a PhD scholarship to L. Molfetta.

Limitations↩︎

Despite its strong results, PORTS has limitations that warrant further examination. First, its effectiveness is sensitive to the quality of tool documentation, with diminished gains in domains where docstrings are vague or underspecified. Second, although PORTS maintains a memory efficiency comparable to RePlug LSR, it requires repeated querying of a frozen LLM to calculate the guidance signals. This dependence introduces additional computational overhead in both time and memory, potentially limiting scalability in resource-constrained settings. Future work may address these challenges by reducing the reliance on LLM inference or developing efficient approximations of guidance signals, thus improving the practicality of retrieval methods that use LLMs as proxies at training time.

7 In-Depth View on the Relevance of PORTS↩︎

Given an input query \(q\) and a set of tools \(t\) with description \(d_{t_i}\), PORTS combines RePlug’s goal-directed retrieval with preference alignment, adapted explicitly for tool selection. This approach enhances both relevance and downstream performance, effectively addressing gaps in existing methods. The foundation lies in RePlug’s gradient structure, derived from minimizing the KL divergence between the retriever distribution \(P_\mathcal{R}(t|q,d_t)\) and the LM’s utility signal \(Q_\mathcal{G}(t|q,d_t,y)\).

7.0.0.1 RePlug Gradient Derivation

Starting from the KL divergence objective: \[\begin{align} \mathcal{L}_\text{replug} &= \text{KL}(P_\mathcal{R}^\theta \parallel Q_\mathcal{G}) \nonumber \\ &= \sum_t P_\mathcal{R}^\theta(t|q, d_t) \log \frac{P_\mathcal{R}^\theta(t|q,d_t)}{Q_\mathcal{G}(t|q,d_t,y)}, \end{align}\] we decompose it into entropy and cross-entropy terms: \[\begin{align} \text{KL} &= \underbrace{\sum_t P_\mathcal{R}^\theta \log P_\mathcal{R}^\theta}_{-H(P_\mathcal{R}^\theta)} - \underbrace{\sum_t P_\mathcal{R}^\theta \log Q_\mathcal{G}}_{-H(P_\mathcal{R}^\theta, Q_\mathcal{G})}. \end{align}\] To derive gradients with respect to retriever scores \(sim(q,d_t)\), we differentiate both terms. First, for the entropy term \(H(P_\mathcal{R}^\theta)\): \[\begin{align} \begin{aligned} \frac{\partial H(P_\mathcal{R}^\theta)}{\partial sim(q,d_t)}&= \frac{1}{\gamma}P_\mathcal{R}^\theta(t|q,d_t)\; \cdot \\ &\cdot\; \Bigl( 1 + \log P_\mathcal{R}^\theta(t|q,d_t) - H(P_\mathcal{R}^\theta) \Bigr), \end{aligned} \end{align}\] where \(\gamma\) is the retriever’s temperature parameter. For the cross-entropy term \(H(P_\mathcal{R}^\theta, Q_\mathcal{G})\): \[\begin{align} \begin{aligned} &\frac{\partial H(P_\mathcal{R}^\theta, Q_\mathcal{G})}{\partial sim(q,d_t)} = \frac{1}{\gamma}P_\mathcal{R}^\theta(t|q,d_t)\cdot \\&\cdot \left(\log Q_\mathcal{G}(t|q,d_t,y) - \mathbb{E}_{P_\mathcal{R}^\theta}[\log Q_\mathcal{G}]\right). \end{aligned} \end{align}\] Subtracting these gradients yields: \[\begin{align} \begin{aligned} &\frac{\partial \mathcal{L}_\text{replug}}{\partial sim(q,d_t)} = \frac{P_\mathcal{R}^\theta(t|q,d_t)}{\gamma} \cdot \\ &\;\;\;\;\;\; \cdot \left( \log\frac{P_\mathcal{R}^\theta(t|q,d_t)}{Q_\mathcal{G}(t|q,d_t,y)} \quad - \text{KL}(P_\mathcal{R}^\theta \parallel Q_\mathcal{G}) \right). \end{aligned} \end{align}\] Here, \(\log\frac{P_\mathcal{R}^\theta}{Q_\mathcal{G}}\) provides per-document alignment signals, while the \(\text{KL}\) term stabilizes training by serving as a baseline for global distribution shifts.

7.0.0.2 PORTS Gradient Extension

Our analysis of the full PORTS loss gradient highlights the limitations of RePlug alone: \[\begin{align} \begin{aligned} &\nabla_\theta \mathcal{L}_\text{PORTS} \propto \nabla_\theta \mathcal{L}_\text{replug} + \nabla_\theta \mathcal{L}_\text{po} \\ &\nabla \mathcal{L}_\text{replug} = P_\mathcal{R}^\theta(t|q,d_t) \Biggl( \log\frac{P_R(t|q,d_t)}{Q_\mathcal{G}(t|q,d_t,y)} +\\& - \text{KL}(P_\mathcal{R}^\theta \parallel Q_\mathcal{G}) \Biggr) \\ & \nabla_\theta \mathcal{L}_\text{po} = \left(1 + \frac{\pi_\theta(t|q,d_{t^+})}{\pi_\theta(t|q,d_{t^-})}\right)^{-1}. \end{aligned} \end{align}\] While \(P_\mathcal{R}^\theta/Q\) compares the retriever confidence against the LLM’s docstring utility assessment, the KL term acts as a global stabilizer that prevents over-adjustments to individual docstrings. Without our preference optimization component, the system simply minimizes differences between retrieval probabilities \(P_\mathcal{R}^\theta\) and downstream log-likelihoods \(\mathcal{Q}_\mathcal{G}\), overlooking LLM handling of imperfect descriptions. Specifically, pure RePlug gradients lack awareness of relative tool utility – a critical shortfall when multiple tools have overlapping or ambiguous descriptions.

The preference optimization contrastive term addresses this by enforcing refinement of tool selection through pairwise comparisons. Unlike the KL penalty, which operates globally, the term \[\left( 1 + \frac{\pi_\theta(t|q,d_{t^+})}{\pi_\theta(t|q,d_{t^-})} \right)^{-1}\] explicitly rewards the retriever for distinguishing between semantically similar but functionally distinct tools (\(d_{t^+}\) and \(d_{t^-}\)). This creates implicit links between tools based on their downstream task performance rather than surface-level similarity. For example, when two API descriptions share terminology but differ in required parameters, the contrastive component amplifies gradients for the tool whose documentation better resolves this ambiguity in practice.

In so doing, PORTS benefits from negative examples not only through the downstream task signal (which can be noisy due to LLM approximation errors) but also through structured semantic comparisons. The retriever learns to associate subtle linguistic cues in tool descriptions with their functional outcomes, even when \(Q_\mathcal{G}\) provides imperfect supervision. This dual mechanism proves critical in real-world scenarios where tool documentation quality varies widely – the contrastive term compensates for sparse or ambiguous \(\mathcal{Q}_\mathcal{G}\) signals by reinforcing discriminative features across the toolset. PORTS’ triplet formulation also enables flexible, state-independent negative sampling, unlike RePlug‘s iterative sampling, which may introduce bias. A qualitative example of PORTS’ retrieval and disambiguation capabilities is shown in Appendix 15.

8 Prompt Templates↩︎

The prompt template for Large Language Models (LLMs) is typically divided into two distinct components: a system message and a user instruction. The system message serves to establish the model’s role and behavioral parameters. In contrast, the user instruction delineates the specific task or query to be addressed. In cases where a model’s chat template does not inherently accommodate a discrete system message, this information is instead prepended to the user instruction. This ensures that the model is primed with all necessary contextual and behavioral guidelines before processing the task at hand. Within the PORTS framework, a frozen LLM is prompted with the input query and the docstring of a retrieved tool to gauge the probability of predicting the target call. During training, we mask the input up to the “Answer” tag and compute the next-token probability of the gold answer using the system and instruction sections as input with a causal attention approach. Our prompt templates are reported in Listing 5 and Listing 6. To better recall the prior knowledge of the model, we describe tools as API functions. We use each model’s specific chat template, omitting special tokens in the listings for clarity. We use a different prompt when working with Llama3-8B to better adhere to the chat template on which it was trained, as suggested in the HuggingFace model card.6

9 Software and Datasets: Details, Intended Use, and Impact↩︎

Despite the popularity of RePlug, no implementation code was publicly available. We dedicated significant effort to reconstructing the method from scratch, carefully clarifying its methodological choices. To benefit the broader research community, we release our complete implementation–including PORTS–as fully open-source under a permissive MIT license. This ensures full reproducibility and establishes the first open-source solution for goal-directed encoder fine-tuning.

Queries, tools, and docstrings can vary greatly depending on the dataset. Table 1, Table 2, Table 3, Table 4, Table 5, and Table 6 show representative input-output examples sampled from the test set of each dataset. Each dataset has been pre-processed to ensure compatibility with our tool-selection task by decoupling instances that require the use of multiple tools. Tool descriptions have been enhanced with detailed information about input and output parameter types, formats, and purposes, following Python-style docstrings to better define the scope of each tool and facilitate the retrieval process. Given the conversational and multi-tool nature of the API-Bank dataset, we have distinguished between inputs for the retriever and generative models. The retriever’s input excludes previous tool calls to avoid biases and inconsistencies in the similarity-based search, while generative models receive the full conversation history. This approach enhances tool selection accuracy while allowing generative models to leverage complete contextual information.

9.0.0.1 Licenses of Used Datasets

All datasets used in our experiments are publicly available and released under permissive open-source licenses. Specifically, ToolBench, ApiBench, Octopus, and BFCLv2 are distributed under the Apache 2.0 License, while ToolE and ApiBank are released under the MIT License. These licenses allow for both academic and commercial use, ensuring full compliance with open-source standards and enabling reproducibility of our experiments.

10 Hyperparameter Space↩︎

Table ¿tbl:tab:hyperparams? presents a comprehensive overview of the hyperparameters explored in our study. This extensive search space was designed to optimize the model’s performance across various dimensions, from basic configuration settings to more nuanced training parameters.

None

Figure 5: Prompt template for call generation with the retrieved tool for Gemma3-1B, Qwen3-4B, Llama3.2-3B, Llama3-8B, and Codestral-22B-v0.1..

None

Figure 6: Prompt template for call generation with the retrieved tool for Llama3-Groq-8B-Tool-Use..

Table 1: ToolBench dataset sample .
Field Text
Query

Please provide me with the user information for the user with the username ’michaelbrown’. Also, fetch the order details for order ID 31415 and get the inventory status of the store.

Gold Tool’s Docstring

def petstore_blitz.getUserByName():
"""
Description:
Fetch user by name.

Arguments:
———
- username : STRING (required)
Description: The name that needs to be fetched. Use user1 for testing.
"""

Answer

petstore_blitz.getUserByName(username="michaelbrown")

Table 2: Octopus dataset sample /.
Field Text
Query

What’s the weather like in New York City for the next three days?

Gold Tool’s Docstring

def get_weather_forecast():
"""
Provides a weather forecast for a specified location over a given number
of days. Each day’s forecast includes a brief description of the expected
weather conditions.

Arguments:
———-
- location (str): The location for which the weather forecast is desired.
Can be a city name, ZIP code, or other location identifiers.

Output:
———
- list[str]: A list of strings, each representing the weather
forecast for one day.
Each string includes the date and a brief description of the weather
conditions. Formatted in ’YYYY-MM-DD: Description’ format.
"""

Answer

get_weather_forecast(’New York City’)

Table 3: API-Bank dataset sample .
Field Text
Query

User: Can you give me a list of all the stress reduction technique categories you offer?
API-Request: [getCategories()]->["Breathing Techniques", "Progressive Muscle Relaxation", "Meditation", "Yoga", "Biofeedback"]
AI: Our available stress reduction technique categories are Breathing Techniques, Progressive Muscle Relaxation, Meditation, Yoga, and Biofeedback.
User: Can you suggest some stress-reducing techniques that are easy to learn?
API-Request: [getTechniques(category=Ńone,́ difficulty=éasy)́]->["name": "Breathing and Grounding Exercise", "description": "This simple technique involves taking a deep breath, exhaling, and grounding yourself by imagining roots growing out of your feet into the ground. This exercise is an excellent way to fall asleep quickly or to calm down when feeling anxious or stressed.", "category": "Breathing Techniques", "difficulty": "easy", "name": "Progressive Muscle Relaxation", "description": "A technique in which you slowly tense and then relax each muscle group of the body. It is particularly useful for relaxation and reducing anxiety.", "category": "Progressive Muscle Relaxation", "difficulty": "easy", "name": "Body Scan Meditation", "description": "This technique requires focusing your attention on different parts of your body and deliberately relaxing them, which can help reduce stress and anxiety.", "category": "Meditation", "difficulty": "easy"]
AI: I recommend the following techniques for easy stress reduction: Breathing and Grounding Exercise, Progressive Muscle Relaxation, and Body Scan Meditation.
User: Can you add the V́isualizationt́echnique to your stress-reducing technique list?
Generate API Request:

Gold Tool’s Docstring

User: Can you give me a list of all the stress reduction technique categories you offer?
AI: Our available stress reduction technique categories are Breathing Techniques, Progressive Muscle Relaxation, Meditation, Yoga, and Biofeedback.
User: Can you suggest some stress-reducing techniques that are easy to learn?
AI: I recommend the following techniques for easy stress reduction: Breathing and Grounding Exercise, Progressive Muscle Relaxation, and Body Scan Meditation.
User: Can you add the ’Visualization’ technique to your stress-reducing technique list?
Generate API Request:

Answer

def addTechnique():
"""
Description:
Add a new stress reduction technique

Arguments:
———
- name : string (optional)
Description: The name of the new stress reduction technique
Format: Not specified
- description : string (optional)
Description: A description of the new stress reduction technique
Format: Not specified
- category : string (optional)
Description: The category of the new stress reduction technique
Format: Not specified
- difficulty : string (optional)
Description: The difficulty level of the new stress reduction technique
Format: Not specified

Output:
———
- data : object (optional)
Description: The newly added stress reduction technique
Format: Not specified
Properties:
- name : string (optional)
Description: The name of the newly added stress reduction technique
Format: Not specified
- description : string (optional)
Description: A description of the newly added stress reduction technique
Format: Not specified
- category : string (optional)
Description: The category of the newly added stress reduction technique
Format: Not specified
- difficulty : string (optional)
Description: The difficulty level of the newly added stress reduction technique
Format: Not specified
"""

Answer

addTechnique(name=’Visualization’, description=’a relaxation exercise in which you create a peaceful mental image of a place or situation’, category=’Meditation’, difficulty=’easy’)

Table 4: APIBench dataset sample .
Field Text
Query

Users want to engage in a conversation with a fictional character based on their persona. This conversation will be used as part of a script for an animation series.

Gold Tool’s Docstring

def AutoModelForCausalLM.from_pretrained(’pygmalion-6b’):
"""
Description:

Pygmalion 6B is a proof-of-concept dialogue model based on EleutherAI’s
GPT-J-6B. The fine-tuning dataset consisted of 56MB of dialogue data
gathered from multiple sources, which includes both real and partially
machine-generated conversations. The model was initialized from the uft-6b
ConvoGPT model and fine-tuned on  48.5 million tokens for  5k steps
on 4 NVIDIA A40s using DeepSpeed.
"""

Answer

AutoModelForCausalLM.from_pretrained(’pygmalion-6b’)

Table 5: BFCL dataset sample .
Field Text
Query

Search for a Chicken Noodle Soup recipe and a Vegan Salad recipe.

Gold Tool’s Docstring

def recipe_search.find():
"""
Description:
Locate recipes based on the type of dish.

Arguments:
———
- dish : string = None (required) The name of the dish to search for.
- diet : string = Keto (optional) Dietary preference.
"""

Answer

recipe_search.find(dish="Chicken Noodle Soup", diet="Vegan")

Table 6: ToolE dataset sample /.
Field Text
Query

Help me with a quick d20 roll, I’ve got a crucial decision to make in my game.

Gold Tool’s Docstring

def diceroller():
"""
Description:
App for rolling dice using the d20 or Fate/Fudge systems.
"""

Answer

diceroller()

width=

11 Computational Budget↩︎

All experiments were performed on machines equipped with NVIDIA RTX 3090 GPUs (24GB VRAM). The total compute time required for training and evaluation across all PORTS’ variants amounted to approximately 500 GPU-hours. This includes finetuning on multiple datasets, ablative experiments, running inference with large language models, and conducting retrieval evaluations.

12 Robustness↩︎

The efficacy of PORTS was evaluated through ablation studies to determine optimal parameter configuration and assess robustness across configuration variations, using the ToolE  dataset with RoBERTa as encoder and Llama3-8B as generative models. To demonstrate the effectiveness of the contrastive loss, we examined the impact of using different numbers of negative examples in the learning process, with results in Figure 7 illustrating advantages of incorporating larger numbers of examples which better guide preference optimization. We investigated the effects of varying weighting factors \(\beta\) and \(\gamma\), with Figure 8 showing higher \(\beta\) and lower \(\gamma\) values yield improved results, optimal when both are set to 0.5. Additionally, we examined the influence of random seeds on our method, focusing on their impact on input data distribution and dropout layer behavior, with results in Table ¿tbl:tab:avg95recall95seed? demonstrating the robustness and effectiveness of PORTS and its low variance in response to such configuration changes.

Figure 7: Average Recall@K across different numbers of negatives and seeds on the ToolE  dataset using ModernBERT and Llama3-8B.
Figure 8: Confusion Matrix for Average Recall@K on the ToolE  dataset using ModernBERT and Llama3-8B, with varying \beta and \gamma hyperparameters.

width=.85

13 Clustering Properties of Tool Embeddings↩︎

API docstrings exhibit skewed token distributions, dominated by recurring elements such as data types and keywords. Compared to general-domain retrieval corpora, tool-related datasets form well-separated semantic clusters, owing to their concise yet distinctive functional signatures. Without targeted supervision, these structural properties can lead retrieval models to rely on superficial lexical cues or converge toward trivial matches. To characterize the clustering tendency of these representations, we apply standard unsupervised algorithms–including K-Means (with \(K \in [2, 16]\)), Agglomerative Clustering (Ward linkage), and DBSCAN (with \(\epsilon = 0.3\))—on 20,000 randomly sampled embedding vectors per dataset. We use four top-performing models from the MTEB leaderboard7 to extract these representations: BAAI/bge-m3,8 intfloat/multilingual-e5-large-instruct,9 answerdotai/ModernBERT-base,10 and Alibaba-NLP/gte-multilingual-base.11 The silhouette coefficient is computed to quantify clustering quality, capturing both intra-cluster cohesion and inter-cluster separation. As summarized in Figure 9, tool-centric datasets consistently achieve higher silhouette scores than general-domain corpora, including MSMarco [61], HotpotQA [62], and PubMedQA [63]. This high clustering tendency presents a fundamental limitation where semantically similar tools concentrate within the same dense clusters, making contrastive supervision essential to differentiate tools that share similar descriptive features yet possess distinct functionalities and produce varying effects on LLM behavior, necessitating targeted intra-cluster contrastive learning to prevent training from optimizing merely for tool relevance rather than functional effectiveness. This gap highlights the stronger intrinsic structure of tool embeddings and further motivates our contrastive supervision strategy to promote fine-grained, functionally meaningful distinctions beyond those induced by LLM likelihoods alone.

Figure 9: Average Silhouette scores across datasets (top–general-domain, bottom–tool-specific) and clustering algorithms, computed over 20,000 sampled embeddings per dataset. Results are aggregated across multiple encoder models. Higher scores indicate more compact and well-separated clusters, reflecting stronger semantic structure in the embedding space.

width=

width=

14 Complete Results↩︎

Table ¿tbl:tab:results95roberta? and Table ¿tbl:tab:results95bge? complement the results of the main paper, listing the retrieval scores achieved by training encoders under the supervision signal of each LLM explored.

15 Qualitative Example↩︎

Table 10 presents a specific query from the ToolE test set, demonstrating the contrast between the top-3 tools retrieved by BGE with and without PORTS tuning. The results clearly illustrate that our alignment process not only successfully positions the correct tool at the top rank, but also generates a significantly sharpened preference distribution.

Figure 10: Input-output tool selection example from the ToolE test set. Cosine similarity comparison between PORTS-tuned BGE (left) and baseline, frozen BGE (right).

References↩︎

[1]
C. Qu, S. Dai, X. Wei, et al., “Tool learning with large language models: A survey,” CoRR, vol. abs/2405.17935, 2024, doi: 10.48550/ARXIV.2405.17935.
[2]
S. Yao, H. Chen, J. Yang, et al., “WebShop: Towards scalable real-world web interaction with grounded language agents,” in NeurIPS, 2022, [Online]. Available: http://papers.nips.cc/paper\_files/paper/2022/hash/82ad13ec01f9fe44c01cb91814fd7b8c-Abstract-Conference.html.
[3]
A. Lazaridou, E. Gribovskaya, W. Stokowiec, et al., “Internet-augmented language models through few-shot prompting for open-domain question answering,” CoRR, vol. abs/2203.05115, 2022, doi: 10.48550/ARXIV.2203.05115.
[4]
S. Qiao, H. Gui, H. Chen, et al., “Making language models better tool learners with execution feedback,” CoRR, vol. abs/2305.13068, 2023, doi: 10.48550/ARXIV.2305.13068.
[5]
R. Yang, L. Song, Y. Li, et al., “GPT4Tools: Teaching large language model to use tools via self-instruction,” in NeurIPS, 2023, [Online]. Available: http://papers.nips.cc/paper\_files/paper/2023/hash/e393677793767624f2821cec8bdd02f1-Abstract-Conference.html.
[6]
N. F. Liu et al., “Lost in the middle: How language models use long contexts,” TACL, vol. 12, pp. 157–173, 2024, doi: 10.1162/TACL\_A\_00638.
[7]
C. Qu, S. Dai, X. Wei, et al., COLT: Towards completeness-oriented tool retrieval for large language models,” CoRR, vol. abs/2405.16089, 2024, doi: 10.48550/ARXIV.2405.16089.
[8]
Y. Qin, S. Liang, Y. Ye, et al., “ToolLLM: Facilitating large language models to master 16000+ real-world APIs,” in ICLR, 2024, [Online]. Available: https://openreview.net/forum?id=dHng2O0Jjr.
[9]
S. Gao, Z. Shi, M. Zhu, et al., “Confucius: Iterative tool learning from introspection feedback by easy-to-difficult curriculum,” in AAAI, 2024, pp. 18030–18038, doi: 10.1609/AAAI.V38I16.29759.
[10]
R. Anantha, B. Bandyopadhyay, A. Kashi, et al., “ProTIP: Progressive tool retrieval improves planning,” CoRR, vol. abs/2312.10332, 2023, doi: 10.48550/ARXIV.2312.10332.
[11]
S. Lodi, G. Moro, and C. Sartori, “Distributed data clustering in multi-dimensional peer-to-peer networks,” in Database technologies 2010, twenty-first australasian database conference (ADC 2010), 2010, vol. 104, pp. 171–178, [Online]. Available: http://portal.acm.org/citation.cfm?id=1862264\&CFID=17470975\&CFTOKEN=71845406.
[12]
S. G. Patil, T. Zhang, X. Wang, et al., “Gorilla: Large language model connected with massive APIs,” CoRR, vol. abs/2305.15334, 2023, doi: 10.48550/ARXIV.2305.15334.
[13]
W. Yu, H. Zhang, X. Pan, et al., “Chain-of-note: Enhancing robustness in retrieval-augmented language models,” CoRR, vol. abs/2311.09210, 2023, doi: 10.48550/ARXIV.2311.09210.
[14]
F. Shi, X. Chen, K. Misra, et al., “Large language models can be easily distracted by irrelevant context,” in ICML, 2023, vol. 202, pp. 31210–31227, [Online]. Available: https://proceedings.mlr.press/v202/shi23a.html.
[15]
G. Izacard, P. S. H. Lewis, M. Lomeli, et al., “Atlas: Few-shot learning with retrieval augmented language models,” JMLR, vol. 24, pp. 251:1–251:43, 2023, [Online]. Available: http://jmlr.org/papers/v24/23-0037.html.
[16]
X. V. Lin, X. Chen, M. Chen, et al., RA-DIT: Retrieval-augmented dual instruction tuning,” in ICLR, 2024, [Online]. Available: https://openreview.net/forum?id=22OTbutug9.
[17]
X. Cheng, D. Luo, X. Chen, et al., “Lift yourself up: Retrieval-augmented text generation with self-memory,” in NeurIPS, 2023, [Online]. Available: http://papers.nips.cc/paper\_files/paper/2023/hash/887262aeb3eafb01ef0fd0e3a87a8831-Abstract-Conference.html.
[18]
D. Bolya, P.-Y. Huang, and P. S. et al., “Perception encoder: The best visual embeddings are not at the output of the network,” CoRR, vol. abs/2504.13181, 2025, doi: 10.48550/arXiv.2504.13181.
[19]
A. Parisi, Y. Zhao, and N. Fiedel, TALM: Tool augmented language models,” CoRR, vol. abs/2205.12255, 2022, doi: 10.48550/ARXIV.2205.12255.
[20]
T. Schick, J. Dwivedi-Yu, R. Dessı̀, et al., “Toolformer: Language models can teach themselves to use tools,” in NeurIPS, 2023, [Online]. Available: http://papers.nips.cc/paper\_files/paper/2023/hash/d842425e4bf79ba039352da0f658a906-Abstract-Conference.html.
[21]
S. Hao, T. Liu, Z. Wang, et al., “ToolkenGPT: Augmenting frozen language models with massive tools via tool embeddings,” in NeurIPS, 2023, [Online]. Available: http://papers.nips.cc/paper\_files/paper/2023/hash/8fd1a81c882cd45f64958da6284f4a3f-Abstract-Conference.html.
[22]
I. Abdelaziz, K. Basu, M. Agarwal, et al., “Granite-function calling model: Introducing function calling abilities via multi-task learning of granular tasks,” CoRR, vol. abs/2407.00121, 2024, doi: 10.48550/ARXIV.2407.00121.
[23]
OpenAI, GPT-4 technical report,” CoRR, vol. abs/2303.08774, 2023, doi: 10.48550/ARXIV.2303.08774.
[24]
Nexusflow.ai, “NexusRaven: Surpassing the state-of-the-art in open-source function calling LLMs.” 2023, [Online]. Available: http://nexusflow.ai/blog.
[25]
Y. Shen, K. Song, X. Tan, et al., “HuggingGPT: Solving AI tasks with ChatGPT and its friends in hugging face,” in NeurIPS, 2023, [Online]. Available: http://papers.nips.cc/paper\_files/paper/2023/hash/77c33e6a367922d003ff102ffb92b658-Abstract-Conference.html.
[26]
Y. Song, W. Xiong, D. Zhu, et al., “RestGPT: Connecting large language models with real-world applications via RESTful APIs,” CoRR, vol. abs/2306.06624, 2023, doi: 10.48550/ARXIV.2306.06624.
[27]
S. Yao, J. Zhao, D. Yu, et al., “ReAct: Synergizing reasoning and acting in language models,” in ICLR, 2023, [Online]. Available: https://openreview.net/forum?id=WE\_vluYUL-X.
[28]
K. S. Jones, “A statistical interpretation of term specificity and its application in retrieval,” J. Documentation, vol. 60, no. 5, pp. 493–502, 2004, doi: 10.1108/00220410410560573.
[29]
S. E. Robertson and H. Zaragoza, “The probabilistic relevance framework: BM25 and beyond,” Found. Trends Inf. Retr., vol. 3, no. 4, pp. 333–389, 2009, doi: 10.1561/1500000019.
[30]
L. Yuan, Y. Chen, X. Wang, et al., CRAFT: Customizing LLMs by creating and retrieving from specialized toolsets,” in ICLR, 2024, [Online]. Available: https://openreview.net/forum?id=G0vdDSt9XM.
[31]
G. Domeniconi, G. Moro, R. Pasolini, and C. Sartori, “Iterative refining of category profiles for nearest centroid cross-domain text classification,” in Knowledge discovery, knowledge engineering and knowledge management, 2014, 2014, vol. 553, pp. 50–67, doi: 10.1007/978-3-319-25840-9\_4.
[32]
G. Domeniconi, G. Moro, R. Pasolini, and C. Sartori, “Cross-domain text classification through iterative refining of target categories representations,” in KDIR 2014, 2014, pp. 31–42, doi: 10.5220/0005069400310042.
[33]
G. Domeniconi, G. Moro, A. Pagliarani, and R. Pasolini, “Markov chain based method for in-domain and cross-domain sentiment classification,” in KDIR 2015, 2015, pp. 127–137, doi: 10.5220/0005636001270137.
[34]
Y. Kong, J. Ruan, Y. Chen, et al., “TPTU-v2: Boosting task planning and tool usage of large language model-based agents in real-world systems,” CoRR, vol. abs/2311.11315, 2023, doi: 10.48550/ARXIV.2311.11315.
[35]
Y. Zheng, P. Li, W. Liu, et al., ToolRerank: Adaptive and hierarchy-aware reranking for tool retrieval,” in LREC-COLING 2024, May 2024, pp. 16263–16273, [Online]. Available: https://aclanthology.org/2024.lrec-main.1413.
[36]
S. Borgeaud, A. Mensch, J. Hoffmann, et al., “Improving language models by retrieving from trillions of tokens,” in ICML, 2022, vol. 162, pp. 2206–2240, [Online]. Available: https://proceedings.mlr.press/v162/borgeaud22a.html.
[37]
G. Izacard and E. Grave, “Leveraging passage retrieval with generative models for open domain question answering,” in EACL, 2021, pp. 874–880, doi: 10.18653/V1/2021.EACL-MAIN.74.
[38]
K. Guu, K. Lee, Z. Tung, et al., “Retrieval augmented language model pre-training,” in ICML, 2020, vol. 119, pp. 3929–3938, [Online]. Available: http://proceedings.mlr.press/v119/guu20a.html.
[39]
M. Li, X. Li, Y. Chen, et al., “Unraveling and mitigating retriever inconsistencies in retrieval-augmented large language models,” CoRR, vol. abs/2405.20680, 2024, doi: 10.48550/ARXIV.2405.20680.
[40]
V. Karpukhin, B. Oguz, S. Min, et al., “Dense passage retrieval for open-domain question answering,” in EMNLP, 2020, pp. 6769–6781, doi: 10.18653/V1/2020.EMNLP-MAIN.550.
[41]
S. Siriwardhana, R. Weerasekera, T. Kaluarachchi, et al., “Improving the domain adaptation of retrieval augmented generation (RAG) models for open domain question answering,” TACL, vol. 11, pp. 1–17, 2023, doi: 10.1162/TACL\_A\_00530.
[42]
W. Shi, S. Min, M. Yasunaga, et al., REPLUG: Retrieval-augmented black-box language models,” in NAACL, Jun. 2024, pp. 8371–8384, doi: 10.18653/v1/2024.naacl-long.463.
[43]
P. F. Christiano, J. Leike, T. B. Brown, et al., “Deep reinforcement learning from human preferences,” in NeurIPS, 2017, pp. 4299–4307, [Online]. Available: https://proceedings.neurips.cc/paper/2017/hash/d5e2c0adad503c91f91df240d0cd4e49-Abstract.html.
[44]
R. Rafailov, A. Sharma, E. Mitchell, et al., “Direct preference optimization: Your language model is secretly a reward model,” in NeurIPS, 2023, [Online]. Available: http://papers.nips.cc/paper\_files/paper/2023/hash/a85b405ed65c6477a4fe8302b5e06ce7-Abstract-Conference.html.
[45]
J. Hong, N. Lee, and J. Thorne, ORPO: Monolithic preference optimization without reference model,” CoRR, vol. abs/2403.07691, 2024, doi: 10.48550/ARXIV.2403.07691.
[46]
M. Kaya and H. S. Bilge, “Deep metric learning: A survey,” Symmetry, vol. 11, no. 9, p. 1066, 2019, doi: 10.3390/SYM11091066.
[47]
M. Li, Y. Zhao, B. Yu, et al., API-bank: A comprehensive benchmark for tool-augmented LLMs,” in EMNLP, Dec. 2023, pp. 3102–3116, doi: 10.18653/v1/2023.emnlp-main.187.
[48]
Y. Peng, S. Li, W. Gu, et al., “Revisiting, benchmarking and exploring API recommendation: How far are we?” IEEE Trans. Software Eng., vol. 49, no. 4, pp. 1876–1897, 2023, doi: 10.1109/TSE.2022.3197063.
[49]
F. Yan, H. Mao, C. C.-J. Ji, et al., “Berkeley function calling leaderboard.” https://gorilla.cs.berkeley.edu/blogs/8_berkeley_function_calling_leaderboard.html, 2024.
[50]
Y. Huang, J. Shi, Y. Li, et al., “MetaTool benchmark for large language models: Deciding whether to use tools and which to use,” in ICLR, 2024, [Online]. Available: https://openreview.net/forum?id=R0c2qtalgG.
[51]
W. Chen and Z. Li, “Octopus v2: On-device language model for super agent,” CoRR, vol. abs/2404.01744, 2024, doi: 10.48550/ARXIV.2404.01744.
[52]
M. Zhu, “Recall, precision and average precision,” Department of Statistics and Actuarial Science, University of Waterloo, Waterloo, vol. 2, no. 30, p. 6, 2004.
[53]
K. Järvelin and J. Kekäläinen, “Cumulated gain-based evaluation of IR techniques,” ACM Trans. Inf. Syst., vol. 20, no. 4, pp. 422–446, 2002, doi: 10.1145/582415.582418.
[54]
Y. Liu, M. Ott, N. Goyal, et al., “RoBERTa: A robustly optimized BERT pretraining approach,” CoRR, vol. abs/1907.11692, 2019, [Online]. Available: http://arxiv.org/abs/1907.11692.
[55]
S. Xiao, Z. Liu, P. Zhang, et al., “C-pack: Packed resources for general chinese embeddings,” in SIGIR, 2024, pp. 641–649, doi: 10.1145/3626772.3657878.
[56]
A. Dubey, A. Jauhri, and A. P. et al., “The llama 3 herd of models.” 2024, [Online]. Available: https://arxiv.org/abs/2407.21783.
[57]
W. Wang et al., “A survey of LLM-based agents in medicine: How far are we from baymax?” in ACL 2025, 2025, pp. 10345–10359, [Online]. Available: https://aclanthology.org/2025.findings-acl.539/.
[58]
G. Domeniconi, M. Masseroli, G. Moro, and P. Pinoli, “Cross-organism learning method to discover new gene functionalities,” Comput. Methods Programs Biomed., vol. 126, pp. 20–34, 2016, doi: 10.1016/J.CMPB.2015.12.002.
[59]
G. Domeniconi, M. Masseroli, G. Moro, and P. Pinoli, “Discovering new gene functionalities from random perturbations of known gene ontological annotations,” in KDIR 2014, 2014, pp. 107–116, doi: 10.5220/0005087801070116.
[60]
P. di Lena, G. Domeniconi, L. Margara, and G. Moro, GOTA: GO term annotation of biomedical literature,” BMC Bioinform., vol. 16, pp. 346:1–346:13, 2015, doi: 10.1186/S12859-015-0777-8.
[61]
T. Nguyen et al., MS MARCO: A human generated MAchine reading COmprehension dataset,” CoRR, vol. abs/1611.09268, 2016, [Online]. Available: http://arxiv.org/abs/1611.09268.
[62]
Z. Yang et al., “HotpotQA: A dataset for diverse, explainable multi-hop question answering,” in EMNLP, 2018, 2018, pp. 2369–2380, doi: 10.18653/V1/D18-1259.
[63]
Q. Jin, B. Dhingra, Z. Liu, W. W. Cohen, and X. Lu, “PubMedQA: A dataset for biomedical research question answering,” in EMNLP-IJCNLP 2019, 2019, pp. 2567–2577, doi: 10.18653/V1/D19-1259.

  1. Code, models, and datasets are publicly available at https://github.com/disi-unibo-nlp/ports↩︎

  2. Consistent with [1], we argue that all external means of augmenting LLMs should be classified as tools. Accordingly, we regard individual APIs as separate tools.↩︎

  3. huggingface.co/spaces/mteb/leaderboard↩︎

  4. huggingface.co/mistralai/Codestral-22B-v0.1↩︎

  5. huggingface.co/Groq/Llama-3-Groq-8B-Tool-Use↩︎

  6. huggingface.co/Groq/Llama-3-Groq-8B-Tool-Use↩︎

  7. huggingface.co/spaces/mteb/leaderboard↩︎

  8. huggingface.co/BAAI/bge-m3↩︎

  9. huggingface.co/intfloat/multilingual-e5-large-instruct↩︎

  10. huggingface.co/answerdotai/ModernBERT-base↩︎

  11. huggingface.co/Alibaba-NLP/gte-multilingual-base↩︎