Optimizing Agentic Language Model Inference via Speculative Tool Calls
Daniel Nichols, Prajwal Singhania, Charles Jekel, Abhinav Bhatele, Harshitha Menon
TL;DR
The paper tackles the latency bottlenecks of tool-using language-model agents by introducing two speculative tool-calling strategies: a client-side approach that overlaps tool execution with generation without engine changes, and an engine-side approach that preserves prompts in the inference server via a tool cache. It provides analytical models of expected speedups, demonstrates throughput and time-savings gains across BFCL-based workloads, and proposes a cache-based API to enable practical adoption. Key findings show up to double-digit percent reductions in end-to-end latency and hundreds of tokens per second in throughput, with engine-side gains offering additional improvements under favorable tool latencies. Together, these methods offer a scalable path to making tool-rich agentic LMs more efficient in real-world, multi-tenant environments.
Abstract
Language models (LMs) are becoming increasingly dependent on external tools. LM-based agentic frameworks frequently interact with their environment via such tools to search files, run code, call APIs, etc. Further, modern reasoning-based LMs use tools such as web search and Python code execution to enhance their reasoning capabilities. While tools greatly improve the capabilities of LMs, they also introduce performance bottlenecks during the inference process. In this paper, we introduce novel systems optimizations to address such performance bottlenecks by speculating tool calls and forcing sequences to remain resident in the inference engine to minimize overheads. Our optimizations lead to throughput improvements of several hundred tokens per second when hosting inference for LM agents. We provide a theoretical analysis of our algorithms to provide insights into speculation configurations that will yield the best performance. Further, we recommend a new "tool cache" API endpoint to enable LM providers to easily adopt these optimizations.
