Abstract
Prior work synthesizes tool-use LLM datasets by first generating a user query, followed by complex tool-use annotations like DFS. This leads to inevitable annotation failures and low efficiency in data generation. We introduce ToolGrad, an agentic framework that inverts this paradigm. ToolGrad first constructs valid tool-use chains through an iterative process guided by textual "gradients", and then synthesizes corresponding user queries. This "answer-first" approach led to ToolGrad-5k, a dataset generated with more complex tool use, lower cost, and 100% pass rate. Experiments show that models trained on ToolGrad-5k outperform those on expensive baseline datasets and proprietary LLMs, even on OOD benchmarks.
Introduction
To perform real-world tasks, Large Language Models (LLMs) must master tool-use—the ability to call external APIs for information or actions. Training models for this capability requires high-quality datasets pairing user queries with correct tool-use sequences. Traditionally, synthetic data generation relies on a "query-first" paradigm: generating a hypothetical user query and then using an agent (often employing Depth-First Search) to search for a valid tool-use path.
This approach is inherently inefficient. Search is computationally expensive and frequently fails to find a valid path, leading to low "pass rates" and training sets contaminated with failed trajectories. ToolGrad addresses this by inverting the process into an "answer-first" framework.
The ToolGrad Framework
ToolGrad is an agentic framework inspired by TextGrad, which uses textual feedback as "gradients" to optimize prompts. Instead of starting with a query, ToolGrad starts with an empty workflow and iteratively builds a successful tool-use chain through a multi-step process:
- Iterative Chain Construction:
- API Proposer: Suggests a mini-batch of potential APIs from a large database.
- API Executor: Runs the proposed APIs to generate execution reports (success/failure, outputs).
- API Selector (The "Gradient"): An LLM evaluates these reports and chooses the best API to augment the current workflow. This discrete selection serves as the "textual gradient" for data generation.
- Workflow Updater: Formally adds the successful tool call to the chain.
- Inverse Prediction: Once a complex, successful tool-use chain is established, an LLM performs "inverse prediction" to synthesize a user query and a final response that perfectly matches that specific chain.
This method ensures that every data point in the resulting dataset is grounded in a verified, successful execution, eliminating the wasted resources spent on failed search branches common in traditional methods.
Experimental Results
Using this framework, the authors generated ToolGrad-5K, a dataset containing 5,000 triplets of (query, tool-use workflow, response). It features an average of 6.1 tool uses per sample, significantly higher than the 3.3 average of prior benchmarks like ToolBench.
Key findings include:
- 100% Pass Rate: ToolGrad achieves a perfect pass rate by construction, compared to 63.8% for DFS-based methods.
- Cost Efficiency: ToolGrad reduced LLM invocation costs by approximately 29% and tool execution costs by 12.5%.
- Model Performance: Small models (Gemma-3 1B, 4B, 12B) fine-tuned on ToolGrad-5K reached ~99% tool recall, outperforming proprietary state-of-the-art models like GPT-4o and Claude 3.7 Sonnet on the same benchmark.
- Generalization: Llama-3 models trained on ToolGrad-5K consistently outperformed those trained on the much larger ToolBench (197k samples) when evaluated on out-of-distribution (OOD) benchmarks, suggesting that trajectory complexity and cleanliness are more critical than raw dataset size.
Discussion and Future Work
While ToolGrad significantly improves tool-use data generation, some limitations remain. The current dataset focuses on direct tool-use chains and lacks explicit "reasoning" steps (e.g., Chain-of-Thought) between calls, which may be necessary for specific multi-step reasoning frameworks. Additionally, while tool chains are complex, the synthesized user queries may lack the linguistic variety of human interactions.
Future work includes incorporating memory systems to learn from execution failures within a session and using ToolGrad's high-quality trajectories for training tool-use agents via Reinforcement Learning (RL).
Summary updated