Abstract
Fine-tuning Large Language Models (LLMs) for agentic tasks often treats all tokens with equal importance, leading to models that overfit on repetitive formatting (boilerplate) rather than mastering core logic (reasoning). This paper introduces a novel framework to address this: the Shuffle-Aware Discriminator (SHAD), which automatically distinguishes between reasoning and boilerplate tokens, and Reasoning-highlighted Fine-Tuning (RFT), an adaptive training approach that prioritizes logic over structure. Our method significantly improves model performance on complex agentic tasks and tool-use benchmarks, particularly in out-of-distribution scenarios.
Introduction
When fine-tuning LLMs to act as agents—performing multi-step planning or calling external tools—datasets typically follow a highly structured format (e.g., "Thought: ... Action: ..."). Standard Supervised Fine-Tuning (SFT) treats every token as equally critical. However, tokens like "Thought:" and "Action:" are boilerplate: they are repetitive, sample-independent, and easy for the model to memorize. In contrast, the reasoning tokens—the specific logic connecting a query to a tool—are harder to learn and essential for generalization.
Treating these roles identically often results in models that follow formatting perfectly but fail on actual reasoning. This paper proposes disentangling these roles to focus the model's learning capacity on the logic that matters most.
Methodology
The proposed framework consists of two primary stages: automated classification via SHAD and prioritized training via RFT.
1. Shuffle-Aware Discriminator (SHAD)
SHAD identifies token roles without manual labeling by exploiting the statistical nature of boilerplate. Boilerplate tokens are "sample-independent"; they appear across many different tasks regardless of the specific input. By shuffling the dataset—pairing random queries with random responses—a model can still learn to predict boilerplate because of its high frequency and consistency. However, it will fail to predict reasoning tokens because they no longer logically follow the shuffled query. By comparing the loss of a model trained on shuffled data against a reference model, SHAD identifies tokens where the loss is low (boilerplate) versus those where it remains high (reasoning).
2. Reasoning-highlighted Fine-Tuning (RFT)
Once tokens are classified, RFT modifies the training process using an adaptive weighting scheme. Instead of standard cross-entropy loss, RFT calculates separate losses for reasoning and boilerplate groups. It then uses a softmax-based temperature coefficient to assign higher weights to the group with the higher loss—typically the reasoning tokens. This prevents the model from "getting lazy" by perfecting easy boilerplate while ignoring difficult logic.
Experimental Setup and Datasets
The researchers utilized a diverse mix of datasets for training and evaluation:
- Training: ToolBench and APIGen for tool-use logic, supplemented with ShareGPT for general conversation.
- Evaluation: Held-in benchmarks included StableToolBench and the Berkeley Function Calling Leaderboard (BFCL). To test generalization, held-out benchmarks like T-eval (step-level reasoning) and Nexus (complex nested tool use) were employed.
Key Results and Insights
The SHAD+RFT method consistently outperformed standard SFT and advanced baselines across all benchmarks.
- Generalization Gains: On the challenging Nexus benchmark, SHAD+RFT improved LLaMA3-8B's performance from 14.0% to 27.8%.
- Loss Dynamics: Analysis of training curves shows that while boilerplate loss drops rapidly and stays low, reasoning loss is much harder to minimize. RFT successfully forces the model to maintain focus on these high-loss reasoning tokens throughout the training process.
Qualitatively, models trained with RFT were less likely to hallucinate or generate erroneous template phrases when faced with out-of-distribution instructions, demonstrating a more robust grasp of underlying task logic rather than just surface-level patterns.
Conclusion and Future Work
By disentangling reasoning from boilerplate, we can train more capable and generalizable AI agents. While the current method relies on relatively consistent boilerplate across a dataset, future work will explore more granular, token-level importance spectrums and expanding this approach to the broader domain of general Supervised Fine-Tuning.
Summary updated