Abstract
Tool-augmented large language models (LLMs) leverage tools, often in the form of APIs, to enhance their reasoning capabilities on complex tasks, thus taking on the role of intelligent agents interacting with the real world. The recently introduced ToolLLaMA model by Qin et al. [2024] utilizes the depth-first search-based decision tree (DFSDT) method for reasoning with 16,000+ real-world APIs, which effectively improves the planning and inferencing performance of tool-augmented LLMs compared to traditional chain reasoning approaches. However, their approach only employs successful paths from decision trees (also called inference trees) for supervised fine-tuning (SFT) during training, which does not fully exploit the advantages of the tree of thought. In this study, we propose an inference trajectory optimization framework based on the preference data extracted from decision trees to address this limitation. We first introduce a novel method for constructing preference data from the tree of thought, capitalizing on the failed explorations previously overlooked in the trees. Specifically, we generate an effective step-wise preference dataset, named ToolPreference, for tool use based on the ToolBench dataset. In the subsequent training phase, we first fine-tune the LLM with tool-usage expert trajectories and then use these step-wise preference pairs for direct preference optimization (DPO) to update the policy of the LLM, resulting in our ToolPrefer-LLaMA (TP-LLaMA) model. Our experiments demonstrate that by obtaining insights from errors in inference trees, TP-LLaMA significantly outperforms the baselines across almost all test scenarios by a large margin and exhibits better generalization capabilities with unseen APIs. At the same time, TP-LLaMA has also demonstrated superior reasoning efficiency compared to the baselines, making it more suitable for complex tool-usage reasoning tasks.
Introduction
To solve complex real-world tasks, Large Language Models (LLMs) often need to use external tools (APIs) like search engines, calculators, or database connectors. Current state-of-the-art models like ToolLLaMA use a "Depth-First Search Decision Tree" (DFSDT) to explore various API combinations until they find a path that works. However, traditional training methods, such as Supervised Fine-Tuning (SFT), typically only utilize the final "golden path" of success. This approach is akin to a student who only sees correct answers without understanding why their incorrect attempts were wrong. Consequently, these models often repeat mistakes during inference, wasting computational resources on unproductive branches of the decision tree or failing to generalize to new tools.
Methodology
The proposed framework, TP-LLaMA, addresses these limitations by leveraging the "failed" explorations already present in expert data. The training pipeline consists of two primary stages: first, the model undergoes SFT on successful trajectories to learn basic tool usage; second, it undergoes Direct Preference Optimization (DPO) using a novel dataset. While primarily tested on LLaMA-2-7B, the framework's model-agnostic nature was demonstrated through successful applications to Mistral, Qwen, and Gemma.
Step-wise Preference Data Construction
A key contribution of this work is the construction of the ToolPreference dataset. Instead of comparing entire successful vs. failed paths, the authors decompose the decision tree into individual steps. At any node, if the expert search chose a branch leading to success over one leading to a dead end, a preference pair is created. This dataset consists of 69,393 pairs of step-wise preference samples extracted from the ToolBench dataset, which contains over 16,000 real-world APIs.
Results
Empirical evaluations demonstrate that TP-LLaMA significantly outperforms its predecessors across six different test scenarios. The model achieved an average pass rate of 65%, a substantial improvement over the 49% pass rate of the original ToolLLaMA and the 53% of standard SFT models. Furthermore, TP-LLaMA exhibits superior reasoning efficiency, reaching correct answers in an average of 22.62 steps, compared to 32.06 steps for the SFT baseline—a nearly 30% improvement in speed. The model also showed strong generalization capabilities on "unseen" APIs, suggesting it has learned the underlying logic of tool interaction rather than just memorizing sequences.
Discussion and Conclusion
The core philosophy of TP-LLaMA is that failure is a rich data source—as the proverb goes, "a fall into a pit, a gain in your wit." By explicitly teaching the model what to avoid, it develops a finer-grained understanding of the reasoning process and learns to "prune" its internal search tree effectively. While the method's success depends on the quality and diversity of the initial expert decision trees, it marks a significant step forward in making tool-augmented LLMs more efficient and robust. Future work may involve distinguishing between different types of failures and implementing context condensation techniques to handle longer reasoning histories.
Summary updated