On my laptop, adding a small draft model made tool calls, JSON, and code 1.4 to 1.7 times faster end to end. Those are the outputs agents produce most. It made replayed multi-turn agent steps with 4,000-token contexts 6% slower. The difference is the time an agent step spends processing its whole context (prefill) before it writes a short answer (decode). Speculative decoding only speeds up decode, which is also all that tokens-per-second benchmarks measure. Those agent steps spent 77% of their time in prefill.
If you run a local model behind an agent framework, loading a draft model is one flag on llama-server. I would have judged it by the acceptance rate the server prints, and for agent loops that would have been the wrong number to look at. Once I turned on the prompt cache, the same draft model made agent steps 10% faster instead of slower, though the cache itself did most of the work.
Contents
- How a draft model saves time
- Setup
- Results by workload
- Why the agent steps got slower
- Turning on the prompt cache
- Four missing tokens in Qwen3’s template
- N-gram lookup
- What acceptance rate do you need?
- Draft length and temperature
- When lossless still changes the output
- Llama and MLX
- Limitations
- Run the check on your own agent
- Conclusion: what I’d change on an agent server
- References
How a draft model saves time
A large target model produces one token per forward pass. On a laptop or a single GPU, each pass is limited by how fast the weights can be read from memory, and the arithmetic units sit partly idle. In speculative decoding [1, 2], a small draft model guesses the next k tokens, and the target checks all k in one pass, keeps the longest prefix it agrees with and adds one token of its own. With greedy decoding the output is, in principle, exactly what the target would have written alone. That is the “lossless” claim, and in my runs it didn’t always hold. How much you gain depends on how many guesses the target accepts (the acceptance rate) and on what a verification pass costs compared with a normal one.
One greedy step looks like this (simplified; the real loop lives inside llama.cpp):
Setup
Everything below comes from 29,854 timed requests across two model families and two inference engines, plus 832 from the prompt-cache follow-up. I used llama-server from llama.cpp [5] (build 11960), because most local agents talk to a model over HTTP, one request per step. The main pair (A) is Qwen3-8B at 4-bit (Q4_K_M) as the target and Qwen3-0.6B (Q8_0) as the draft [4], with thinking turned off. To see whether the results hold outside the Qwen family, I repeated the core sweep with Llama-3.1-8B-Instruct and Llama-3.2-1B-Instruct (pair C). I also ran pair A through MLX, Apple’s array framework, which has its own draft-model support.
|
ID |
Workload |
Source |
Prompts |
Max new tokens |
|---|---|---|---|---|
|
W1 |
Open chat |
MT-Bench first turns [6] |
80 |
512 |
|
W2 |
Code |
HumanEval prompts [7] |
164 |
512 |
|
W3 |
Single tool call |
BFCL simple and multiple [8] |
200 |
256 |
|
W4 |
JSON extraction |
generated text plus a JSON schema |
150 |
256 |
|
W5 |
Long agent context |
208 steps from 22 replayed BFCL multi-turn episodes |
208 |
256 |
W5 took the most work. I ran BFCL multi-turn tasks with the target model, executed its tool calls in the BFCL environments, and saved the context at every step, so each W5 request is one saved state: system prompt, tool schemas, the conversation so far and the tool results. The first version of the builder crashed after 8 tasks. Qwen had emitted a tool call whose JSON was cut off mid-string, llama-server refused it with an HTTP 500, and my script had no plan for that. Now such an episode ends as “aborted”. The mean W5 prompt is 4,085 tokens; the mean answer is 48.
Every prompt is rendered with the model’s own chat template and tokenized before the timer starts, so the clock covers only what an agent waits for. The timed part is one streamed request:
BASE is the target alone. DRAFT-k adds the draft model with up to k drafted tokens per step. Each configuration ran every prompt three times (twice for the Llama and MLX runs), on a fresh server, in shuffled order. I judge everything by wall-clock latency per request, from sending it to receiving the last token. Speedup is mean BASE latency divided by mean speculative latency on the same prompts, with a 95% bootstrap confidence interval. Each prompt’s latency is the median of its repeats, and the bootstrap resamples prompts in pairs so that a prompt always meets its own baseline:
All of it ran on an Apple M5 Pro laptop with 48 GB of unified memory, over about three nights. I stopped it during the day because the laptop got hot, and I dropped a 32B target I had planned, because it would have taken too long. My smoke-test batches of 5 prompts also had the same file names as the full sweep, so the sweep counted them as finished and skipped them. I found it before any analysis, and the done-check now also compares the number of prompts in a batch.
Results by workload
With k = 4, code generation ran 1.72 times faster than the target alone, JSON extraction 1.65 times and single tool calls 1.41 times. Chat gained 1.19 times. The long agent contexts of W5 ran at 0.94 times the speed of BASE (95% CI 0.93 to 0.95): each step took about 6% longer.
Acceptance rates line up with the first four: 95% of JSON tokens, 92% of tool-call tokens and 88% of code tokens came from the draft’s guesses, against 49% for chat. I expected braces and key names copied from a schema to carry the acceptance rate and argument values to drag it down. They didn’t: MLX marks each output token as drafted or not, and in tool calls the draft supplied 79% of the structure tokens and 78% of the argument-value tokens.
Why the agent steps got slower
W5’s 66% acceptance was well above chat’s. But the draft has to read the prompt too, so with speculation the prefill gets slightly longer while only the decode gets shorter, and the end-to-end gain is capped by the share of time a request spends decoding. Amdahl’s law [3] gives the number:
llama-server returns all four inputs in its timings object (prompt_ms and predicted_ms), so checking this takes a few lines. With the measured means for a tool call (W3) and an agent step (W5):
In W5 the draft’s own prefill adds 0.39 seconds per step and the faster decode saves only 0.13.

Chat is 2% prefill and keeps nearly all of its 1.19 times, while tool calls at 30% prefill fall from 1.75 times on decode to 1.41 overall. W5 is worse on both counts (Figure 2): a decode gain of only 1.16 times, applied to less than a quarter of the step. Across all 29 speculative configurations of pair A at temperature 0 on llama.cpp, n-gram modes included, the Amdahl prediction was never more than 0.011 off the measured speedup.
The weak decode gain is because W5 replies mix tool calls with prose for the user, which the draft predicts less well than W3’s bare tool calls. Even with W3’s decode gain, W5’s time split would only reach about 1.01 times.
Summed over the steps of each of the 22 BFCL tasks, DRAFT-4 took 0.94 times as long as BASE. Only 2 of the 22 tasks finished faster, and on average speculation added 2.6 seconds to a 41-second task.
Turning on the prompt cache
I set up this follow-up after going back over the W5 numbers. Every request in the main sweeps set cache_prompt: false, so every W5 step re-read its entire context, which is not how an agent runs. An agent sends step 5 right after step 4, and llama-server can keep the key-value (KV) cache from the previous request and process only the tokens after the longest shared prefix. If the cache removes most of the prefill, the formula above says speculation should start to pay.
So I replayed the same 208 W5 steps in agent order, episode by episode, with cache_prompt: true on one server per run, for BASE and DRAFT-4, twice each. The whole thing took about 18 minutes. llama-server reports how many prompt tokens it actually processed (prompt_n) and how many it reused (cache_n), which gives the hit rate directly:
The cache served 92.8% of all prompt tokens. After the first step of an episode, a step processed 89 tokens on average out of 4,136 (97.8% reused). First steps reused 44%, whatever system prompt and tool schema they happened to share with the end of the previous episode.
I also wanted to know whether the draft model kept its own cache or re-read everything. llama-server’s speculative prefill time includes the draft’s prefill, and it came out at 1.12 times BASE’s without the cache and 1.11 times with it. Had the draft re-read its full 4,000-token context while the target used the cache, that ratio would have jumped above two, since the draft’s full prefill (about 0.39 seconds per step uncached) is bigger than BASE’s whole cached prefill (0.30 seconds). The ratio barely moved, so the draft reuses its context as well.

|
W5, pair A |
Without cache |
With cache |
|---|---|---|
|
BASE mean step time |
4.32 s |
1.29 s |
|
BASE prefill share |
77% |
23% |
|
DRAFT-4 decode speedup |
1.16x |
1.19x |
|
DRAFT-4 speedup per step |
0.94x (0.93 to 0.95) |
1.10x (1.06 to 1.14) |
|
DRAFT-4 speedup per episode |
0.94x (0.93 to 0.95) |
1.10x (1.05 to 1.14) |
|
Episodes faster with DRAFT-4 |
2 of 22 |
18 of 22 |
|
Amdahl prediction |
0.94x |
1.11x |
Per episode, the draft saved 1.1 seconds out of 12. The cache alone made BASE steps 3.36 times faster than uncached BASE, and cache plus speculation reached 3.70 times.
Four missing tokens in Qwen3’s template
In all 186 step-to-step transitions of a run, reuse stopped exactly 4 tokens before the end of the previous prompt. I compared the token IDs directly and found the cause in Qwen3’s chat template. With thinking off, it ends the generation prompt with an empty block, then drops that block when it renders the same assistant turn as history:
Because the prefix match breaks there, the model re-processes its own previous answer on every step. With 48-token answers that is cheap.
N-gram lookup
llama.cpp can also speculate without a draft model: it looks up n-grams in the text it has already seen and proposes how they continued. It needs no second model, just a flag:
I’d expected this to pick up agents echoing tool output, but the best mode, ngram-mod, gave 1.00 times on tool calls, 1.00 on JSON extraction and 1.03 on W5 (uncached), and combined with the draft model it matched the draft model alone on tool calls and JSON (1.41 and 1.65 times). My guess is that the replies are too short to repeat much.
What acceptance rate do you need?

A linear fit of per-request speedup against acceptance, over all pair A speculative requests, crosses 1.0 at an acceptance rate of 0.43 (95% CI 0.42 to 0.44):
For the Llama pair, whose 1B draft is relatively more expensive, the line crosses at 0.60. Prefill share moves a request’s speedup as much as acceptance does, so the fit is loose (R² of 0.42 for pair A). Below about 0.45 acceptance (0.6 with a 1B draft) I wouldn’t expect a gain even on decode-heavy requests.
Draft length and temperature

On JSON extraction, k = 8 (1.68 times) edged out k = 4 (1.65 times), and on tool calls they tied (1.42 and 1.41 times). On chat, k = 8 already lost (0.85 times) and k = 16 more than halved the speed (0.45 times), because every rejected guess still costs verification work. By geometric mean across workloads k = 4 and k = 8 came out best, and for mixed traffic I’d pick k = 4.
Most published speedups are measured at temperature 0, so I reran DRAFT-4 at 0.7. The speedups barely moved: 1.42 times on tool calls, 1.66 on JSON, 1.72 on code and 1.15 on chat. BASE at 0.7 still matched the greedy output on 196 of the 200 tool-call prompts (5 of the 80 for chat).
When lossless still changes the output
Greedy speculative decoding should return the same tokens as the target alone. In 1,349 of the 20,390 outputs I compared, it didn’t. Most were chat: about half of pair A’s W1 outputs differed from BASE at every k, against 9% of its W2 outputs and 8% of its W5 outputs, and none of its tool calls or JSON outputs on llama.cpp. If you need reproducible outputs, for tests or for caching by output hash, don’t compare speculative outputs against a non-speculative baseline.
I probed 300 of the chat cases. At the first token where the two outputs diverge, I re-ran the target over the shared prefix in one batch and read its probabilities:
In 286 cases the two candidates were a near-tie (log-probability gap below 0.2, median 0.03), and the batched pass picked the token from the speculative output. Verification evaluates several tokens in one batch while a normal decode step evaluates one, so the two paths use different kernels and summation orders. With a near-tie, that rounding difference is enough to flip the token, and everything after it changes.
The other 14 cases come from just two divergence points, repeated across configurations and repeats. One is close to a tie (a gap of 0.27 between ” two” and ” first”), but the other isn’t: in a Markdown table separator, the batched pass prefers a seven-dash token with a probability of about 0.83, while the one-token BASE path wrote the eight-dash token. The batched pass agrees with the speculative output there too, so the draft did not sneak in a token the target rejects. A gap that large is more than I’d expect from summation order, and I haven’t found the cause.
Llama and MLX
DRAFT-4 speedup over BASE at temperature 0:
|
Workload |
Qwen, llama.cpp |
Llama, llama.cpp |
Qwen, MLX |
|---|---|---|---|
|
W2 code |
1.72 |
1.42 |
1.96 |
|
W4 JSON |
1.65 |
1.40 |
1.87 |
|
W3 tool call |
1.41 |
1.17 |
1.56 |
|
W1 chat |
1.19 |
1.20 |
1.38 |
|
W5 agent step |
0.94 |
0.90 |
not run |
The Llama pair showed the same split with smaller gains. Tool calls gained slightly less than chat here, because Llama’s acceptance on tool calls (83%) was lower than Qwen’s (92%) and its chat acceptance (67%) higher. Its draft is also larger relative to the target (1B against 8B), so each guess costs more.
MLX gave pair A bigger gains on W1 to W4. It uses its own 4-bit weights for both models, so this compares two sets of model files as well as two engines. Every speedup went up by 0.16 to 0.24 times and the order of the workloads stayed the same.
MLX is also where the drafted-token split I quoted earlier comes from, because mlx_lm flags every generated token that came from the draft:
Limitations
All the numbers come from one M5 Pro laptop. My first plan framed the whole piece around Apple Silicon, and I dropped that, since the exact speedups are specific to this laptop while the prefill arithmetic is not. Apple Silicon has unified memory and its own balance of bandwidth and compute, and on a discrete GPU both the prefill share and the cost of a verification pass will be different.
The server may also undersell speculation. Users have reported that llama-server drafts fewer tokens and runs 10 to 15% slower than llama.cpp’s speculative example [9]. A 2026 report found that multi-token-prediction speculation lost throughput at every configuration on Apple’s Metal backend [10]. That is a different method, and I haven’t tested it.
Run the check on your own agent
A draft model in llama-server takes a few extra flags. Flag names have changed across builds, so check llama-server --help | grep -i draft first.
The draft has to share the target’s tokenizer, which in practice means the same model family. -np 1 keeps a single slot, so requests run one at a time, as they would for a single agent, and every step lands in the same cache slot.
Each /completion response includes a timings object, and its fields are enough to decide:
Send the prompts your agent actually sends, in the order it sends them, once to each server, and compare mean latency. Compute the prefill share, P / (P + D), from the BASE run. Above about one half I wouldn’t bother with a draft model unless the decode speedup is large; at a tenth or less, most of the decode speedup survives end to end. Also look at tokens_reused on step 2 of an agent loop. Near zero means the prompt cache isn’t working.
Conclusion: what I’d change on an agent server
If the server mostly answers single tool calls or JSON requests, I’d add a small draft model and not think much more about it. For an agent loop with long contexts I’d turn on the prompt cache first, which gave 3.4 times by itself, and only then add the draft. Without the cache I’d leave the draft off for agent loops altogether.
The code, prompt sets, raw results and figures are here: https://github.com/ankur287/speculative-decoding-agents
References
[1] Y. Leviathan, M. Kalman and Y. Matias, Fast Inference from Transformers via Speculative Decoding (2023), ICML 2023
[2] C. Chen, S. Borgeaud, G. Irving, J.-B. Lespiau, L. Sifre and J. Jumper, Accelerating Large Language Model Decoding with Speculative Sampling (2023), arXiv:2302.01318
[3] G. M. Amdahl, Validity of the Single Processor Approach to Achieving Large Scale Computing Capabilities (1967), AFIPS Spring Joint Computer Conference
[4] Qwen Team, Qwen3 Technical Report (2025), arXiv:2505.09388
[5] G. Gerganov and contributors, llama.cpp (2023), GitHub repository ggml-org/llama.cpp
[6] L. Zheng, W.-L. Chiang, Y. Sheng et al., Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena (2023), NeurIPS 2023 Datasets and Benchmarks Track
[7] M. Chen, J. Tworek, H. Jun et al., Evaluating Large Language Models Trained on Code (2021), arXiv:2107.03374
[8] S. G. Patil, H. Mao, F. Yan et al., The Berkeley Function Calling Leaderboard (BFCL): From Tool Use to Agentic Evaluation of Large Language Models (2025), ICML 2025
[9] llama.cpp issue #12968, Misc. bug: llama-server speculative decoding not as performant as llama-speculative-simple (2025), GitHub ggml-org/llama.cpp, https://github.com/ggml-org/llama.cpp/issues/12968
[10] llama.cpp issue #23752, MTP speculative decoding degrades throughput on Metal (Apple Silicon): net loss at every configuration (2026), GitHub ggml-org/llama.cpp, https://github.com/ggml-org/llama.cpp/issues/23752
