•
4 min read

A tool returned 1K tokens. Why did the next request contain 32K?

I put one actionable ticket in the middle of a long archive and asked Gemma to look it up. On a DGX Spark, the first tool call took 5.89 seconds. The simulated tool returned about a thousand tokens, including a queue ID. Gemma then had to submit the original ticket to that queue. This time the complete call took 1.66 seconds.

The second request was actually longer. After the chat template and tool definitions, the median follow-up contained 32,096 input tokens. Each trial reused 30,976 cached tokens. That left a median of 1,120 uncached positions, close to the length of the tool result itself. All three trials got both function names and both sets of arguments right. The times are medians from request submission to end of stream. Replay and scoring rules

What the agent sent twice

Each second request included the instructions, the archive, the assistant’s lookup call, and the tool response. On the first turn, Gemma found the ticket ID in the archive. On the second, that ID was already in its lookup call, and the tool response supplied the queue ID. Replaying the archive let us measure prefix reuse on the follow-up. Prefix caching let the engine reuse attention state for the shared beginning. The application could keep sending the complete conversation.

I now look at two counters together when a follow-up feels slow: total prompt tokens and cached prompt tokens. Their difference counts uncached prompt tokens, including the newly appended tool response. In this replay, Qwen3.6 reached its first follow-up output a little earlier than Gemma (0.60 versus 0.72 seconds), yet Gemma finished the tool call a little earlier (1.66 versus 1.77 seconds). An agent can dispatch the tool once it has complete, valid arguments. That makes both clocks worth keeping.

What did it cost to keep the prefix?

I started with a simple question: how much space would one history take if it grew to 128K tokens? On Llama 3.1 8B, 32 layers keep keys and values for every position. With 8 KV heads, 128 dimensions per head and two bytes per element, one more token adds 128 KiB across the model. Multiply by 131,072 and you get 16 GiB.

Gemma 4 26B-A4B has 25 layers that can recycle local history after 1,024 positions. Those layers together need about 200 MiB of BF16 cache. Five global layers continue to accumulate history, adding 2.50 GiB at 128K. At the same 128K context length, Gemma uses less KV memory per session than Llama 3.1 8B. DeepSeek-V4.1-Flash uses compressed global history and reports 890 bytes per token; local state still needs a separate allowance. Formulas and checkpoint sources

One 128K session: Llama 3.1 8B needs 16 GiB of BF16 KV; Gemma 4 needs about 2.70 GiB with rolling windows; DeepSeek reports 111.25 MiB for global history alone.

The memory figures are estimates from architecture and storage format. The tool-call times came from a synthetic task on one machine. When I plan a service, I use the first set to budget for concurrent conversations and the second kind of test to see whether a returning conversation actually gets its cache back. A model’s advertised context length answers neither question on its own.

TokenFlow engineering note and capacity table · Earlier Spark serving experiment