mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-09-09 04:02:35 +00:00
The loop appends step/start before system/message and the entered user messages. Capturing nodes at step/start therefore omits inputs already included in the provider's successful usage, then adds those inputs back as a positive surface delta. Prompt replacement can also incorrectly add or subtract the difference from the prior prompt on a completed call. Snapshot the current priced surface immediately before assistant/message commits. Keep provider output separate from the durable assistant node so listener rewrites retain their signed delta. The invariant is zero delta immediately after an unchanged successful output: provider usage already includes every admitted prompt input. Later appends/replacements still produce signed deltas, and low or absent usage keeps heuristic fallback. Delete stepStart.nodes rather than adding prompt-specific corrections or another request snapshot: the existing transactional surface fold already contains the successful request inputs, including replacements made during same-step retry recovery. Keep turn/step state and all overlap, mismatch, and late-assistant lifecycle validation. Retry attempts are log-only and request middleware changes configuration; injected messages remain queued until admission. No loop, event format, projection, or retry policy changes. Exercise the real loop with reported usage and initial, growing, shrinking, and empty prompts; same-step failed attempt plus retry prompt replacement; request middleware; eager observation and fresh seeded replay. The two regressions fail before the fix with spurious deltas of +48 and +18 tokens. Retain existing durable-output rewrite, route repricing, missing/low usage, transactional failure, and lifecycle tests. Update README EN/ZH and the existing system-prompt surface-node Agent Note, including pairing records. Validation (dedicated worktree, no full unit suite): - pnpm exec vitest run packages/llm/token-meter/tests packages/compaction/compaction-basic/tests/compaction-loop-repro.spec.ts --coverage --coverage.include='packages/llm/token-meter/src/index.ts' 118 passed; exact changed runtime file 100% statements/branches/functions/lines. - pnpm exec vitest run packages/core/agent-loop/tests/request-reconstruction.spec.ts packages/compaction/compaction-basic/tests/compaction-basic.spec.ts packages/compaction/compaction-basic/tests/loader-composition.spec.ts 118 passed, including retry reconstruction and real Loader composition. - pnpm run doc-sync: 33 gates passed. - pnpm run test:docs: 15 gates passed. - pnpm run lint: passed, 0 warnings/errors. - git diff --cached --check: passed. Baseline normalize.ts comment conflict marker is intentionally untouched.
description, kind
| description | kind |
|---|---|
| Package map for the conversation-condensing feature family: automatic compaction, the on-demand /compact command, and tool-output trimming. | package-group |
compaction/ — compaction capability family
English | 中文
Summary
The compaction/ group keeps long agent conversations working near the model's context limit: older history is condensed into a summary automatically as token pressure builds, on demand with /compact, and oversized tool outputs can be trimmed first so there is less to condense. The shipped dsh base enables the feature by default — mount the packages explicitly to tune when and how condensation happens. The token measurement that decides when to condense lives in a separate LLM-family service.
Table of Contents
Packages
Each package below provides one piece of the feature; open a package page for how to use it.
| Package | Role | ctx key |
|---|---|---|
compaction/ |
The shared condensation contract: the operations and summary format every backend and trigger use | ctx.compaction |
compaction-basic/ |
Automatic condensation of older history into a summary as token pressure builds | registers ctx.compaction |
compaction-tool-result-pruner/ |
Trims oversized tool outputs so less history needs condensing | ctx.toolResultPruner |
command-compact/ |
The /compact command to condense history on demand |
registers on ctx.commands |
Related documentation
Start with the subsystem reference for the shared vocabulary, then read the two Agent Notes for the design rationale.
- Compaction subsystem reference — the condensation vocabulary, results, and service behavior.
- Compaction capability-seam Agent Note — how the family is split and why it depends on session and LLM vocabulary.
- Queued manual compaction Agent Note — how on-demand
/compactserializes against running turns. - Capability seams — the Service Definition / Service Provider / Consumer split this family follows.
Dev Note
Working context for maintainers — click to expand
None.