Skip to main content
Vadim Nicolai
Senior Software Engineer

Senior Software Engineer building AI-powered products with TypeScript, Rust, and LLMs. Writes about AI agents, eval-driven development, and edge computing.

View all authors

The Long-Context Tax: Token 32,768 Costs 20x Token 1

· 35 min read
Vadim Nicolai
Senior Software Engineer

This week brought two very different answers to the same problem. Qwen4 uses Gated DeltaNet in 30 of its 40 layers. Amazon's Ergo, a 1.1T-parameter open-weight model, uses sliding-window plus grouped-query attention. The problem both are solving: every token an LLM generates re-reads the keys and values of every earlier token, in every layer.

I wanted the actual size of that tax, so I built the decode step from scratch in numpy and measured it on my MacBook (M4 Pro, 24 GB): six attention designs, one Qwen3-4B-shaped model, contexts from 0 to 32,768 tokens. Nothing was downloaded; random weights at real model shapes time exactly like trained ones. The full script is at the end.

Every token you generate re-reads the entire conversation: what token 32,768 costs in units of token 1, at 32 concurrent users

What token 32,768 costs in units of token 1, with 32 users sharing the server:

  1. Multi-head attention (MHA): 78x, and an 18.0 GiB KV cache per user.
  2. Grouped-query attention (GQA, 8 KV heads), the default of most open models: 20x, 4.5 GiB.
  3. Multi-head latent attention (MLA), DeepSeek's design: 6.4x, 1.27 GiB.
  4. A 3:1 DeltaNet hybrid, Qwen4's layer ratio: 4.9x, 1.15 GiB.
  5. A 4K sliding window, the building block of Ergo and Gemma: 3.4x, 0.56 GiB.
  6. Gated DeltaNet (linear attention) alone: 1.0x, 0.04 GiB.

Then I ran the config.json of 19 open models through the same arithmetic. Per 128K-token conversation, Llama 3.1 70B keeps 40 GiB of cache, Amazon Ergo 8.1 GiB, Qwen4 2.6 GiB and DeepSeek V4 Flash 0.68 GiB.

I think the KV cache, not FLOPs, is now the main design constraint of open LLMs. Every architecture trend of 2026 shrinks the bytes kept per token; none of them makes the matrix multiplications cheaper.

Btw, for a single user the tax is only 1.6x on a GQA model at the bandwidth floor. It explodes when a server batches users, which is what everyone paying for inference does. The rest of this post is the measurements behind each number, an architecture gallery of what each design stores, the 19-model simulation, and how this week's releases read through it.

Inference Server on an M4 Pro: The Practical 26x Speedup

· 16 min read
Vadim Nicolai
Senior Software Engineer

Athrael's course Introduction to GPU Inference has a lesson called "Your first inference server". You install narwhal-inference and start a router with four llama.cpp engines: two do prefill and two do decode. The engines serve ERNIE-4.5-0.3B at 4-bit, and you load-test them with 2,000 prompts. The lesson lists Linux and WSL2 as supported. It does not list macOS. I ran it on my MacBook (Apple M4 Pro, 24 GB) anyway, to see how far it gets.

In short, it runs on the M4 only inside an x86 Linux container under Rosetta, at about 4% of the lesson's throughput. The same model on native llama.cpp with Metal matches the lesson's per-token decode speed from a single engine.

Inference server on an M4 Pro: Narwhal under Rosetta vs native llama.cpp on Metal

Context7 LangGraph Test: Claude Code on APIs It Never Saw

· 12 min read
Vadim Nicolai
Senior Software Engineer

I gave Claude Code three tasks on upstash-redis 1.9.0, an SDK release from November 2026. That release is newer than the model's training, and the SDK was not installed where the agent worked. With web access denied and no docs source, it passed 0 of 9 runs. With Context7, it passed 7 of 9. In the baseline, 6 runs declined to write code and 3 wrote an older answer. On an API it already knew (LangGraph 1.2's interrupt), it passed every time either way. In that Context7 LangGraph test, Context7 confirmed the answer for about 6 cents more per run. Setup details are below.

Context7 LangGraph test results: 0 of 9 runs passed without Context7 and 7 of 9 with Context7 on upstash-redis 1.9.0

Agent Eval Harness: 6 Essential ADLC Steps to Build First

· 17 min read
Vadim Nicolai
Senior Software Engineer

Six of the eight agent vendors I surveyed ship an evaluation runner as product code. IBM, Salesforce, AWS, Databricks, Google and Microsoft each give you a command or function that runs your agent against a test set and scores it. Only one of them writes down the rule that makes the runner useful, and that rule lives in a sample skill, not in the product.

AI Agent Design: 5 Essential Scoping Rules in the ADLC

· 10 min read
Vadim Nicolai
Senior Software Engineer

AI agent design is the phase of the agent development lifecycle (ADLC) with the least product code behind it. In part 01 I read the lifecycle pages and public repos of eight vendors. For design, only Salesforce ships an artifact you can write and check in. Everywhere else, design survives only as runtime settings: a tool list, an autonomy mode, a call or spend cap.

How AWS threat-designer decides its LangGraph agent is done: a deterministic validate node, not the model, and a quiet floor of 25 threats

· 8 min read
Vadim Nicolai
Senior Software Engineer

Nothing the model says ends a threat-designer run. When the agent stops calling tools, it has not finished. It has only reached a plain Python function that decides whether it may finish.

Through a precondition buried in a tool, that function also rejects any catalog smaller than 25 threats (constants.py L124). I found that rule nowhere stated as a product requirement.

My claim is that this is the right design for deciding who controls the exit. It is also a crude way to define what "done" means. If you believe the model should orchestrate its own loop, you will disagree with the first half.

How GitLab runs a stateless LangGraph agent on a custom checkpointer

· 14 min read
Vadim Nicolai
Senior Software Engineer

GitLab Duo's agent service, the Duo Workflow Service behind GitLab Duo Agent Platform, writes every LangGraph checkpoint into GitLab's own Postgres, yet the service has no connection to that database. Each checkpoint read and write travels down the user's own gRPC stream. The client (an IDE, the CLI or Workhorse) makes the HTTP call to GitLab and hands back the answer.

A LangGraph agent service can keep nothing about a session between requests if a custom LangGraph checkpointer writes into the database the product already has. Inside a request, it still holds the whole run in memory.

The Duo Workflow Service (DWS) pays for this with a second copy of LangGraph's persistence layer. That price is right for GitLab. For most teams it is wrong, for the reason in the last section.

On 2026-11-21 I measured 60 big-company public repos for LangGraph depth. Of the 18 deep users, GitLab's ai-assist ranked second, with 56 production files importing LangGraph and 61 checked-in graphs. Five of the 18 run their product on a saver they wrote, and only GitLab relays checkpoint writes through the client.

Everything I say about DWS comes from reading ai-assist's main branch as of 2026-11-23. I did not run DWS, did not call GitLab's API, and measured no latency.

How Kibana pauses a LangGraph agent without a checkpointer

· 13 min read
Vadim Nicolai
Senior Software Engineer

Elastic's human-in-the-loop tutorial compiles the graph with a MemorySaver and resumes with a Command that carries the user's choice (Rengifo (2026)). Elastic's shipped Agent Builder agent uses neither a checkpointer nor a resume Command.

On 2026-11-21 I measured 60 big-company public repos and found 18 that use LangGraph deeply. Kibana is the only one of them that pauses for a human without a checkpointer. The 16 others that pause all use interrupt and a resume Command.

I also collected 1,187 AI-engineering postings on 2026-11-22. The 94 that mention LangGraph ask for human-in-the-loop or durable execution 28% of the time, against 9.8% of the other postings. Those counts lean low, for two reasons: a mention is often one item in a "LangGraph, CrewAI or similar" list, and I truncated long postings.