Editorial illustration for Llama-Server Cache Hits 92.8% of Prompt Tokens in Tool Call Test
Llama Cache Hits 92.8% in Faster Tool Call Test
A small draft model helped and hurt, depending on what the task actually spent its time doing. Running Qwen3 and Llama models through llama.cpp, a laptop setup with speculative decoding turned on produced code, JSON, and tool calls 1.4 to 1.7 times faster, the exact outputs an agent relies on most. But feed that same setup a replayed multi-turn agent loop with 4,000-token contexts, and it got 6% slower instead.
The gap comes down to where the time actually goes. Speculative decoding speeds up decode, the part where a model writes its answer, and that's also the only thing tokens-per-second benchmarks tend to measure. Prefill, the step where the model reads through its entire context before writing anything, doesn't get touched by a draft model at all.
In this testing, agent steps spent 77% of their time in prefill. That mismatch is the whole story: a technique that looks great on a decode-only benchmark can quietly cost you time once prefill dominates the clock. Turning on llama-server's prompt cache changed the math entirely, flipping that same draft model from a 6% slowdown into a 10% speedup on agent steps.
Speculative Decoding Makes Tool Calls Faster. Agents Need a Cache. Benchmarks with Qwen3 and Llama on llama.cpp show a draft model sped up code, JSON, and tool calls up to 1.7x, while uncached agent loops ran 6% slower.
Why this matters
The 92.8% cache hit rate is the real headline here, not the 1.7x speedup from speculative decoding. For anyone building agents on llama.cpp, this is a reminder that raw inference tricks and system-level caching solve different problems, and conflating them costs you. A draft model helps when the bottleneck is generation, tool calls, JSON, code.
But agent loops spend most of their time on prompt processing, re-feeding 4,000-token contexts turn after turn, and that's where cache_n and prompt_n matter more than any decoding gimmick. The 6% slowdown on uncached multi-turn steps is the detail worth sitting with: it shows speculative decoding can actively hurt you if your workload is dominated by reused context rather than fresh output. For teams shipping agent infrastructure, the takeaway is to measure where your tokens actually go before reaching for a draft model.
A 97.8% reuse rate after the first step means most of the "speedup" work was already done by caching, not prediction. Benchmark your own loop shape before borrowing someone else's optimization.
Common Questions Answered
What is the 92.8% cache hit rate mentioned in the Llama-Server test, and why is it significant?
The 92.8% cache hit rate represents how effectively the system reuses cached prompt tokens during agent loops, which is the actual performance bottleneck for multi-turn conversations. This metric is more important than the 1.7x speedup from speculative decoding because it reveals that agent loops spend most of their time on prompt processing rather than token generation, making cache efficiency the real key to optimization.
Why does speculative decoding speed up tool calls but slow down multi-turn agent loops in the llama.cpp benchmarks?
Speculative decoding with a draft model accelerates code, JSON, and tool call generation by up to 1.7x because these tasks are generation-bottlenecked. However, multi-turn agent loops with 4,000-token contexts run 6% slower because they spend most of their time on prompt processing and context re-feeding rather than generation, where speculative decoding cannot help and may introduce overhead.
What is the performance difference between Qwen3 and Llama models when using speculative decoding on llama.cpp?
Both Qwen3 and Llama models showed speedups of 1.4 to 1.7 times faster for code, JSON, and tool calls when speculative decoding was enabled on a laptop setup with llama.cpp. The exact speedup depends on the specific task and whether the bottleneck is generation or prompt processing.
How does the bottleneck differ between tool call generation and agent loop processing in the test results?
Tool call generation is bottlenecked by token generation speed, which is why speculative decoding provides significant speedups of up to 1.7x. In contrast, agent loops with 4,000-token contexts are bottlenecked by prompt processing and context re-feeding across turns, making system-level caching more critical than inference optimization techniques.
What does the article suggest is the key takeaway for developers building agents on llama.cpp?
The article emphasizes that raw inference tricks like speculative decoding and system-level caching solve different problems, and conflating them leads to suboptimal performance. For agent builders, implementing effective prompt caching is more important than focusing solely on generation speedups, since agent loops spend most of their time re-processing cached contexts rather than generating new tokens.
Further Reading
- Speculative Decoding Makes Tool Calls Faster. Agents Need a Cache. - Towards Data Science
- MTP speculative decoding in llama.cpp, faster but not identical - Maurizio Fonte
- Qwen3 & Qwen3.8 on llama.cpp — faster local inference with MTP + n-gram speculative decoding, prompt-cache tuning and thinking budgets - GitHub
- Speculative decoding: How it works, when it helps & where it fits in your inference stack - Redis
- Speculative Decoding for Faster LLM Inference - GMI Cloud