Table of Contents
Fetching ...

ToolWeaver: Weaving Collaborative Semantics for Scalable Tool Use in Large Language Models

Bowen Fang, Wen Ye, Yunyue Su, Jinghao Zhang, Qiang Liu, Yesheng Liu, Xin Sun, Shu Wu, Jiabing Yang, Baole Wei, Liang Wang

TL;DR

ToolWeaver tackles the scalability and semantic bottlenecks of one-token-per-tool approaches by representing each tool as a compositional, hierarchical sequence of codes learned through collaborative-aware tokenization. It combines a two-stage generative alignment with residual vector quantization (RQ-VAE) and a Sinkhorn-based uniform mapping to embed intrinsic tool semantics with extrinsic co-usage patterns, enabling logarithmic vocabulary growth and dense collaborative signals. The approach achieves state-of-the-art results on the ToolBench benchmark (~47k tools) in both retrieval and end-to-end tool-use tasks, while preserving the LLM’s general language capabilities. This yields more scalable, generalizable, and semantically rich tool-augmented agents suitable for complex, multi-tool workflows in real-world applications.

Abstract

Prevalent retrieval-based tool-use pipelines struggle with a dual semantic challenge: their retrievers often employ encoders that fail to capture complex semantics, while the Large Language Model (LLM) itself lacks intrinsic tool knowledge from its natural language pretraining. Generative methods offer a powerful alternative by unifying selection and execution, tasking the LLM to directly learn and generate tool identifiers. However, the common practice of mapping each tool to a unique new token introduces substantial limitations: it creates a scalability and generalization crisis, as the vocabulary size explodes and each tool is assigned a semantically isolated token. This approach also creates a semantic bottleneck that hinders the learning of collaborative tool relationships, as the model must infer them from sparse co-occurrences of monolithic tool IDs within a vast library. To address these limitations, we propose ToolWeaver, a novel generative tool learning framework that encodes tools into hierarchical sequences. This approach makes vocabulary expansion logarithmic to the number of tools. Crucially, it enables the model to learn collaborative patterns from the dense co-occurrence of shared codes, rather than the sparse co-occurrence of monolithic tool IDs. We generate these structured codes through a novel tokenization process designed to weave together a tool's intrinsic semantics with its extrinsic co-usage patterns. These structured codes are then integrated into the LLM through a generative alignment stage, where the model is fine-tuned to produce the hierarchical code sequences. Evaluation results with nearly 47,000 tools show that ToolWeaver significantly outperforms state-of-the-art methods, establishing a more scalable, generalizable, and semantically-aware foundation for advanced tool-augmented agents.

ToolWeaver: Weaving Collaborative Semantics for Scalable Tool Use in Large Language Models

TL;DR

ToolWeaver tackles the scalability and semantic bottlenecks of one-token-per-tool approaches by representing each tool as a compositional, hierarchical sequence of codes learned through collaborative-aware tokenization. It combines a two-stage generative alignment with residual vector quantization (RQ-VAE) and a Sinkhorn-based uniform mapping to embed intrinsic tool semantics with extrinsic co-usage patterns, enabling logarithmic vocabulary growth and dense collaborative signals. The approach achieves state-of-the-art results on the ToolBench benchmark (~47k tools) in both retrieval and end-to-end tool-use tasks, while preserving the LLM’s general language capabilities. This yields more scalable, generalizable, and semantically rich tool-augmented agents suitable for complex, multi-tool workflows in real-world applications.

Abstract

Prevalent retrieval-based tool-use pipelines struggle with a dual semantic challenge: their retrievers often employ encoders that fail to capture complex semantics, while the Large Language Model (LLM) itself lacks intrinsic tool knowledge from its natural language pretraining. Generative methods offer a powerful alternative by unifying selection and execution, tasking the LLM to directly learn and generate tool identifiers. However, the common practice of mapping each tool to a unique new token introduces substantial limitations: it creates a scalability and generalization crisis, as the vocabulary size explodes and each tool is assigned a semantically isolated token. This approach also creates a semantic bottleneck that hinders the learning of collaborative tool relationships, as the model must infer them from sparse co-occurrences of monolithic tool IDs within a vast library. To address these limitations, we propose ToolWeaver, a novel generative tool learning framework that encodes tools into hierarchical sequences. This approach makes vocabulary expansion logarithmic to the number of tools. Crucially, it enables the model to learn collaborative patterns from the dense co-occurrence of shared codes, rather than the sparse co-occurrence of monolithic tool IDs. We generate these structured codes through a novel tokenization process designed to weave together a tool's intrinsic semantics with its extrinsic co-usage patterns. These structured codes are then integrated into the LLM through a generative alignment stage, where the model is fine-tuned to produce the hierarchical code sequences. Evaluation results with nearly 47,000 tools show that ToolWeaver significantly outperforms state-of-the-art methods, establishing a more scalable, generalizable, and semantically-aware foundation for advanced tool-augmented agents.
Paper Structure (79 sections, 9 equations, 12 figures, 13 tables)

This paper contains 79 sections, 9 equations, 12 figures, 13 tables.

Figures (12)

  • Figure 1: An overview of the ToolWeaver framework. (a) We contrast the standard "one-token-per-tool" method, which creates a massive flat vocabulary, with our compositional approach that scales logarithmically. (b) Our model leverages collaborative signals between tools (e.g., Realtime Weather and Air Quality) for complex reasoning where "one-token-per-tool" representations fail. (c) The ToolWeaver architecture learns these structured representations through a collaborative-aware vector quantization process, which are then integrated into an LLM.
  • Figure 2: Analysis of the collaborative regularization weight $\lambda$. Performance, measured by average NDCG@k across all I1-I3 scenarios, consistently peaks at $\lambda=1$.
  • Figure 3: Cumulative ablation analysis of ToolWeaver's components on tool selection (NDCG@k). Performance is shown for the baseline (w/o Semantic Initialization), after adding semantic initialization (w/o Collaborative Guidance), and for the full model.
  • Figure 4: Comparison of tokenization strategies.
  • Figure 5: Hyperparameter sensitivity analysis. (a) Performance vs. Vocabulary Size: Evaluated with fixed code length $L=2$. Performance peaks at 2,048 tokens, confirming that a compact vocabulary fosters better collaborative learning than a sparse, large one. (b) Performance vs. Code Length: Evaluated with fixed codebook size $K=1024$. While deeper hierarchies ($L=4$) improve semantic resolution, excessively long sequences ($L=6$) degrade performance due to generation complexity.
  • ...and 7 more figures