Abstract
ToolFlow is a novel data synthesis pipeline designed to enhance Large Language Model (LLM) tool-calling capabilities through multi-turn dialogue synthesis. By leveraging graph-based tool sampling and a "plan-then-generate" strategy, ToolFlow produces high-quality synthetic data that bridges the "naturalness gap" in existing training sets. Experiments show that a LLaMA-3.1-8B model trained on ToolFlow data achieves performance comparable to GPT-4 in complex tool-calling tasks while maintaining general conversational proficiency.
Introduction
While Large Language Models (LLMs) are increasingly deployed to interact with external APIs, training them effectively requires massive amounts of high-quality tool-calling data. Current synthetic data generation methods often suffer from two major flaws: irrelevant tooling and a lack of coherence. Tools are frequently sampled randomly, leading to unrealistic prompts (e.g., using a weather app and a stock tracker in the same turn). Furthermore, most synthetic data focuses on single-turn interactions, failing to capture the complexity of real-world multi-turn dialogues where tool outputs serve as inputs for subsequent steps or are interspersed with general "chitchat." This creates a "naturalness gap" between training data and actual usage.
Methods
The ToolFlow pipeline addresses these issues through a three-stage synthesis process:
- Graph-based Tool Sampling: Instead of random selection, ToolFlow utilizes a "Tool Graph" where nodes represent APIs and edges represent relationships based on Parameter-Parameter (P-P) or Parameter-Return (P-R) similarity. By performing a random walk on this graph, the system selects clusters of tools that are logically related (e.g., flight booking and weather services).
- Planned-Generation Strategy: To ensure coherence, the LLM first generates a high-level "Dialogue Plan." This plan outlines the logical flow of the conversation, including transitions and non-technical "chitchat" turns, before the actual dialogue is written.
- Multi-Agent Synthesis: Three specialized agents—User, Assistant, and Tool—interact to execute the dialogue plan. The User initiates requests, the Assistant manages tool calls, and the Tool agent simulates API responses.
Key Results and Evaluation
The researchers trained a LLaMA-3.1-8B model using 8,000 synthetic dialogues generated by ToolFlow. The model was evaluated across several benchmarks, including BFCL-v2, API-Bank, and ToolAlpaca.
- Competitive Performance: On the BFCL-v2 leaderboard, the ToolFlow-tuned model achieved an overall score of 82.57%, rivaling GPT-4-turbo (87.65%) and significantly outperforming the base LLaMA-3.1-8B (78.14%).
- State-of-the-Art Dialogue Accuracy: On the API-Bank dataset, ToolFlow achieved a state-of-the-art average accuracy of 62.10%, surpassing both GPT-4-turbo and GPT-4o.
- Ablation Study: Evaluation results demonstrate that both graph-based sampling and planning are critical for high-quality synthesis. As shown in the evaluation metrics, the combination of both components leads to superior naturalness (NAT), coherence (COH), and accuracy (ACC).
Key Insights
- API Interconnectivity: Treating APIs as a graph based on shared data types allows synthetic data to mimic complex, real-world workflows where information flows between services.
- Planning for Naturalness: Separating logic from phrasing through a dialogue plan prevents "robotic" data and allows for the inclusion of realistic conversational elements like chitchat.
- Data Quality Over Quantity: The results prove that a relatively small but high-quality dataset (8,000 dialogues) can enable an 8B parameter model to compete with much larger closed-source models.
Limitations and Future Work
Despite its success, ToolFlow has limitations. The diversity of synthetic data is currently capped by the available seed APIs (approx. 16,000 from ToolBench). Future work could explore "hallucinating" new tools to enrich the seed set. Additionally, while the pipeline uses GPT-4 as a teacher model, further research is needed to determine if models can improve by training on self-synthesized data (weak-to-strong distillation). Finally, the tool graph might be further refined to capture deeper functional relationships beyond explicit parameter naming.
Summary updated