Local inference · 3 min read

The Hidden Cost of Giving AI Agents More Context

Budget for the served window, then measure what happens when a worker sees the same prefix again.

Group 1 · Qwen3.5-4B. Window — First padded — Later cached. 4K — first request — median. 8K — first request — median. 16K — first request — median.

A planner preparing three workers for the same repository has an appealing shortcut. Give each worker the project history, the architecture notes, and the entire conversation. Every worker gets the background. Every worker also has to fit the assignment, relevant code, tool definitions, and eventual answer into the capacity of its own serving slot.

Lemonade exposes two numbers that answer different planning questions. The model metadata can describe its maximum context window. The served context length describes the runtime configuration for the loaded model. PR #3280 exposes that second value. A scheduler deciding what to send on this request needs the runtime value and a policy for the case where it is absent. Lemonade PR #3280

curl -s http://localhost:13305/v1/models
{
  "max_context_window": 32768,
  "context_length": 8192
}

Those values illustrate two fields from a model entry. With that configuration, planning against 32,768 would promise four times the served capacity. Even 8,192 is an upper bound on the whole exchange. The output, message framing, and space needed to inspect a tool result can all draw on that same budget.

Separate a capacity question from a latency question

The Group 1 Qwen3.5-4B study compared the time to the first generated token on the first padded request with the median of later cached requests at 4K, 8K, and 16K. Prompt length and configured context increased together. A comparison across those conditions cannot isolate the effect of changing only the configured window. Comparing a first request with a later median also changes the reuse conditions. The figure shows the comparison design. Its labels are conditions, not timing estimates.

For a follow-up, hold the model, backend, hardware, prompt text, and output cap fixed while varying only the configured window. Then hold the window fixed and vary the padded input length. Record the actual input token count, time to first token, and total elapsed time separately. Repeat both with an identical prefix and with the stable prefix deliberately changed. Name the cache state in the run record so someone reading the table can reconstruct the comparison.

Make a packing decision a worker can explain

Suppose the served window has 8,192 slots and the scheduler reserves 1,024 for a reply and verification. After 2,048 tokens of shared instructions and 2,700 of task evidence, 2,420 remain. A 2,000-token summary fits that example. A 3,000-token transcript does not. The planner can report those numbers before asking the model to generate anything. Count the serialized request with the appropriate tokenizer when implementing the design.

For parallel Fredrin-style workers, I would put stable repository instructions first, put changing task evidence after them, and select history for each assignment independently. Identical prefixes give a compatible backend an opportunity for reuse. Worker affinity, eviction, and backend cache behavior still determine whether it happens. Two workers receiving the same prefix is a testable scheduling hypothesis, not evidence of a shared cache hit.

Keep a receipt for each packing decision. Write down the runtime limit, what was reserved, what was omitted, and whether the finished task passed its checks. A smaller prompt that discards the failing input may return sooner and leave the reviewer with a second round of work. Pairing the latency record with the acceptance receipt makes that trade visible.

Supporting diagrams (4)
Illustrative model metadata. Model maximum — 32,768. Served context length — 8,192.
Two context lengths in one entry
Worked example · tokens. Served window — 8,192. Reply + checks — 1,024. Shared + task input — 4,748. Available for history — 2,420.
A worker’s context budget
Proposed prompt layout. Worker — Stable prefix — Changing suffix. Planner — repo rules — task and plan. Tester — repo rules — fixture inputs.
What two workers can reuse
Proposed design. Trial A — Fix input length, vary window. Trial B — Fix window, vary input length. Record for each — Prefix state, TTFT and total time.
A cleaner follow-up experiment
Planner workspaceFit a task into context ↗