An agent on a single RTX 3090: where context gets lost

We run a coding and office-work agent fully locally: Qwen 27B on a single RTX 3090, our own Rust/CUDA inference engine flash-moe, and our own agent, run-done. The context window is 90K tokens. Here is what we measured.

TL;DR

  • On your own GPU, the expensive thing is a prefix-cache miss, not context length. Re-prefilling 70K tokens takes over a minute.
  • History compaction loses the working details. Across 18 sessions, none of 115 commands, 20 file paths or 30 error messages made it into the summary.
  • NVIDIA's step-wise compaction saves no time on a local GPU: each context restart costs 70–110 s.
  • Three things work: tool output goes to a file, a "shift handoff" summary, and a mechanical block of commands and errors.

Setup

GPURTX 3090, 24 GB
ModelQwen3.8-27B, Q4_K_M, fully in VRAM
Engineflash-moe: Marlin, int8 KV cache, prefix cache, MTP speculation, tool-call mask
Agentrun-done: tools, tool selection, subagents, compaction
Speedprefill 863–913 tok/s, decode 71–76 tok/s, 69–83% of the prompt served from cache

The real cost is a cache miss

An API charges the same per token at any length. Your own GPU charges in time. The engine reuses only an exact prefix: change one byte at the start of the prompt and the whole tail is recomputed.

In September we put the summary at the start of the prompt together with a message counter. The counter changed every turn and flushed the cache. Now the start of the prompt never changes, and any context rebuild is a rare event.

Tool output goes to a file

Since August 2026 the agent saves long bash output and file reads to disk in full. The context gets the head, the tail and the file path. The model reads what it needs with grep and sed.

The test: a 1.1 MB book, 3–4 times larger than the window. The task: read it in full, name the last chapter and the five points before the conclusion.

The model did not read it all. It read the end, found the key phrase with grep, read the text around it and the table of contents. 35 seconds, 15K tokens of context, both answers correct, the points quoted verbatim.

What compaction loses

We compared compaction summaries with the full history of 18 sessions:

In historyIn summary
bash commands1150
File paths200
Error messages300

For Claude Code logs, the deja-vu tool counted 0.2% of commands and 9.8% of paths surviving. After compaction the model remembers the plan but not the command with its flags, the error text or the file it needs.

We added three modes, each switched on by a setting:

  1. Shift handoff. A four-part summary: the task verbatim, current state, failed attempts with the reason, the plan.
  2. "Déjà vu" block. Plain code, no model, extracts from the full history the request, the latest commands with exit codes, files and errors. The block survives repeated compactions.
  3. Step-wise mode. At the window threshold the turn restarts: task, summary, block, recent messages.

Step-wise compaction is expensive

Measured on 14 recorded sessions. Summary of 1,500 tokens, prefill 700 tok/s, decode 28 tok/s.

Threshold (above system)Median peak contextExtra engine time per call
no mode50.6K0 s
12K41.4K3.4 s
24K30.4K6.6 s
48K47.8K1.0 s

One restart at the 24K threshold: 54 s to generate the summary, 17 s to re-prefill the tail, up to 36 s to prefill the head. Through an API, generation is fast and the mode pays off. On a 3090 it does not.

We enabled the shift handoff and the "déjà vu" block. Step-wise mode only with a threshold of 48K or more.

Tool-call mask in the engine

The engine does not let the model break a tool call:

  • the name must come from the list;
  • the keys must follow the schema;
  • the response is cut off if a call is repeated verbatim.

The last rule came after a response with 131 identical calls.

The mask works together with speculation: a draft is accepted as long as the mask allows it. A 34-token call is generated at 104 tok/s, versus 37 tok/s before.

Inkling 2 Mini vs Qwen 27B

Inkling 2 Mini is a MoE model with 5.4B active parameters. We ported it to flash-moe and checked it against llama.cpp: KLD 3.3·10⁻³, the first token matched in 39 of 41 positions.

Inkling 2 MiniQwen 27B
68 tasks83–86%91–96%
Time per task2.3–3.0 s1–3 s
Tool use, 27 tasks, strict57–59%91–94%
Same, "called a suitable tool"89–96%89–100%
With hints and 5 selected tools78–81%83–85%
Same on 22 new tasks68%95–100%

We checked everything that could have spoiled the result:

  • the port: KLD against llama.cpp at noise level;
  • the chat template: byte-identical to the official one;
  • sampling and reasoning effort: no difference;
  • quantization: Q8 (full precision) gave the same 56–59% as Q4.

Inkling picks a suitable tool, but more often reaches for bash and looks around first. Hints and a narrower tool list lift it to 78–81%, but on new wording the gain shrinks to 68%. A narrower list only hurts Qwen. The vendor itself reports Inkling below Qwen 27B on agentic benchmarks. For the agent we kept Qwen.

Takeaways

  1. On your own GPU, protect the cache first: the start of the prompt must not change.
  2. Keep large data in files. A 27B model finds what it needs with grep.
  3. When compacting, preserve commands, paths and errors with code, not with the model.
  4. Verify API recipes on your own GPU by measuring.