BUILD · Jun 20, 2026

DeepSeek V4's hybrid attention changes your agent context budget

How CSA and HCA compression make million-token context affordable for agents, and what that means for planning horizons, tool result accumulation, and multi-turn economics.

Agent-ready: drop this post into Claude Code or Codex

TL;DR: DeepSeek V4’s hybrid attention compresses the KV cache to ~2% of what a standard transformer needs at 1M context. For agents, this changes the economics of long-running sessions. Planning horizons expand from partial file reads to entire repositories. The recommendation shifts from aggressive context compression to letting the architecture handle it. But the advantage only matters when context is large — on short tasks, V4 underperforms models optimized for fast tool calls. The right approach is multi-model routing: V4 for analysis, something faster for execution.

Key takeaways:

  • DeepSeek V4 uses Compressed Sparse Attention (CSA) and Heavily Compressed Attention (HCA) to reduce KV cache to ~2% of a standard transformer at 1M context. At 1M tokens, V4-Pro uses 27% of V3.2’s compute and 10% of its memory.
  • Cache-hit input pricing at $0.0036/1M tokens. The fixed cost of agent scaffolding (system prompt, project conventions, tool schemas) drops to near-zero per turn. DeepSeek offers up to 90% discounts on repeated context prefixes.
  • Planning horizons expand from 128K (~900 lines of code) to 1M (~7,000 lines). The entire repository fits in active context. Context engineering shifts from “what to exclude” to “let compression handle it.”
  • The compression advantage disappears at short context. V4-Pro scores 67.9% on Terminal-Bench 2.0 vs GPT-5.5’s 82.7%. For rapid tool call loops, use a different model.
  • The practical deployment pattern is two-model routing: V4-Flash ($0.28/M) for wide scanning and batch work, V4-Pro ($3.48/M) for long-context analysis. Reserve frontier models for the critical execution path.

The first time I ran an agent with a 200K context budget, I was refreshing the API billing page every five minutes. The agent was doing legitimate work — loading a codebase, planning changes, calling tools — but at Claude Opus pricing ($25 per million output tokens), every long analysis pass cost about a meal. By the time the agent had loaded the whole repo, made a plan, and started executing, I had spent what the feature was worth.

I needed a cheaper way to do the analysis. The execution was fine on the expensive model. But the part where the agent loads everything and figures out what to do? That shouldn’t cost frontier API rates.

DeepSeek V4 is the model that makes that split rational. Here is why the architecture matters for that one question.

How does DeepSeek V4 compress attention differently from everything else?

The KV cache is the memory wall for long-context inference. Every token generates a Key and Value vector. These are cached so the model doesn’t recompute them on every generation step. At 1 million tokens, that cache becomes the single biggest memory bottleneck on inference hardware.

Earlier models tackled this by compressing the head dimension. Multi-Head Attention (MHA) stores one KV pair per head per token. Grouped-Query Attention (GQA) shares KV pairs across groups of heads, a 2-4x reduction. Multi-Head Latent Attention (MLA) compresses the KV into a low-rank latent, a 10-20x reduction. All of these compress the cache per token. The number of tokens still grows linearly.

DeepSeek V4 compresses along the sequence dimension itself. Instead of storing one KV entry per token, it stores one entry per group of tokens. This is a fundamentally different approach.

Compressed Sparse Attention (CSA) is the fine-grained compressor. It groups ~4 tokens into one KV entry. The grouping uses data-dependent weighting: the model learns per dimension which information to keep, rather than averaging blindly. Groups overlap instead of butting together, which prevents hard boundaries between compressed entries. The result is a 4x cache reduction before any other optimization kicks in, while preserving local resolution for next-token prediction.

Heavily Compressed Attention (HCA) is the aggressive compressor. It bundles up to 128 tokens into one KV entry. This acts as a global summary — a cheap, lossy representation of long stretches of context that the precise CSA and full attention layers can refer back to. Individual fine-grained details are sacrificed. But the model can suddenly reason over enormous spans of text without memory blowing up.

The layer stack determines which compression is used where. Early layers use HCA only — a cheap global summary of the entire context window, no local detail needed. Middle layers alternate between HCA and CSA — balancing long-range overview with local precision. The final layer uses full uncompressed attention — maximum precision for the one layer that directly determines the next token.

Think of it like a restaurant kitchen during service. The HCA layers are the pass — a global view of every ticket in the window, no individual ingredient details. The CSA layers are the station chefs — they know exactly what is on their four burners. The final layer is the head chef tasting the plate before it goes out. All three are needed. But you don’t need the head chef tasting every ingredient on every ticket.

The numbers are concrete. DeepSeek V4-Pro requires 27% of V3.2’s single-token inference FLOPs and 10% of its KV cache at 1M context (Nvidia NIM model card). The total KV cache footprint is roughly 2% of what a standard transformer would need. Low-rank query projections are shrunk to ~15.8% of original size. Grouped output projection to ~14.3%.

What does affordable 1M context change for agent design?

The planning horizon is the most immediate change. A standard 128K context window holds roughly 900 lines of code or 80 pages of conversation. Most agent frameworks use aggressive context compression — summarizing earlier tool results, dropping conversation history, implementing sliding windows over past turns — because the alternative is filling the context window on the first analysis pass.

At 1M tokens, that constraint loosens. A million tokens holds roughly 7,000 lines of code or 650 pages of conversation — enough for most production repositories. The agent can load the entire codebase, plan against the full surface area, and still have room for multi-step tool execution results.

This changes the recommendation. Before V4, context engineering guides told you to select carefully, compress aggressively, and design for tight budgets. With V4 on long-context tasks, the advice becomes: load everything, let the architecture compress it, and only pay attention to what doesn’t fit. The planning phase no longer needs to decide what to exclude. It includes everything by default.

The economics make this viable. DeepSeek’s cache-hit input pricing is $0.0036 per million tokens for Pro and $0.0028 for Flash. An agent loop rereads the same system prompt, project conventions, tool schemas, and relevant file context on every turn. With standard architectures, this repeated context grows the KV cache on every step and consumes memory. With CSA+HCA compression, the repeated context occupies a fraction of the memory. The fixed cost of agent scaffolding drops to pennies per session.

DeepSeek offers up to 90% discounts on repeated context prefixes, according to their API documentation. For multi-turn agent conversations where the same project context appears in every turn, this is the difference between watching the token counter nervously and ignoring it entirely.

Where does the compression fall short?

The compression advantage is a function of context length. When there is nothing to compress, the advantage disappears.

V4-Pro scores 67.9% on Terminal-Bench 2.0 — a benchmark that measures shell-based agentic tool use — against GPT-5.5’s 82.7%. That is a 15-point gap. Terminal workloads involve many small tool calls, short context windows, and rapid iteration. The million-token compression machinery has nothing to work with. The overhead of routing through CSA and HCA layers becomes pure cost.

The same pattern appears in Chew Loong Nian’s real-world testing across 20 tasks. V4-Flash won 7 tasks outright at $0.14 per million input tokens — all on shorter tasks where the price-quality tradeoff favored it. V4-Pro-Max only pulled ahead on three long-context retrieval tasks loading 800K tokens of a real GitHub repository and asking for a function’s call graph. Pro hit 3/3. Flash hit 1/3.

The pattern is consistent: V4 earns its premium when context is large. When context is small, use something else.

What does a practical V4 agent deployment look like?

The answer is multi-model routing. One architecture for analysis. A different one for execution. A third for the critical path.

V4-Flash for wide scanning and batch work. At $0.28 per million output tokens, it is 90x cheaper than Claude Opus 4.7 and 107x cheaper than GPT-5.5. Use it for code review sweeps across the entire repository, bulk classification, data extraction, and any task where latency isn’t critical. The 1M context means you can feed it the whole repo without watching the counter.

V4-Pro for long-context analysis. At $3.48 per million output tokens, it is 12x Flash but still 7x cheaper than Opus. Use it when you need the quality gradient at extreme context — loading a full monorepo for architectural analysis, multi-hop retrieval, understanding how a large codebase fits together. The 1M context at 10% of V3.2’s memory cost makes this the only economically viable option for this workload.

Frontier model for critical execution. Opus 4.7 or GPT-5.5 for the execution path where a mistake costs more than the API call. The pattern: V4 does the analysis and produces a plan. The frontier model executes the plan on the narrow, high-stakes part.

This is the same pattern that restaurant kitchens use. The prep cooks handle mise en place — washing, chopping, portioning — across 50 ingredients. That is Flash’s job. The sous chef organizes the station and sequences the orders for the pass. That is Pro’s job. The head chef fires the protein and plates the dish. That is Opus’s job. Each role has different cost, different skill, and different leverage. You don’t have the head chef chopping onions.

What are the integration realities?

The architecture is the easy part. The integration is where the friction lives.

The thinking-mode protocol that V4 uses for its reasoning modes (Non-think, Think High, Think Max) is non-standard. OpenCode couldn’t run V4-Pro at launch — it kept failing on the thinking-mode handshake. Cursor’s forum had open threads about V4’s context being capped at 200K with reasoning_content errors after tool calls. Community GGUF support wasn’t available at launch. llama.cpp support trailed by days. MLX on Apple Silicon trailed by a similar margin.

vLLM works with the native FP4/FP8 checkpoints out of the box. That is the one bright spot. But the hardware floor is real: V4-Flash needs at least 2x A100 80GB or 1x H200 141GB. V4-Pro needs 4x A100 or 2x H200 to use the full 1M context. This isn’t a model you run on a laptop.

Alex Lavaee, who ran one of the more thorough independent evaluations, summarized the integration picture: “the practical takeaway is to budget for integration work, not just inference. You will likely maintain your own patches for several weeks.”

The message isn’t that V4 is unusable. It is that the first two weeks will be frustrating. By week three, the tool ecosystem will have caught up.

What is the bottom line for my agent budget?

The cost math for a typical agent session makes the case.

A single agent loop with 50 tool calls, 200K accumulated context, and mixed input-output:

  • V4-Flash: roughly ₹3 ($0.04)
  • V4-Pro: roughly ₹42 ($0.50)
  • Claude Opus 4.7: roughly ₹2,080 ($25)
  • GPT-5.5: roughly ₹2,495 ($30)

The gap widens with longer sessions. At 500K context and 200 tool calls:

  • V4-Flash: roughly ₹10 ($0.12)
  • V4-Pro: roughly ₹140 ($1.68)
  • Claude Opus 4.7: roughly ₹5,825 ($70)
  • GPT-5.5: roughly ₹6,990 ($84)

The DeepSeek numbers include cache-hit input pricing. The frontier model numbers assume no caching discounts.

The conclusion isn’t that V4 replaces frontier models everywhere. It is that the economics now support a three-tier architecture. Use Flash for the wide work. Use Pro for the deep analysis. Use frontier for the critical path. The cost of the analysis layer drops by roughly 90%. The cost of the critical path stays the same. The blended cost of the agent session drops by roughly 70-80%.

That is the architecture change that matters for builders.

Agent mode

DeepSeek V4's hybrid attention compresses KV cache along the sequence dimension rather than the head dimension, making million-token context economically viable. For agent workloads, this shifts the context engineering bottleneck from memory to integration — the architecture is ready, the tool ecosystem is not. Plan for two-week integration buffer before deploying to production.

FAQ

Can I use DeepSeek V4 through existing agent harnesses like Claude Code or OpenCode? Partial support at launch. vLLM works with native FP4/FP8 checkpoints. OpenCode and Cursor had integration issues with the thinking-mode protocol. Check the current state of your harness’s V4 adapter before building — the ecosystem is catching up fast but wasn’t ready on day one.

What is the cache-hit pricing and why does it matter for agents? Cache-hit input pricing is what the provider charges when your input matches a cached prefix. DeepSeek charges $0.0036/1M for V4-Pro and $0.0028/1M for V4-Flash on cache hits — roughly 90% off cache-miss rates. Agent loops constantly reread the same system prompt and project context. Cache-hit pricing makes the fixed cost of each turn essentially zero.

Does V4’s native FP4 inference affect output quality? DeepSeek designed V4 for native FP4 inference — it was trained for it, not quantized after training. Independent evaluations show V4-Pro roughly 5-7 points behind Claude Opus 4.7 on most coding benchmarks, which is competitive for a 7x price difference. FP4 isn’t a post-training optimization for V4; it is the training target.

How does V4-Flash compare to local models for cost-sensitive agent work? V4-Flash at $0.28/M output is hard to beat on pure cost for API-based work. But local models (Gemma 4 at open weights, LFM 2.5, Qwen 3.6) cost $0 per token and have no latency from network calls. The tradeoff is quality. For simple classification and extraction, local models win on latency and privacy. For complex reasoning with long context, V4-Flash wins on capability per dollar.

Will the CSA+HCA architecture spread to other model families? Likely yes. The compressed attention mechanism in DeepSeek V4 is the most significant architectural innovation in sequence-dimension compression. Other labs are expected to adopt similar approaches within two release cycles. Watch Llama 5, Qwen 4, and Mistral’s next foundation model for sequence-compression features.


This article was published on Agentic Up (https://agenticup.dev): practical guides for developers and founders building with AI agents. Reach me at [email protected]

Newsletter

Get the brief on AI agents

Practical posts on shipping agents, automating work, and building in public. No hype, no fluff.

Contact: [email protected]