Asymmetric Inference Architecture for Long-Context Agents: Prefill/Decode Budgets, KV Cache, and Sparse Memory

    Real agent workloads are rarely short question-and-answer exchanges. A single task may require reading repositories, logs, API documentation, and multiple rounds of tool returns before producing a compact patch, conclusion, or next tool call. This article examines why long-context agents benefit from asymmetric inference: smaller prefill-side activation, compact causal context encoding, shared or projected KV cache, stage-aware expert routing, side memory lookup for low-value patterns, and sparse access over shared global state. It also covers evaluation metrics, failure modes, and boundaries for choosing this architecture.

    Asymmetric Inference Architecture for Long-Context Agents

    Agent applications rarely run on short question-and-answer traffic. A single task often begins by reading a repository, logs, API documentation, and multiple rounds of tool returns, then ends with a relatively compact patch, conclusion, or next tool call. If prefill and decode share the same path—where every token activates parameters of the same scale and every layer maintains its own global key-value cache—the compute and memory cost of long context is consumed first by the reading phase. Faster generation alone may not improve end-to-end latency enough to matter. One engineering direction with strong explanatory power is to split the network into a causal structure that first compresses context and then retrieves what generation needs, while allowing the two sides to use asymmetric activation scales.

    Load asymmetry is the problem the architecture must solve

    A common assumption in traditional mixture-of-experts networks is that each token activates roughly the same expert scale whether the model is in prefill or decode. This is simple to implement and easy to load-balance, but it does not match the agent bill. Prefill must scan every historical token, so compute grows linearly with context length or worse. Decode usually appends only a small number of tokens, but it must repeatedly read an already long cache. Binding both stages to the same activation budget is equivalent to pricing the reading phase with the compute standard of the generation phase.

    A more reasonable split is to price by stage. The reading phase aims to turn a long sequence into a compact representation that can later be retrieved and aligned; it does not need to expand full global interaction at every layer. The generation phase needs stronger step-by-step reasoning and larger activation capacity. If prefill-side activation is clearly smaller than decode-side activation, the marginal cost of long-read, short-write workloads falls, and the advantage becomes more visible when cache hit rates are high. This is not a simple counterexample to “larger parameters are slower.” It separates total parameters, active parameters, and stage parameters: total scale determines the upper bound of what can be remembered and composed; active scale determines the bill for a single forward pass.

    How a causal encoder-decoder changes the KV cache

    It is useful to think of the lower layers as a causal encoder and the upper layers as a decoder, but this should not be imagined as two independent networks unrelated to the training objective. The encoder works mainly during prefill, compressing context along the causal direction into compact hidden states. The decoder runs as the main path during generation. The key difference is that global key-value state does not have to be recreated by every decoder layer from its own hidden state. The final encoder-layer hidden state can be projected into global KV for upper layers to use, while the decode side keeps only local state that is more relevant to the current generation.

    A direct consequence is that context representation can be tighter. In a traditional per-layer global cache, the number of layers, number of heads, and sequence length multiply together to determine cache size. Projection-based sharing converges “global memory” into one construction at the end of the encoder, and upper layers read it as needed. The cost is that the projection must preserve causality: later text cannot see tokens that have not yet been generated, and positions and segment boundaries must align with the original sequence. Otherwise, the compressed representation will fail at long-range coreference and at tool-return boundaries.

    Three things should be validated separately during design. First, after compression, can cross-segment retrieval still locate early constraints such as API contracts, error codes, and options the user has already rejected? Second, when the decoder runs only upper layers, does local coherence degrade through repetition, missing constraints, or premature closure? Third, do the projection dimensions match the upper-layer head dimensions? Avoid narrowing channels so much to save cache that fine-grained features such as multimodal signals or code symbols are lost.

    Asymmetric activation is not arbitrary expert halving

    Asymmetry means that the same model uses different activation scales for prefill and decode, not that two unrelated small models are used. Expert routing, shared layers, and cross-stage residual paths must still be jointly optimized under the same training objective. If half the experts are simply disabled at inference time, the routing distribution will drift from training. Reading quality will collapse first, and generation-speed numbers will be meaningless.

    A more stable engineering approach is for routing to see both budgets during training. The prefill path encourages “few but stable” expert combinations, focusing on local patterns, entity normalization, and long-range compression. The decode path allows more experts to participate in composition, focusing on planning, tool selection, and multi-step consistency. The two sides can share some resident experts so that rare knowledge does not exist only on one side. Load balancing also cannot rely only on a whole-network average; it must be measured by stage. Otherwise, prefill experts may sit idle while decode experts are congested at the same time.

    Compared with symmetric mixture-of-experts with identical input and output activation, the gains of an asymmetric structure are concentrated in context-dominated tasks: codebase question answering, log attribution, multi-document verification, and tool calls with long system prompts. If the task itself has short context and long-form generation, larger decode-side activation becomes the main cost, and the reading discount from asymmetry is diluted. Before choosing an architecture, use real traffic to break down the bill by stage rather than looking only at single-generation token throughput.

    Move low-value memory out of attention

    Large models contain a class of capabilities that has low computational value but consumes substantial parameters and attention: fixed collocations, entity aliases, common local patterns, and format templates. If all of these are computed on the fly by deep attention, long contexts will repeatedly pay for the same pattern. A cleaner division of labor is to leave composition and reasoning in the transformer layers, while moving local memory that can be table-hit into a side memory module, such as fragment-hash embedding lookup. Lookup results are injected into the backbone through residual or gated paths. A hit means less computation; a miss falls back to the backbone. Lookup failure must not become a silent error.

    This kind of side memory must control hash collisions and update strategy. Too many collisions bind unrelated fragments to the same vector, producing behavior that looks familiar but gets every detail wrong. The memory table should also not replace retrieval from external knowledge bases. A table is suitable for stable, high-frequency patterns covered within the training distribution. Volatile facts, private documents, and real-time tool results should still go through external retrieval and context injection. Mixing both into one module bloats the memory table and removes the boundary that long-context compression needs.

    Sparse attention and shared key-value state

    Another waste in long context is dense global attention at every layer. A more common reorganization is to share global key-value state as much as possible or project it from terminal states, then use two-level indexing inside layers for sparse access. The first level uses a coarse index to locate potentially relevant blocks or segments. The second level performs fine-grained attention only on the candidate set. Compute then grows with the number of relevant blocks rather than with the full sequence length, but the index itself must be learnable and diagnosable.

    A typical symptom of sparse-index failure is an answer with normal style that ignores a hard constraint in the later or middle part of the sequence. Evaluation therefore cannot rely only on average loss or short-context benchmarks. Construct probes where constraints appear at different positions: a prohibition stated early, an API modified in the middle, or an error stack that appears only near the end. Shared key-value state also needs multimodal alignment checks. If image or document-layout features appear only early in the encoder, projecting them into global KV must preserve positional correspondence with text tokens. Otherwise, the generation phase may “see the image” but name the wrong region.

    Cost structure when multimodal and agent workloads are bound together

    Native multimodality is not simply concatenating visual tokens into a text sequence. Visual token counts are often large. If they follow the same symmetric activation and per-layer global cache as text, prefill time will dominate end-to-end latency. Placing visual compression on the encoder side and letting the decoder use visual evidence mainly through compact global state can improve both latency and token consumption. In practice, measure separately: prefill latency after visual tokens enter, text decode latency, cache hit rate, and token waste caused by repeatedly reading system prompts and tool results. A high cache hit rate only means prefix reuse works well; it does not replace the check of whether the architecture is still cheap on a single cache miss.

    If an agent runtime binds model training together with tool protocols, context assembly, and retry strategy, the benefit comes from distribution alignment, not from the brand of a runtime. The context forms seen during training should resemble production: which segments are trimmed, how tool returns are segmented, and whether failure traces are fed back. If training optimizes only clean dialogue, long tool chains in production will still amplify errors during prefill. Configuration changes should also be treated as part of the training distribution; otherwise, the same weights will drift sharply under different assembly strategies.

    Metrics and boundaries for deployment

    Evaluation should include at least four categories of metrics, split by stage rather than reporting a single generation token throughput. First, the slope of prefill latency relative to context length, and the slope when the share of multimodal tokens changes. Second, the relationship between decode latency and activation scale, confirming that asymmetry does not trade generation quality for speed. Third, long-range constraint retention, using position probes rather than subjective scores on open-ended questions. Fourth, total tokens and total time per task, because prefill savings may be offset by repeated retries and redundant context.

    The pseudocode below expresses stage budgets so they can be configured explicitly in the inference service rather than scattered across framework defaults.

    1. prefill_budget = compact_experts + memory_lookup + shared_kv_projection
    2. decode_budget = richer_experts + sparse_index_on_shared_kv
    3. # Enable a smaller prefill_budget first only when the task's context token count
    4. # is significantly larger than the planned generation token count

    The boundaries should also be clear. Asymmetric activation improves loads that match its structure, not every benchmark. Very short dialogues, pure long-form generation, and strongly real-time token-by-token interaction may be better served by symmetric activation or a smaller specialized model. Side memory and sparse indexing both add failure modes, so miss fallback and index hit-rate monitoring are required. Any specific parameter scale, token throughput, or billing figure should be based on actual measurement and cannot be extrapolated from an architecture sketch into a promise.

    If the above mechanisms are reduced to one selection principle, it is this: first measure the token ratio between prefill and decode and the cache hit rate, then decide whether to adopt causal segmentation, asymmetric activation, lookup memory, and sparse access over shared key-value state. Letting structure follow the bill is closer to the real constraints of agent workloads than simply piling on total parameters.