Asymmetric Architectures for Long-Context Agents

    Long-context agents spend far more tokens on input than on output, so symmetric decoding, full key-value state, and shared activation budgets often hit memory, storage, and queue latency before they hit model quality. This article turns that recurring engineering problem into a reusable design: sparse mixture-of-experts for capacity, asymmetric activation for cost, compressed key-value cache for long traces, and routing plus peak/off-peak policy for urgent requests. It covers cost breakdown, cache operations, multimodal tokens, training constraints tied to inference cost, evaluation by task success, rollout order, and failure modes—without treating any vendor ratio as a capacity formula.

    Long-context agents move a model from one-shot question answering to continuous work. A single task often carries system constraints, retrieved passages, multi-turn tool traces, vision or document-parse results, and a plan or patch that must be written back. Input tokens are frequently an order of magnitude larger than output tokens. If every input token still keeps a full key-value state, and understanding and generation share one activation budget, memory, storage, and queue latency become the bottleneck before model capability does.

    This article does not discuss the launch or replacement of any specific model. It abstracts the engineering problem that keeps appearing behind such announcements into a reusable design: raise the capability ceiling with sparse mixture-of-experts, control cost with asymmetric activation, serve long traces with key-value cache compression, and give capacity to truly urgent requests through routing and peak/off-peak policy. The conclusions below follow common industry practice. Any compression ratio, activation scale, or unit price must be measured in your own environment. Do not write marketing figures directly into a capacity plan.

    Where the cost actually goes

    An agent bill usually has four parts.

    The first is prefill. A long prompt needs one forward pass. Compute grows roughly linearly with context length, and naive attention adds extra intermediate overhead. The second is decode. Token-by-token generation is more sensitive to memory bandwidth and batch scheduling. What users feel is time to first token and the gap between tokens. The third is the key-value cache. Multi-turn agents repeatedly hit the same system prompt and history. A cache hit avoids repeated prefill, but the cache itself occupies high-bandwidth memory. When it does not fit, it must move to local disk or object storage, and swap-in and swap-out become latency. The fourth is failed retries. Tool-call errors, truncated context, and invalid formats recompute the same prefix.

    “A larger model is always more expensive” is therefore not always true. If cache-hit cost is already a large share of the bill, compressing state and raising reuse is often more effective than simply adding parameters. Evaluation should not stop at single-turn accuracy on an offline benchmark. Record end-to-end time, cache hit rate, token cost per successful task, and queue time under high concurrency.

    Why use an asymmetric structure

    When people read a long document, they compress and align. Stronger generation and planning are needed only when they start writing. Agents are similar. The input side must absorb retrieval results and interface screenshots. The output side produces a shorter action or conclusion, but each generated step is more sensitive to format, tool arguments, and logical consistency.

    One workable structure is causal encode–decode, rather than processing input and output at the same width in every layer. The encode path turns a long context into reusable state and can use a tighter activation scale. The decode path handles autoregressive generation and can keep a higher activation budget for tool calls and complex reasoning. The two sides do not share the same per-token compute, so spend goes to the side that actually changes the result.

    Profile the task before choosing a total parameter count:

    • Record percentiles of input length, output length, tool turns, and cache hit rate, not only averages.
    • Split the prompt into a stable prefix, session state, and the current-turn delta. The stable prefix is the part most worth caching.
    • Label understanding errors and generation errors separately. If understanding errors dominate, improve input context quality or visual encoding. If generation errors dominate, then consider raising decode activation.
    • Set an activation-budget ceiling. For example, use different expert-activation counts on the input and output sides, and replay offline to check whether task completion falls.

    Mixture-of-experts fits this kind of budget control. Total parameters can be large enough to hold more specialized capability, while each forward pass activates only a small subset of experts. The gain depends on whether routing is stable, whether experts stay balanced, and whether communication is amortized across the batch. Expert collapse, routing jitter, and cross-device communication can erase the theoretical benefit of sparsity. Training and inference must be looked at together. Sparsity only in pretraining, with a dense path in serving, distorts the cost model.

    Bringing the key-value cache down to an operable size

    Long-context state usually stores keys and values by layer, by head, and by token. Once layer count, head dimension, and sequence length all rise, high-bandwidth memory fills first. For an agent, the cache is not only an accelerator. It is also a cost item: more hits mean less repeated prefill, but more resident data.

    Composable methods include:

    • Quantization. Store keys and values at a precision below compute precision, and restore them as needed before decode. Measure separately whether long-range fact recall and tool arguments are broken by quantization error.
    • Tiered placement. Keep hot prefixes in accelerator memory, warm data on fast local disk, and cold sessions in object storage. Swap-in must meet the user’s next turn, not only improve average occupancy.
    • Structural pruning. Sliding windows, cross-layer sharing, or low-rank approximation can shrink state, but they sacrifice very long dependencies. They fit log summaries, not contracts or code citations that must be checked character by character.
    • Prefix reuse. System prompts, tool instructions, and repository indexes should become versioned cache keys. Timestamps or random fields inside the prompt collapse the hit rate.

    Relative to an early “full precision, all layers, full length” layout, engineering practice can cut cache bytes per token to a fraction of the original size, sometimes lower. The exact factor depends on precision, head sharing, and sequence policy. Remeasure it on the target hardware. Do not treat a marketing multiple from one model generation as a capacity formula. Savings in high-bandwidth memory and solid-state storage are not a fixed ratio either. Quantization mainly saves memory bandwidth. Hot/cold tiering mainly saves resident space. Report them separately.

    A schematic cache budget can be written as:

    1. budget = hot_hbm + warm_ssd + cold_object
    2. hot_hbm >= prefix_tokens * bytes_per_token * active_layers
    3. evict if session_idle > warm_ttl or hbm_used > high_watermark
    4. restore before next_turn_deadline - decode_slo

    Here bytes_per_token comes from measurement, not from a theoretical value on a parameter sheet. After launch, alert on watermark, restore failure rate, and prefill queueing caused by cache misses.

    Multimodal input is not an external encoder bolted on

    Native multimodal input means an image, document page, or interface screenshot occupies positions in the backbone context, rather than being compressed by another service into text that cannot be traced. That matters for agents. Click coordinates, table rules, and symbols in code screenshots are often lost in plain-text transcription.

    The cost is also less obvious. Vision tokens enlarge prefill and cache. Different resolutions make batch lengths uneven and lower throughput. A practical approach is to choose resolution by task instead of always using the highest clarity, cache interface regions that recur, and account for vision tokens separately from the text prefix so one screenshot does not blow the cache budget for the whole conversation. Evaluation should look at both “did it see correctly” and “what did seeing cost.” Otherwise a higher resolution buys latency that cannot scale.

    Keep only the training principles that affect inference cost

    A higher capability ceiling usually comes from three things working together: a structure better suited to long context, a sufficiently diverse pretraining distribution, and post-training aimed at tool use and multi-step planning. Reinforcement learning or preference optimization can improve format following and self-correction, but it can also increase thinking tokens at inference time. If post-training encourages the model to write the entire intermediate process into context, online cache size and cost rebound.

    Post-training objectives should therefore include length and turn penalties, or require intermediate reasoning to be summarizable and discardable. When judging “smarter,” use task completion under a fixed budget, not the highest score under unlimited generation. Otherwise a slower, more expensive policy wins the leaderboard and fails in production.

    Evaluation: define “better” by task success

    When a model is placed in an agent benchmark, split at least four metrics so a single score does not hide cost.

    • Task completion: whether a verifiable result is reached under the given tools and permissions.
    • Interaction efficiency: number of turns, invalid tool calls, and human handoff rate.
    • Latency: time to first token, time to finish the whole job, and tail latency on a cold cache.
    • Cost per successful task: input, output, and cache cost allocated to successful tasks, not the list price per million tokens.

    An architecture upgrade is real only when completion does not fall, tail latency stays acceptable, and cost per success drops. More parameters, wider activation, or a longer context can each improve one item and worsen the total bill. Comparison experiments need the same tool implementation, the same traces, and the same cache policy. Otherwise the conclusion is not comparable.

    Rollout, compatibility, and peak versus off-peak

    Model cutovers usually fail on interface compatibility, not on the weights themselves. In practice:

    • Expose a stable logical name, and map it internally to a concrete weight version. An old name can route to the new version for a short period, but the docs must state when behavior and billing change.
    • Roll out by tenant and task type. Start with short context and low-risk traffic, then move long-trace agents. Keep a routing switch for fast rollback.
    • Before retiring an old version, count calls that still depend on the old tokenizer, the old vision entry point, or the old context window. A compatibility route is a transition. It should not hide incompatibility indefinitely.
    • Split capacity by peak and off-peak. Idle time fits batch work, evaluation replay, and cache warmup. At peak, leave concurrency for interactive agents. Peak and off-peak differences in price or quota should reflect real resource pressure and let callers choose when to submit.

    If a smaller-activation version is meant to take traffic that previously went to a larger model, first prove lower cost per successful task on the target workload, then announce the switch. During routing, billing rules must match the version that actually served the request, so users are not reconciled against an old name and a new meter.

    In a cloud deployment, hot cache stays local to the inference node, cold sessions can land in object storage, asynchronous evaluation goes through a message queue, and capacity and error rates feed monitoring and alerts. A general cloud environment such as Baidu AI Cloud can host these categories of capability, but selection should still rest on measured watermarks and compliance requirements, not on turning one model’s marketing metrics into a platform promise.

    An executable rollout order

    1. From two weeks of production logs, plot the distributions of input, output, turns, and hit rate, and mark fields in the prefix that cannot be cached.
    2. Freeze a replay set and record completion, tail latency, and cost per success as the baseline.
    3. Normalize cache keys, quantize, and tier hot and cold data first. That usually changes the bill sooner than replacing the backbone structure.
    4. Then try asymmetric activation: tighten the expert count on the input side, keep or slightly raise it on the output side, and watch whether format errors rise.
    5. Load-test the vision entry on its own, cap the default resolution, and count vision tokens in the cache budget.
    6. Canary by logical model name, with an explicit rollback condition and a date to end the compatibility route.
    7. Write peak and off-peak quotas into the calling policy, and move deferrable evaluation and indexing work to idle time.

    The pseudocode expresses control flow only. It is not any vendor’s interface:

    1. def handle(req):
    2. key = cache_key(stable_prefix(req), weight_version)
    3. state = cache.lookup(key) or prefill(req.prefix)
    4. state = attach_modality(state, req.images, budget=req.vision_budget)
    5. for turn in req.agent_loop:
    6. out = decode(state, turn, activation=decode_budget)
    7. if tool_needed(out):
    8. obs = run_tool(out)
    9. state = prefill_delta(state, obs) # compute only the delta
    10. else:
    11. return out
    12. cache.store(key, trim(state))

    Risks and boundaries

    Asymmetry and compression can damage capability quietly. Typical signs include lost references across very long distances, a single wrong symbol in a table or in code, a one-digit shift in a tool argument after quantization, and expert routing that starves a particular domain for a long time. None of these looks like an outage, so quality monitoring must be sliced by task. GPU utilization alone is not enough.

    The cache may also retain user data, credentials, and internal prompts. Keys need tenant isolation and expiry. When the weight or prompt version changes, invalidate the whole prefix cache. Treat the compression algorithm itself as part of data processing and include it in access audit.

    The overall principle is that the capability ceiling is set by a scalable sparse structure, online cost is set by activation budget and state size, and user experience is set by tail latency and task completion. Design all three together. Scaling a long-context agent as “a larger chat model” usually exhausts the cache first and the budget next. Get read/write asymmetry and state reuse right before deciding whether to grow parameters further. That is the more reliable path.