DSH Plugin Store
Back to home

TT-Wang

dsh-slice-agent-loop

A drop-in DeepSeek Harness agent loop whose context engine is a bounded slice instead of a growing transcript

Stars
1
Language
TypeScript
Created
Aug 11, 2026
Updated
Aug 14, 2026
Other
GitHub repo

Introduction

dsh-slice-agent-loop

English | 中文

Every turn, hand the model exactly the context it needs. No more, no less.

That sounds like common sense, but today's mainstream coding agents replay the entire conversation history back to the model every call: the excess is never trimmed, and what falls short can never be recovered. This plugin brings a slice loop built around that one sentence into the DeepSeek Harness: same harness, same model, same tools and persistence — only the agent loop is swapped, so in every comparison below the loop itself is the only variable.

Early beta; tracks DSH snapshot 20260812T172954Z (rc.2; rc.1-compatible).

One sentence, two constraints

ConstraintTranscript (full-history) status quo
No moreContext has an upper boundContext grows to the window limit, then compacts; attention dilutes, the bill grows with every turn
No lessInformation stays recoverableAfter compaction, detail is gone and cannot be brought back

Three structural problems of the transcript architecture: A · Context rot — the longer the context, the less the model gets out of each item in it; B · compaction beheads the session — summaries are lossy and irreversible, the original text is nowhere; C · cost grows quadratically with turns — every call resends the full history; cache discounts delay the blow-up but cannot beat volume.

The design: a tape, and recall

What the model sees each turn is not the conversation history but a working slice rebuilt for that turn:

ZoneNature
system prompt · tool schemasFrozen, byte-identical for the whole session (prefix-cache friendly)
SESSION TAPEAppend-only ledger of sealed turns: what was asked and done, file baselines with patches applied, replies
OPEN FILESCurrently open files, with sha256 anchors and edited markers
Current turn + tool observationsAppended within the turn, sealed and archived at turn end

The tape looks like a transcript — append-only, cache-friendly — but every entry carries a hash and provenance. Long content is truncated at the cut with an exact marker, and the full text stays durable in the session log.

Recall is how "no less" is honored, in two tiers: recall_search finds which turn said something (scored search, tool-output flood excluded by default), recall_turn returns that turn verbatim. The tape leaves a signpost at every cut pointing back to the original.

Transcript's problemThis plugin's answer
A · Context rotBounded peak: the model always works in a small context
B · Compaction lossFold without losing: the session log is fully durable, two-tier recall retrieves verbatim
C · Quadratic costEach turn carries only what that turn needs; the tape is append-only, so the prefix cache works

Measurements: two arms, head to head

default = DSH's stock transcript loop (with calibrated compaction); slice = this plugin. Same harness, same tools, one round on each of two model generations: deepseek-v4-flash (0731) and deepseek-v4-pro (0813). Prices use the sheet effective 2026-08-16, at off-peak rates: flash miss $0.22/M · hit $0.007/M · output $0.66/M; pro $0.66 / $0.022 / $1.98 (peak doubles every rate, so relative deltas are unchanged). The new sheet narrows both cache discounts to ~1/30 (formerly flash 1/50, pro 1/120). Per-call ledgers kept, every number recomputable; results below report both rounds.

① Long-horizon loads · both arms × both models

The bounded slice's home turf is the long session — a transcript's cost and peak grow with every turn, a slice's do not. Two long-horizon scenarios (16-turn compaction amnesia · 76-turn context flood), each cell flash / pro:

ScenarioArmVerifier (flash / pro)Price (flash / pro)Peak (flash / pro)
s13 (16 turns)slice✓ / ✓$0.0241 / $0.090016K / 17K
default✓ / ✓$0.0296 / $0.085259K / 40K
s10 (76-turn flood)slice✓ zero loss / ✓ zero loss$0.1529 / $0.616332K / 43K
default✓ / ✗ early timeline LOST$0.3755 / $0.7682378K / 42K

The two s10 rounds together are the transcript dilemma caught whole. Flash round: default's compaction can't keep up with the flood, the peak ratchets to 378K — everything stays in context, every quiz passes, but the context is out of control. Pro round: compaction works properly (peak sawtooths 40→34→39→40, bounded at the threshold) — and it costs the early timeline that lived only in history: the verifier fails the run. Unbounded peak or lossy forgetting: a transcript must pick one. Slice, both rounds: bounded peak + zero loss, at 59% / 20% lower price. The short s13 scenario's price swings with the pricing structure (slice -18% under flash, +6% under pro); the peak advantage (2.4–3.7×) does not.

② Amnesia re-enactment · both arms · eviction-verified

24 benchmark numbers produced by the agent's own script run, existing only in tool output — before the exam: the numbers never enter any reply (turn 1 explicitly asks only to confirm the run), the source samples are deleted on first run (nothing on disk), and a dilution flood forces default's compaction to rewrite history multiple times. The exam has two tiers: first no hint at all, then an explicit "you produced these numbers yourself in this session — go check the records."

ModelArmEvictionNo-hint tierExplicit tierTrapPeakPriceWall
flashslice✓ 0/1624/2424/24no fabrication ✓21.5K$0.0521222s
default✓ 0/160/2424/24no fabrication ✓51.9K$0.0910569s
proslice✓ 0/1624/2424/24no fabrication ✓22.1K$0.1692383s
default✓ 0/1624/2424/24no fabrication ✓33.4K$0.46122014s

Both arms share the same durable substrate — DSH persists the full session log, so recovery is possible in principle for either. The difference is affordance, and it changes shape with model strength. On flash: given the neutral exam, slice spontaneously ran recall_search → recall_turn (the tape leaves signposts at every cut) and recovered within the turn; default searched the workspace, found nothing, and wrote UNKNOWN as instructed (zero fabrication, duly recorded) — until the explicit tier, where it zstd-decompressed its own session jsonl and dug the values out. Pro is strong enough that default performs that forensic dig unprompted — so the gap moves from whether recovery happens to what it costs: the same 24/24 takes slice 3 requests (383s / $0.169) and default 32 requests (2014s / $0.461) — 2.7× the price, 5.2× the wall clock. "Recoverable" and "goes and recovers" are separated by one layer of tools and signposts; the stronger the model, the more that layer shows up as pure efficiency.

③ CB-20 precision retrieval · both arms

ContextBench (given a real issue, the agent retrieves the code locations the fix depends on): a 20-question subset of the official 50-question benchmark. Paired comparison n=19 — default timed out (20 min) on one question in each round (different questions; both finished by slice in minutes):

Metric (19-question paired mean)slice flashdefault flashslice prodefault pro
fileRecall0.8160.7610.7520.780
spanRecall0.8470.7720.7940.811
filePrecision0.2270.2290.2440.212
F1 · file-level (from means)0.3550.3530.3680.333
F1 · file-level (macro)0.3420.3230.3430.327
total price$0.6021$0.5414$1.3603$1.7318
completion20/2019/2020/2019/20

The two generations swap the recall lead (slice +5.5pp under flash, default +2.8pp under pro), but slice wins F1 and completion on both, and pulls ahead on precision under pro (+3.2pp); price flips from +11% under flash to -21% under pro — pro's output is expensive ($1.98/M), and default's longer sessions and extra steps cost more on an expensive model. The re-read discipline a bounded slice forces stays an advantage on retrieval across both generations.

Per-question detail · flash (19 paired: recall / span / F1 / price)
Question (Multi-SWE-Bench)slice R/span/F1default R/span/F1slice $default $
c__0f94ce4d1.00/1.00/0.361.00/1.00/0.260.06010.0597
c__1ac60ce91.00/1.00/0.251.00/1.00/0.200.01600.0237
c__b9b452620.33/0.30/0.170.33/0.30/0.130.11180.0627
c__cdbc58901.00/1.00/0.221.00/1.00/0.180.03000.0267
cpp__6a4e21e90.67/0.63/0.220.67/0.25/0.400.03630.0283
cpp__7c9ef76c0.67/0.97/0.330.33/0.93/0.180.01940.0276
cpp__bca55dea1.00/1.00/0.640.29/0.14/0.210.04380.0206
cpp__fe080aac0.50/0.87/0.330.50/0.87/0.250.02580.0342
go__0498ad7f1.00/1.00/0.291.00/1.00/0.180.01750.0341
go__0b78ed501.00/1.00/0.671.00/1.00/1.000.01500.0095
go__0f79e39c1.00/1.00/0.501.00/1.00/0.500.01350.0094
go__1384380d0.67/0.39/0.420.67/0.51/0.320.03020.0764
go__1ba303a50.67/0.92/0.360.67/0.92/0.440.03650.0389
go__250649eb1.00/1.00/0.501.00/1.00/0.570.00990.0129
go__2a889a1d1.00/1.00/0.291.00/1.00/0.290.02990.0088
go__2c512ec30.00/0.00/0.000.00/0.00/0.000.03150.0171
go__3d1b31451.00/1.00/0.501.00/1.00/0.290.01370.0270
go__3d85271b1.00/1.00/0.221.00/1.00/0.220.01620.0106
go__3deeea9c1.00/1.00/0.221.00/0.75/0.500.04490.0131

Unpaired timeout: c__8bffb1b1 (default timed out at 20 minutes; slice finished in 137s, R/span 1.00/1.00, $0.0213).

Per-question detail · pro (19 paired: recall / span / F1 / price)
Question (Multi-SWE-Bench)slice R/span/F1default R/span/F1slice $default $
c__0f94ce4d0.40/0.65/0.170.80/0.85/0.330.14460.1326
c__8bffb1b11.00/1.00/0.441.00/1.00/0.360.04850.0906
c__b9b452620.33/0.30/0.400.33/0.30/0.200.05010.1579
c__cdbc58901.00/1.00/0.201.00/1.00/0.180.05150.1199
cpp__6a4e21e90.67/0.49/0.160.33/0.15/0.130.14110.0947
cpp__7c9ef76c0.33/0.93/0.120.67/0.97/0.270.12400.1051
cpp__bca55dea0.71/0.56/0.450.86/0.86/0.360.11440.1728
cpp__fe080aac0.50/0.87/0.360.50/0.71/0.290.06480.0763
go__0498ad7f1.00/1.00/0.401.00/1.00/0.290.04860.0551
go__0b78ed501.00/1.00/0.671.00/1.00/0.400.04150.1038
go__0f79e39c1.00/1.00/0.401.00/1.00/0.500.03460.0257
go__1384380d0.67/0.36/0.470.67/0.66/0.440.09760.0872
go__1ba303a50.67/0.92/0.440.67/0.92/0.360.06040.1281
go__250649eb1.00/1.00/0.571.00/1.00/0.500.06300.0348
go__2a889a1d1.00/1.00/0.221.00/1.00/0.400.03930.0603
go__2c512ec30.00/0.00/0.000.00/0.00/0.000.06430.0902
go__3d1b31451.00/1.00/0.291.00/1.00/0.290.05450.0501
go__3d85271b1.00/1.00/0.401.00/1.00/0.400.02590.0266
go__3deeea9c1.00/1.00/0.331.00/1.00/0.500.09150.1201

Unpaired timeout: c__1ac60ce9 (default timed out at 20 minutes; slice finished in 949s, R/span 1.00/1.00, $0.1222).

Defects and directions

DefectWhat it is, measuredDirection
1 · Cache hits are structurally fewer than a transcript loop'sThe slice is rebuilt every turn; when bytes move, cache entries die, so the fresh-input share is high (2–3× on short coding tasks). DeepSeek's cache discounts favor append-only transcripts (both ~1/30 under the sheet effective 2026-08-16; formerly flash 1/50, pro 1/120) — short and mid-length tasks may show no price advantage (measured +10–65% on some flash scenarios, though long-horizon debug now flips to -38%; +6% on s13 under pro).Two byte-hygiene optimizations (stable rendering, freeze-on-second-read) are scheduled; long-session and retrieval loads win under both pricings (s10: -59%/-20%; CB-20 pro: -21%); shallower cache discounts (Claude / OpenAI) move the crossover earlier.
2 · The recall channel depends on the model reaching for itHistory is byte-recoverable, and spontaneous recall under controlled pressure is proven (test ②); but on everyday coding loads active recall is near zero (most information fits tape capacity and push covers it), and cross-session "continue from yesterday" cold starts remain a risk.Make recall habitual on everyday loads and cold starts; agent memory is still frontier territory, work scheduled.
3 · Retrieval breadth vs. the frugal kernel is still being balancedThe current kernel buys precision and price at some recall-breadth regression against the previous build.Kernel A/B iteration continues.
4 · Still an early plugin overallCovers the web profile's agent-loop surface today; settings-panel alignment, the subagent ecosystem, and TUI are catching up. The core mechanisms (sealing, audit events, two-tier recall) are validated by the three test groups above.An engineering-coverage problem, not a technical-difficulty one.

Install

dsh plugin --profile web add "github:TT-Wang/dsh-slice-agent-loop#main"

Or from a local checkout: git clone then dsh plugin --profile web add . Restart web afterwards — bundles are composed at boot.

The bundled patch disables the stock loop and compaction — the bounded rebuild replaces both. If your composition carries an agent-loop-invariant row, remove it: a rebuilt slice cannot equal the derived history byte-for-byte, and this plugin refuses to load beside that assertion.

Configuration

keydefault
kernel'slice'system-prompt kernel; 'ported' swaps in the verbatim Python prompt (A/B arm)
maxStepsPerTurn50hard ceiling on continuation steps per turn
maxParallelToolCalls10parallel tool bodies per step; since DSH 0811 this also caps subagent fan-out

Set them from your profile's cordis.patch.yml, targeting the existing row by id (- id: slice-agent-loop + config:).

Development

npm install --legacy-peer-deps   # the @deepseek-ai/* peers are unpublished
npm run link:dsh                 # symlink them from your dsh checkout
npm run typecheck && npm test

lib/ is committed (git-source installs run no build) — npm run build before pushing. Real-model smoke: npm run e2e:recall (needs DEEPSEEK_API_KEY in env).

License

BSD-3-Clause — see LICENSE.