T ool F low: Boosting LLM Tool-Calling Through Natural and Coherent Dialogue Synthesis (2025)

Abstract: Supervised fine-tuning (SFT) is a common method to enhance the tool calling capabilities of Large Language Models (LLMs), with the training data often being synthesized. The current data synthesis process generally involves sampling a set of tools, formulating a requirement based on these tools, and generating the call statements. However, tools sampled randomly lack relevance, making them difficult to combine and thus reducing the diversity of the data. Additionally, current work overlooks the coherence between turns of dialogues, leading to a gap between the synthesized data and real-world scenarios. To address these issues, we propose a Graph-based Sampling strategy to sample more relevant tool combinations, and a Planned-generation strategy to create plans that guide the synthesis of coherent dialogues. We integrate these two strategies and enable multiple agents to synthesize the dialogue data interactively, resulting in our tool-calling data synthesis pipeline ToolFlow. Data quality assessments demonstrate improvements in the naturalness and coherence of our synthesized dialogues. Finally, we apply SFT on LLaMA-3.1-8B using 8,000 synthetic dialogues generated with ToolFlow. Results show that the model achieves tool-calling performance comparable to or even surpassing GPT-4, while maintaining strong general capabilities.

## introduction enabling large language models (llms) to perform tool calling significantly enhances their capabilities and practical applications. this requires the models to possess strong understanding, reasoning, and instruction-following abilities. customized fine-tuning is a widely used method to improve the tool-calling capabilities of llms (abdelaziz et al., 2024; patil et al., 2023; schick et al., 2023; qin * work done during internship at huawei noah's ark lab. a typical tool-calling data synthesis process involves three steps: (1) selecting candidate tool(s), (2) generating requirements based on those tools, and (3) creating the call statements @xcite . however, the data synthesized through this method often lacks realism and naturalness. randomly sampled tools frequently fail to interconnect, making it difficult to combine them for complex tasks. consequently, the requirements for subsequent synthesis tend to be simplistic, which reduces the diversity and complexity of the data. furthermore, much of the existing research focuses solely on generating single-turn toolcalling instructions, neglecting the coherence between dialogue turns @xcite . in real-world interactions, llms typically engage with users through dialogues rather than single-round q&a sessions. this creates a gap between q&a-type training data and its practical application, ultimately diminishing the naturalness of the synthesized data. to address these two challenges, we propose toolflow, a tool-calling data synthesis pipeline that employs a graph-based sampling algorithm to improve the correlation among the selected tools and a planned-generation strategy to enhance the naturalness and coherence of the synthesized tool call dialogues. specifically, we consider tools with similar parameters or return values to be related. for instance, both "book_flight" and "get_weather" require parameters related to location. in practical scenarios, these two tools are indeed interconnected, as they often occur together in travel contexts. based on this assumption, we construct a tool graph that represents the similarity between parameters and return values of the tools. each node in the graph represents a tool, while the edges indicate the relevance between pairs of tools. when sampling tools, we randomly select a subgraph from this tool graph, ensuring that the sampled tools are more likely to interact effectively, thereby facilitating the generation of complex requirements. on the other hand, before synthesizing dialogues, we first have the llm create a plan based on the selected subset of tools. this plan outlines the requests that users need to make in each turn of the dialogue. while constructing the plan, the model focuses on establishing the dialogue framework without worrying about phrasing and details. this approach allows the model to concentrate on the logical relationships and interactions between requirements, resulting in more coherent demands. additionally, we enable the llm to incorporate non-tool-call requests into the plan. this not only enhances the diversity of the conversation content but also facilitates seamless transitions between topics, naturally leading to new requirments. we generate dialogues using three agents: user, assistant, and tool. based on the selected tool subset and the established plan, these agents interact to complete the dialogue. by iterating through the "sampling-planning-generation" process, we synthesized a total of 8,000 dialogues. to evaluate the effectiveness of our proposed method, we conduct a comprehensive ablation study on the graph-based sampling and planning strategy by generating dialogues of the same size selectively without these modules. we perform a thorough evaluation of the data quality, which demonstrates that toolflow can effectively enhance the naturalness, coherence, and diversity of the generated dialogues. finally, we apply supervised fine-tuning to llama-3.1-8b-instruct @xcite using the synthesized data and validate improvements in the model's toolcalling capabilities while preserving its general abilities, with toolflow. we summarize our contributions into the following three key points: ## related works integrating external tools with large language models (llms) significantly broadens their functional scope, allowing for more specialized, precise, and reliable solutions to complex problems @xcite . there are generally two main strategies for embedding tool-use capabilities into llms: prompt-based methods and tool-augmented sft. prompt-based methods enable llms to utilize tools by providing descriptions and examples of the tools in the prompt, without any incremental training @xcite @xcite . react @xcite is one of the notable methods within this category. it allows llms to switch between reasoning and executing actions to tackle challenging tasks. however, the effectiveness of these approaches can be limited by the inherent capabilities of the model. on the other hand, tool-augmented tuning is attracting increasing interest due to its direct enhancement of llm's tool usage capabilities @xcite @xcite . as the limited availability of tool calling datasets, @xcite adapted data from various other domains for application in tool calling studies. others @xcite @xcite ) mainly synthesized single-turn instructions that involve basic tool calling requirements. however, llms typically interact with users through dialogue rather than single-turn q&a. this mismatch means the data is unnatural, creating a gap with real-world scenarios. our toolflow focuses on enhancing the coherence and naturalness of dialogues in data synthesis, making it more aligned with actual applications. ## methodology to generate realistic and coherent dialogues, we propose a three-step data synthesis process: (1) selecting a tool subset using graph-based sampling; ## correlation analysis to further investigate the impact of the diversity and coherence of the dialogue data on model performance, we conducted additional correlation analysis. in the previous experiments, we synthesized a total of 8, 000 × 4 = 32, 000 dialogues by using toolflow and its ablation settings. we randomly sampled from these data 10 times, each time selecting 4,000 dialogues to form 10 new training sets. we calculated the diversity metrics d-3 and h, and the coherence metrics ss and enr for each dataset. then, we used this data to fine-tune the llama3.1-8b-instruct. we tested these ten fine-tuned models on the bfcl and mtbench. finally, we calculated the pearson correlation coefficient between the evaluation metrics of the training data and the model performance and reported it in the average results on the bfcl show that both diversity and coherence of the training data contribute a lot to enhancing the model's tool-calling capabilities. mtbench results show a strong positive correlation between data coherence and the model's conversational performance, consistent with our assumption. notably, while we use entropy and distinct-n scores to assess diversity, the inconsistent correlation between these metrics and model performance suggests they may reflect different dimensions of diversity. ## dataset overlap analysis to ensure the reliability of the evaluation, we conducted an overlap analysis between training and test datasets. this examination helps verify the independence of these test data and prevents potential data leakage issues. we employed both n-grambased and similarity-based methods to demonstrate that there is no significant data leakage in the toolflow dataset. we also included the wellknown xlam agent training set @xcite as a control group for comparison. n-gram-based method following the approach used in llama-2 @xcite , we considered a token contaminated if it appeared in any token n-gram longer than 10 tokens in both the evaluation sample and the training set. a tool was classified as leaked if more than 10% of the tokens in its json string were contaminated. ## conclusion in this work, we propose graph-based sampling and planned generation strategies to enhance the diversity and coherence of synthetic data. based on these two strategies, we introduce a pipeline called toolflow for synthesizing tool calling data and generate 8,000 training samples. using this dataset, we conduct sft on llama3.1-8b-instruct, resulting in improved tool calling capability of the model. subsequently, we conduct correlation analysis to demonstrate the influence of data diversity and coherence on model performance. this provides a reference for the composition of training data for the tool-enhanced agent.