Introduction
Large Language Models (LLMs) are increasingly utilized as agents capable of interacting with external tools such as search engines, calculators, and specialized APIs. However, the effectiveness of these models is often hampered by the precision required for tool calls. A single incorrect token—such as a misplaced bracket or an incorrect parameter type—can lead to a complete failure of the API interaction. Traditional training methods, like Supervised Fine-Tuning (SFT) and trajectory-level Reinforcement Learning (RL), often fail to address these fine-grained errors, leading to "coarse-grained" evaluations that overlook critical token-level discrepancies.
The TTPA Framework
To address these limitations, we introduce the Token-level Tool-use Preference Alignment (TTPA) training framework. TTPA shifts the focus from entire trajectories to individual tokens, ensuring that models learn the precise syntax and logic required for successful tool usage. The framework is built upon three core innovations:
- Reversed Dataset Construction: Traditional synthetic data generation often results in "data leakage" or unsolvable queries. TTPA reverses this process: it first prompts an LLM to simulate a scenario, select tools, and generate an answer. A user query is then generated based on this successful execution path. This ensures that every training example is solvable and that the model learns to infer tool requirements rather than simply repeating information from the prompt.
- Token-level Preference Sampling (TPS): Instead of comparing entirely different reasoning paths, TPS focuses on the model's internal uncertainty. By identifying tokens where the model's probability distribution is closely contested, TPS introduces controlled perturbations to create realistic, subtle errors. This forces the model to learn from the exact types of mistakes it is prone to making.
- Error-oriented Scoring Mechanism (ESM): Perturbed tool calls are evaluated using a deterministic scoring taxonomy that checks for format errors, incorrect tool names, missing parameters, and type/value mismatches. These fine-grained scores allow for the creation of high-quality "Preferred" and "Dispreferred" pairs for Direct Preference Optimization (DPO).
Experimental Evaluation
The TTPA framework was applied to fine-tune a Qwen2.5-7B-Instruct model. The training dataset consisted of 3,895 instructions and 8,550 preference pairs covering 114 unique APIs. Evaluation was conducted across several rigorous benchmarks:
- ToolBench: Assessing performance under various query lengths and tool configurations.
- BFCL (Berkeley Function Calling Benchmark): Measuring syntactic correctness via Abstract Syntax Trees.
- General Reasoning Benchmarks: MMLU-pro, HellaSwag, GSM8K, and CommonSenseQA were used to monitor for catastrophic forgetting.
Key Results
The TTPA-tuned 7B model demonstrated significant improvements over both open-source and proprietary baselines. On the ToolBench I1-instruction (Vanilla) subset, it achieved an 86.0% pass rate, surpassing GPT-4o-mini (82.0%) and specialized models like ToolACE-8B (77.0%).
Crucially, the fine-grained alignment did not come at the cost of general intelligence. As shown in the radar chart below, the TTPA model maintained competitive performance across general reasoning tasks while significantly outperforming peers in tool-use accuracy. In custom fine-grained evaluations, the model showed an average improvement of 11.8% in parameter accuracy (choosing and filling) compared to baseline models.
Conclusion
TTPA provides a robust framework for aligning LLMs with the precise requirements of tool usage. By emphasizing token-level accuracy and utilizing a reversed data generation strategy, the framework effectively mitigates common failure modes in API interactions. Future work will focus on reducing the computational overhead of token-level sampling and expanding the framework to handle dynamic, ever-changing tool environments.
Summary updated