ToolGrad: Efficient Tool-use Dataset Generation with Textual "Gradients"

Zhongyi Zhou, Kohei Uehara, Haoyu Zhang, Jingtao Zhou, Lin Gu, Ruofei Du, Zheng Xu, Tatsuya Harada

TL;DR

ToolGrad introduces an "answer-first" framework for generating tool-use datasets, inverting the traditional approach of searching for solutions to pre-generated queries. By iteratively building successful tool-use chains guided by textual "gradients" (LLM feedback) and then synthesizing the corresponding user prompts, ToolGrad achieves a 100% annotation pass rate with lower costs and higher complexity than existing methods.

What Problem Does This Paper Address?

To perform real-world tasks, Large Language Models (LLMs) must master "tool-use"—the ability to call external APIs for information or actions. However, training models for this requires high-quality datasets pairing user queries with correct tool-use sequences.

Current synthetic data generation relies on a "query-first" paradigm:

  1. Generate a hypothetical user query.
  2. Use an agent (often employing Depth-First Search or DFS) to search for a valid tool-use path to solve it.

This approach is inherently inefficient. Search is expensive, and it frequently fails to find a valid path, leading to low "pass rates" and "contaminated" training sets filled with failed trajectories. The authors identify a need for a scalable, high-success-rate method to generate complex tool-use data.

Methods

The authors introduce ToolGrad, an agentic framework inspired by TextGrad (which uses textual feedback as "gradients" to optimize prompts). ToolGrad flips the script to an "answer-first" approach:

  1. Iterative Chain Construction: Instead of starting with a query, ToolGrad starts with an empty workflow and iteratively builds a successful tool-use chain.
  2. API Proposer: Suggests a mini-batch of potential APIs from a large database.
  3. API Executor: Runs the proposed APIs to generate execution reports (success/failure, outputs).
  4. API Selector (The "Gradient"): An LLM acts as the selector, evaluating reports and choosing the best API to augment the current workflow. This discrete selection serves as the "textual gradient" for data generation.
  5. Workflow Updater: Formally adds the successful tool call to the chain.
  6. 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.

Datasets

  • ToolGrad-5K: A new 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 prior benchmarks.
  • ToolBench: Used as the source for the API library (filtered to ~8.7k high-quality APIs) and as a baseline for comparison.
  • ToolBench-I3: Used as an out-of-distribution (OOD) benchmark to test the generalization of models trained on ToolGrad-5K.

Key Insights and Ideas

  • The Inversion Advantage: It is computationally and logically easier for an LLM to look at a successful solution and ask "What was the question?" than it is to solve a complex problem from scratch via trial-and-error search.
  • Efficiency through Success: By only building on successful API calls, ToolGrad eliminates the wasted resources spent on failed search branches common in DFS-based methods.
  • Complexity by Design: The iterative nature of the framework naturally encourages the generation of longer, more sophisticated tool-use chains compared to query-first methods, which often struggle to find solutions for complex prompts.
  • Quality over Quantity: Models trained on the 5k samples of ToolGrad-5K outperformed models trained on the much larger ToolBench (197k samples), suggesting that the "cleanliness" and complexity of the trajectories are more important than raw dataset size.

Key Results

  • 100% Pass Rate: Unlike the baseline DFS method (63.8% pass rate), ToolGrad achieves a perfect pass rate by construction.
  • Superior Complexity: ToolGrad-5K samples average 6.1 ground-truth tool uses, nearly double the 3.3 of the baseline.
  • Cost Reduction: ToolGrad reduced LLM invocation costs by ~29% and tool execution costs by ~12.5% compared to the baseline.
  • Model Performance: Small models (Gemma-3 1B, 4B, 12B) fine-tuned on ToolGrad-5K reached ~99% tool recall, outperforming proprietary SOTA models like GPT-4o and Claude 3.7 Sonnet (which scored between 82-85%) on the same benchmark.
  • OOD Generalization: Llama-3 models trained on ToolGrad-5K consistently outperformed those trained on ToolBench when evaluated on the ToolBench-I3 OOD benchmark, despite the training set being 40x smaller.

Limitations and Future Work

  • Reasoning Gap: The current dataset focuses on direct tool-use chains and does not include explicit "reasoning" steps (like Chain-of-Thought) between calls, which may limit performance in specific multi-step reasoning frameworks like ReAct.
  • Linguistic Diversity: While the tool chains are complex, the LLM-generated user queries might lack the linguistic variety found in real-world human interactions.
  • Memory Systems: The "API Executor" currently operates in isolation; the authors suggest that incorporating a memory system to learn from previous execution failures within a session could further improve efficiency.
  • Reinforcement Learning: The authors propose that the high-quality trajectories generated by ToolGrad could be highly effective for training tool-use agents via Reinforcement Learning (RL).

Summary updated

Abstract

Prior work synthesizes tool-use LLM datasets by first generating a user query, followed by complex tool-use annotations like depth-first search (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-500, a dataset generated with more complex tool use, lower cost, and almost 100% pass rate. Experiments show that ToolGrad models outperform those trained on expensive baseline datasets and proprietary LLMs. The ToolGrad source code, dataset, and models are available at https://github.com/zhongyi-zhou/toolgrad.
BibTeX
@inproceedings{zhou2026toolgrad,
  author = {Zhongyi Zhou and Kohei Uehara and Haoyu Zhang and Jingtao Zhou and Lin Gu and Ruofei Du and Zheng Xu and Tatsuya Harada},
  title = {{ToolGrad: Efficient Tool-use Dataset Generation with Textual "Gradients"}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.findings-acl.950},
}

Loading related content...

Figure