From Failure to Mastery: Generating Hard Samples for Tool-use Agents

Bingguang Hao, Zengzhuang Xu, Yuntao Wen, Xinyi Xu, Yang Liu, Tong Zhao, Maolin Wang, Long Chen, Dong Wang, Yicheng Chen, Cunyin Peng, Xiangyu Zhao, Chenyi Zhuang, Ji Zhang

Abstract

The advancement of LLM agents with tool-use capabilities requires diverse and complex training corpora. Existing data generation methods, which predominantly follow a paradigm of random sampling and shallow generation, often yield simple and homogeneous trajectories that fail to capture complex, implicit logical dependencies. To bridge this gap, we introduce HardGen, an automatic agentic pipeline designed to generate hard tool-use training samples with verifiable reasoning. Firstly, HardGen establishes a dynamic API Graph built upon agent failure cases, from which it samples to synthesize hard traces. Secondly, these traces serve as conditional priors to guide the instantiation of modular, abstract advanced tools, which are subsequently leveraged to formulate hard queries. Finally, the advanced tools and hard queries enable the generation of verifiable complex Chain-of-Thought (CoT), with a closed-loop evaluation feedback steering the continuous refinement of the process. Extensive evaluations demonstrate that a 4B parameter model trained with our curated dataset achieves superior performance compared to several leading open-source and closed-source competitors (e.g., GPT-5.2, Gemini-3-Pro and Claude-Opus-4.5). Our code, models, and dataset will be open-sourced to facilitate future research.

Introduction

Large Language Models (LLMs) are increasingly deployed as autonomous agents capable of interacting with external environments through API calls. However, the efficacy of these agents is heavily dependent on the quality of their training data. Current synthetic data generation methods often rely on random sampling and shallow simulations, resulting in "happy path" trajectories where instructions are explicit and logical steps are trivial.

In real-world scenarios, tasks are rarely so straightforward. They often require "implicit logical bridging"—the ability to infer necessary intermediate steps that are not explicitly stated in a user's query. For example, a model might need to retrieve a specific user ID before it can execute a subscription update, even if the user only requested the latter. Existing models frequently struggle with these intertwined, multi-step instructions. To address this, we present HardGen, a pipeline specifically engineered to generate complex, verifiable training samples by focusing on model failure modes.

Methodology: The HardGen Pipeline

HardGen operates through a three-phase agentic process designed to elevate the complexity of synthetic tool-use data:

1. Failure-inspired Hard Trace Sampling

Rather than sampling APIs at random, HardGen identifies "failure APIs"—tools that current state-of-the-art models consistently fail to utilize correctly. By constructing a dynamic API Graph based on these failure cases, the pipeline samples "hard traces." These traces represent sequences of tool calls that pose genuine reasoning hurdles, ensuring the training data targets the model's existing weaknesses.

2. Trace-conditioned Tool Evolution

To force the model to develop robust planning capabilities, HardGen employs a technique called Tool Evolution. It takes a multi-step trace (e.g., get_zipcode → buy_tickets) and abstracts the sequence into a single Advanced Tool (e.g., buy_tickets_advanced). The pipeline then generates a Hard Query that specifies only the high-level goal. By removing the explicit "shortcut" tools from the immediate context, the trainee model is forced to decompose the high-level goal into its constituent primitive tool calls, effectively teaching it to bridge logical gaps autonomously.

3. Feedback-guided CoT Refinement

To ensure the accuracy of the generated trajectories, HardGen utilizes a Reasoner-Verifier loop. When a model generates a Chain-of-Thought (CoT) or tool call, a Verifier checks the output against the execution environment. If the output is incorrect, the Verifier provides a "hint" rather than the direct answer, guiding the model toward the correct solution. This iterative refinement ensures that the final dataset consists of high-quality, executable, and verifiable reasoning paths.

Experimental Results

We curated the HardGen Dataset, containing 27,000 trajectories across 2,095 real-world APIs spanning domains such as Finance, Gaming, and Data Analysis. We evaluated our model, HardGen-4B-RL, against the Berkeley Function Calling Leaderboard (BFCLv3), APIBank, and ACEBench.

Figure 1: BFCLv3 Leaderboard Performance comparing HardGen-4B-RL against industry-leading models.

As shown in the performance leaderboard, the HardGen-4B-RL model achieved an overall accuracy of 79.14% on BFCLv3. Remarkably, this 4B-parameter model outperformed significantly larger proprietary models, including GPT-5.2 (60.12%), Gemini-3-Pro (78.17%), and Claude-Opus-4.5 (78.92%).

The most significant performance gains were observed in multi-turn trajectories, where the model's accuracy improved from a base of 22.13% to 63.13%—a +41% increase. Furthermore, the methodology proved architecture-agnostic; applying HardGen to the Llama-3 family resulted in similar double-digit performance boosts.

Conclusion

The success of HardGen demonstrates that for specialized tasks like tool-use, data quality and logical complexity are more critical than raw parameter count. By focusing on failure cases and utilizing abstraction as a catalyst for reasoning, we can train small, efficient models to outperform industry giants. Future work will focus on scaling this pipeline to proprietary API ecosystems where executable sandboxes are more difficult to maintain.

Summary updated

BibTeX
@misc{hao2026from,
  author = {Bingguang Hao and Zengzhuang Xu and Yuntao Wen and Xinyi Xu and Yang Liu and Tong Zhao and Maolin Wang and Long Chen and Dong Wang and Yicheng Chen and Cunyin Peng and Xiangyu Zhao and Chenyi Zhuang and Ji Zhang},
  title = {{From Failure to Mastery: Generating Hard Samples for Tool-use Agents}},
  year = {2026},
  eprint = {2601.01498},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2601.01498},
}
Figure