ToolSpec: Accelerating Tool Calling via Schema-Aware and Retrieval-Augmented Speculative Decoding

Heming Xia, Yongqi Li, Cunxiao Du, Mingbo Song, Wenjie LiarXiv 2026

TL;DR

ToolSpec is a training-free, plug-and-play framework that accelerates LLM tool calling by up to 4.2x. By combining a finite-state machine for schema-enforced token drafting with a retrieval mechanism that reuses historical tool calls, it drastically cuts down generation latency while maintaining the exact output distribution of the target model.

What Problem Does This Paper Address?

As Large Language Models (LLMs) transition into autonomous agents, they increasingly rely on external tools (APIs, databases, calculators) to solve complex tasks. However, multi-turn tool interactions introduce massive latency.

Interestingly, the bottleneck isn't the execution time of the external tool itself—it's the time the LLM spends generating the tool call text (usually structured JSON). As shown in the paper's analysis, tool execution time remains flat, but generation latency explodes as models scale, accounting for up to 96% of end-to-end latency in 72B models.

Figure 2: Latency breakdown of the Qwen2.5-Instruct model series on ToolBench (Qin et al., 2024b). Tool execution latency remains essentially constant, whereas tool-calling generation latency increases with model scale, reaching up to 96% of the end-to-end latency.

Existing speculative decoding (SD) methods speed up inference by using a smaller "draft" model to guess tokens, which the larger target model verifies in parallel. However, these draft models require expensive extra training and often struggle with the rigid, out-of-distribution syntax required for tool calling.

Methods

ToolSpec bypasses the need for a draft model entirely by exploiting the highly predictable, structured nature of tool calls through two training-free innovations:

  1. Schema-Aware Drafting: Tool calls must strictly adhere to predefined JSON schemas. ToolSpec builds a Finite-State Machine (FSM) directly from the tool's documentation. When a tool call is triggered, the FSM deterministically fills in fixed structural tokens (like {"name":, , "parameters":) and restricts choices for tool and parameter names. This allows the system to generate highly accurate structural drafts for parallel verification.
  2. Retrieval-Augmented Speculation: While the FSM handles structure, parameter values (e.g., dates, usernames) are open-ended. ToolSpec maintains a datastore of successful historical tool calls. It embeds the user's query, retrieves the top-$k$ most similar past invocations, and matches the current output suffix to speculatively copy over long sequences of historical parameter values as drafts.
Figure 5: Illustration of tool-calling generation with TOOLSPEC. To accelerate structural tool calling, TOOLSPEC integrates two complementary drafting strategies: (a) schema-aware drafting, where a finite-state machine guides highly accurate drafting within the predefined tool schema; and (b) retrieval-augmented speculation, which reuses historical generation patterns as high-quality drafts to speed up recurrent tool calls.

These candidate drafts are packed together and verified simultaneously by the target LLM in a single forward pass using tree-based attention.

Datasets

The authors evaluated ToolSpec across four widely recognized tool-use benchmarks:

  • API-Bank: A multi-turn dialogue benchmark comprising 73 diverse APIs.
  • ToolAlpaca: A benchmark evaluating general-purpose tool use across simulated and real-world APIs.
  • BFCLv2 (Berkeley Function Calling Leaderboard): A comprehensive evaluation covering single/multi-step tool use and real-time execution.
  • ToolBench: A large-scale benchmark featuring multi-tool interactions over 16,000+ real-world APIs.

No new datasets were introduced in this paper.

Key Insights and Ideas

  • Structure is a Cheat Code: Traditional speculative decoding treats text generation as entirely probabilistic. ToolSpec realizes that for tool calling, a massive portion of the tokens are effectively predetermined by the API schema. Hardcoding these into an FSM yields a "draft model" with near-perfect accuracy for structural tokens.
  • History Repeats Itself: In agentic workflows, users frequently repeat intents or preference patterns. By treating past tool calls as a cache and using suffix-matching, ToolSpec can guess long, continuous blocks of text (the "long-tail" of accepted tokens), which drastically boosts the efficiency of speculative decoding.
  • Format Adherence is Essential: The method relies on the LLM's ability to follow JSON schemas perfectly. The authors found a strong positive correlation (~0.90 Pearson coefficient) between a model's format adherence and the speedup ToolSpec achieves. Fortunately, modern models like LLaMA-3.1 and Qwen2.5 score above 99% in format adherence, making them ideal targets.

Key Results

  • Substantial Speedups: ToolSpec consistently achieves 3.5x to 4.2x wall-clock speedups over standard autoregressive decoding across various model families (LLaMA-3.1, LLaMA-3.2, Qwen2.5, and ToolLLaMA).
  • Outperforming Baselines: It delivers up to a 71% relative improvement over the previous best training-free speculative decoding methods (like Token Recycling and Prompt Lookup Decoding).
  • Zero Quality Degradation: Because ToolSpec uses the standard speculative decoding verification framework, it mathematically preserves the original output distribution of the target LLM—meaning accuracy remains completely unchanged.
Figure 6: Speedup comparison between TOOLSPEC and prior plug-and-play methods on ToolBench.

Limitations and Future Work

  • Scale of Evaluation: Due to computational constraints, the authors could not include ultra-large-scale models like Qwen2.5-72B or LLaMA-3.1-70B in their primary benchmark tables, though preliminary tests on 32B models show that the speedup scales favorably with model size.
  • Dependence on Schema and Patterns: The system's performance is tightly coupled with the presence of recurring invocation patterns and strict schema adherence. Performance might degrade in highly chaotic, entirely novel user interactions or with weaker base models that fail to output valid JSON.
  • Memory Management: While the historical datastore footprint is currently small (~4.9 MB for ~600 entries), deploying ToolSpec at a massive scale will require bounded memory bank strategies or cache-eviction policies, which the authors leave for future investigation.

Summary updated

BibTeX
@misc{xia2026toolspec,
  author = {Heming Xia and Yongqi Li and Cunxiao Du and Mingbo Song and Wenjie Li},
  title = {{ToolSpec: Accelerating Tool Calling via Schema-Aware and Retrieval-Augmented Speculative Decoding}},
  year = {2026},
  eprint = {2604.13519},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2604.13519},
}
Figure