DeepSeek V4 and the Agent Context Problem

DeepSeek released V4 last week, and the benchmark crowd immediately started comparing it against GPT-5 and Gemini 2.5 on MMLU, HumanEval, and the usual suspects. The numbers are competitive. Not state-of-the-art. And that framing misses the entire point.

V4 isn't trying to win a benchmark. It's trying to solve the one problem that actually kills agent workflows in production: context management at scale. And it might be the first model architecture built from the ground up with that specific problem in mind.

Two checkpoints dropped: V4-Pro at 1.6T total parameters (49B active) and V4-Flash at 284B total (13B active). Both support a 1M-token context window. But the headline number isn't the story. The story is how they made that window usable without melting your GPU.

The KV Cache Problem Nobody Talks About

Here's what actually breaks when you run a frontier model as an agent. It's not that the model isn't smart enough. It's that every tool call, every file read, every shell command result gets appended to the context. Each subsequent token pays the full attention cost against everything that came before. The KV cache grows linearly. At some point — usually a few hundred tool calls in — you run out of GPU memory, the inference degrades, or you hit a context limit and the model loses its mind.

This isn't a theoretical concern. Anyone who has run Claude Code on a real codebase for more than 30 minutes has watched it happen. The agent starts strong, then gets confused midway through a multi-file refactor because it can't hold the full context anymore.

DeepSeek's numbers on this are striking: V4-Pro uses 27% of the per-token inference FLOPs compared to V3.2 at the same sequence length, and 10% of the KV cache memory. Compared to a standard grouped query attention architecture with 8 heads, V4 requires roughly 2% the KV cache size. V4-Flash is even more aggressive: 10% FLOPs, 7% KV cache.

That's not incremental improvement. That's a different league of efficiency. And it matters because it means you can actually run long agent trajectories without the economics becoming absurd.

How They Did It: Hybrid Attention

The mechanism is called Compressed Sparse Attention (CSA) paired with Heavily Compressed Attention (HCA), and they alternate across layers.

CSA compresses KV entries by 4x along the sequence dimension using softmax-gated pooling with a learned positional bias. A lightning indexer — running in FP4, which is aggressively low precision — picks the top-k compressed blocks per query. It's a sparse selection mechanism, but it operates on blocks that are already 4x shorter than the original sequence, so the search space shrinks accordingly.

HCA goes further: 128x compression, no sparse selection. Every query attends densely to every compressed block, but the compressed sequence is so short that dense attention is cheap. Think of it as a very lossy but very fast summary of everything that came before.

Both mechanisms include a sliding-window branch for recent uncompressed tokens — the model doesn't lose precision on the immediate context. The layers alternate between CSA and HCA across the 61-layer stack, with the multi-token prediction block at the end running sliding-window only.

The storage choices compound the compression: FP8 for most KV entries, BF16 only for the RoPE dimensions, FP4 for the lightning indexer. These aren't afterthoughts — they're integral to hitting the 2% KV cache figure.

Built for Agents, Not Chat

The architectural efficiency is necessary but not sufficient. Three post-training decisions target agent workflows directly, and these are where V4 genuinely differentiates from everything else on the market.

Interleaved thinking across tool calls

V3.2 preserved reasoning traces across tool-result rounds but discarded them whenever a new user message arrived. Fine for single-turn tasks. Catastrophic for multi-turn agentic workflows where the user sends a follow-up after the agent has already chained a dozen tool calls. The model would lose its accumulated reasoning and have to reconstruct state from scratch.

V4 preserves reasoning content across user message boundaries when the conversation contains tool calls. The complete reasoning history persists across all rounds. For non-tool conversations, the old behavior remains — reasoning flushes on each turn to keep context lean. This is a small change in implementation but a massive change in agent reliability. The model maintains coherent, cumulative chains of thought over long-horizon tasks.

XML-based tool calls with dedicated tokens

V4 introduces a |DSML| special token and an XML-based tool-call format. This sounds boring. It isn't. JSON-in-string tool calls are one of the most common failure modes in agent systems — nested quoting, escaped characters, numbers that should be strings, booleans that arrive as text. The XML format with explicit string="true" and string="false" attributes eliminates an entire class of parsing errors. Small detail, huge reliability improvement.

DSec: a sandbox built for RL rollouts

DeepSeek built a Rust-based sandbox platform called DSec that exposes four execution substrates — function calls, containers, microVMs via Firecracker, and full VMs via QEMU — behind a single Python SDK. A single cluster runs hundreds of thousands of concurrent sandboxes. This is the infrastructure they used to train agent behavior with RL against real tool environments. The fact that they built this tells you where their priorities are: agents are not a side project for DeepSeek. They're the main event.

The DeepClaude Signal

Within days of V4's release, someone built deepclaude — a wrapper that swaps Claude Code's API backend from Anthropic to DeepSeek V4 Pro. Same terminal UX, same tool loop, same file editing and bash execution. Just a different model doing the thinking.

The pricing tells the story: $0.87/M output tokens for DeepSeek versus $15/M for Anthropic. That's 17x cheaper. DeepSeek's automatic context caching brings repeat turns down to $0.004/M. The tool spawned 245 points on Hacker News in six hours.

Whether deepclaude itself is a good idea is beside the point. What matters is that the community immediately recognized V4 as a model you'd want to plug into agent infrastructure. Not because it's the smartest model, but because it's the most practical model for the specific workload of running long autonomous coding sessions.

The MLX Angle

For those of us working on M-series Macs, there's a second relevant development. Hugging Face shipped a system for automatically porting transformers models to mlx-lm — a skill and test harness designed so that new models become available on MLX almost as soon as they land in transformers.

This matters because MLX is Apple's framework for running ML models efficiently on Apple Silicon. The combination of V4-Flash's 13B active parameters and efficient KV cache with MLX's unified memory architecture on an M4 Ultra could make local agent workflows viable in a way they simply weren't before. You're not going to run V4-Pro locally — 1.6T parameters is still cloud territory — but V4-Flash at 13B active with 2% KV cache? That's a very different proposition.

What This Means for Agent-First Development

The harness engineering thesis — the one I wrote a 620-page book about — rests on the assumption that models will keep getting better at following instructions within well-designed constraints. V4 validates that assumption from an unexpected angle. It's not that the model is dramatically smarter. It's that the architecture is designed to stay smart over long tool-use trajectories without degrading.

This changes the calculus for harness engineers in three ways:

  • Less defensive context management. When the KV cache is 2% of traditional size, you can afford to include more documentation, more examples, and more task history in the agent's context window. The cost of being thorough drops by orders of magnitude.
  • Longer autonomous runs. The "reprompt every 30 minutes" pattern that most agent workflows default to exists because models degrade over long contexts. If V4's architecture delivers on its efficiency promises, you can design harnesses that let agents run for hours without losing coherence.
  • Cheaper experimentation. At $0.87/M output tokens with aggressive caching, the economics of running agent development loops change fundamentally. You can test harness changes more often, iterate faster, and ship sooner.

The Real Benchmark

We've been measuring AI progress with static benchmarks for too long. MMLU, HumanEval, GPQA — these measure capability in isolation. They tell you how smart a model is on a single forward pass with a clean prompt.

Agent workflows don't work like that. They're messy, multi-turn, stateful, and context-heavy. The model that wins in production isn't the one that scores highest on a benchmark — it's the one that maintains coherence over a hundred tool calls, doesn't forget what it was doing when you send a follow-up, and costs less than your cloud compute budget.

DeepSeek V4 might not top the leaderboards. But it might be the first model that's actually designed for how we're using these things in practice. That's the benchmark I care about.


If this resonates, you might enjoy my book Harness Engineering: The Complete Guide to Agent-First Software Development — 27 chapters covering everything from context engineering to multi-agent orchestration to the economics of agent-first teams.