* feat(system-prompt): admit section updates incrementally * docs(system-prompt): accept retirement restart gap * test(system-prompt): cover retirement and reentry before admission * test(system-prompt): align rebase fixtures and persistence history * fix: align section prompt consumers and CI fixtures * test: pin credentials for section snapshot fixtures * test: align remaining snapshots with section admission * test: preserve section metadata in Web and PowerShell replays * refactor(system-prompt): retire sections through Cordis cleanup * chore: refresh section admission history after rebase * fix(system-prompt): advance admission head after compaction * fix(system-prompt): trim sections before admission hashing * docs: move system upgrade guides to current version * docs: add system message contribution cookbook * perf(system-prompt): avoid indexing history for admission * refactor(system-prompt): derive admission from logged sections * test(system-prompt): update lifecycle and compaction consumers * test(system-prompt): refresh CLI section event expectations * test(system-prompt): refresh question composer section metadata * feat(system-prompt): resolve same-name sections by scope * refactor(persona): use ordinary section registrations * refactor(system-prompt): clarify assembly and related control flow * test(system-prompt): reconcile rebased section snapshots * test(python): use current system text helper after rebase * test(system-prompt): refresh CLI expected section blocks * test(system-prompt): reconcile latest master integration * test(agent-loop): seed tools before deferred addition assertion * refactor(compaction): replace system heads when compacting prefixes * refactor(system-prompt): separate source text and notice attribution * fix(system-prompt): preserve legacy instructions in compaction snapshots * refactor(compaction): build system snapshots while reading the summary prefix * refactor(compaction): rebuild current system instructions * refactor(system-prompt): defer compaction rebuild to admission * refactor(system-prompt): remove redundant fixtures and setup * fix(plan-mode): announce committed user transitions * docs(system-prompt): reconcile section lifecycle and compaction design * refactor(system-prompt): consolidate projection version increments * fix(system-prompt): reconcile master integration and replay fixtures * docs(system-prompt): align upgrade guide with current release * refactor(system-prompt): make admission operations explicit * fix(system-prompt): reconcile master API and release changes * docs(system-prompt): regenerate catalogs after master refresh * refactor(llm-pi-ai): delegate text rendering to pi-ai * fix(llm-pi-ai): preserve blank lines between system text parts * refactor(system-prompt): remove redundant retirement metadata * refactor(system-prompt): own admission and use canonical surface targets * refactor(system-prompt): compare captured sections at commitment Assembly fixes section text and lifecycle; PromptAssembly.systemUpdates() compares them with the committed projection when the loop commits. This replaces SystemPrompt.admit(), needsRebuild() and isCurrent(), the SystemAdmission export, the loop's reassembly after compaction, and SessionSurface.systemHeadResetSeq. The projection records a pending rebuild as a boolean that an attributed reset clears. After a compaction inside a step, the rebuilt head uses the sections captured for that step; later source changes arrive as ordinary updates at the next step. * test: await the session read fixture and type a matcher for lint * test(tool-executor-ptc): describe same-name section override on executor replacement Duplicate section names no longer reject a scoped executor; the earlier registration is overridden and returns as an ordinary update when the executor leaves. * docs(upgrade-guide): move system-prompt integrations to v0.2.2-rc.3 The root version on master is 0.2.2-rc.3; verify-upgrade-guides rejects a guide added under an earlier version directory. * refactor(system-prompt): rebuild over system messages without sections A system message without source.sections now marks rebuilding pending, like a compaction summary. The next model attempt replaces the head with current sections and clears later system messages. This removes the separate legacy flag and its appended whole-prompt replacement and notice. Sessions written by earlier releases, migrated logs, and imported DeepSeek conversations take the same path, so the importer and its tests return to their master versions. * test(web): refresh the imported-conversation recording and drop a stray bytecode file The Web recording for a resumed DeepSeek import was recorded while the prompt was appended after the imported history; the head is replaced again, as on master. The .pyc under the macOS signing skill was staged by accident in an earlier merge. * refactor(session): scan system nodes on read surface.systemNodes is read only when a system rebuild is written. Scanning the current surface nodes on each read restores the surface fold's plan types and state to their master definitions, which no longer carry the system message. * refactor(session): rename SystemSurfaceNode.hasContent to isEmpty The flag reports that the logged content array has no blocks. isEmpty matches the documented "empty head" wording and covers a head that was written empty without ever being cleared. * refactor(llm): join system text through extractTextContent extractTextContent gains a trim option that trims each text block and omits blocks left empty. The DeepSeek serializer, the pi-ai converter, and the prompt inspector use it with a blank-line separator in place of three hand-written joins. The pi-ai converter now trims system and developer text like the other two, so whitespace-only blocks are omitted there as well. * test(snapshots): refresh the PowerShell and cordis-inspect recordings The two PowerShell scenarios still held the initial system message as one unattributed block; replay now writes one block per section with its attribution. The cordis-inspect-jsdoc recording embeds the API catalog, which names SystemSurfaceNode.isEmpty since the rename. * test(plan-mode,harness-dev-context): cover a rejected pre-step and a repeated legacy prompt A rejected pre-step must leave a queued plan-mode switch pending and unannounced until the next accepted step. A second unattributed system message with the same legacy paragraphs must keep the admitted paragraphs. * test(web): refresh Web recordings for section-attributed system messages Twenty-seven Web recordings still held the initial system message as one unattributed block. Replay now writes one text block per section with its attribution; twenty-six recordings differ only in that line. plan-review also records the plan-mode switch notice before the first prompt and appends a plan:status update on exit in place of a head replacement and a series header, so its expanded golden gains the notice row. The Creator persona test joins the system text blocks with blank lines, as the adapters do, before matching the persona line. * refactor(system-prompt): require the retry argument of systemUpdates The agent loop passes it on every attempt. A custom loop that omitted it on a retry received a full comparison in place of the pending rebuild, with no diagnostic; the type now makes each caller state which attempt it is. * docs(upgrade-guide): move the system prompt integrations guide to v0.2.2-rc.5 The root version is 0.2.2-rc.5 after the master merge, and verify-upgrade-guides rejects a guide added under an earlier version directory. * test(web): refresh the mention path presence recording for section-attributed system messages * test: align two specs that master left failing The DeepSeek settings spec waited for a saved notice carrying the provider label from before the rename to DeepSeek API. The Windows packaging workflow spec seeded one of the two helpers that the Stage workflow helpers step copies. * chore: remove a Python cache file committed by mistake
279 lines
23 KiB
Markdown
279 lines
23 KiB
Markdown
---
|
||
description: "面向部署场景的自动会话压缩(compaction):用于选择、调优或排查随 token 压力上升对较早历史进行摘要的方式。"
|
||
kind: "package-reference"
|
||
---
|
||
|
||
# @deepseek-ai/dsh-compaction-basic
|
||
|
||
[English](README.md) | 中文
|
||
|
||
## 概述
|
||
|
||
本包让长时 agent(智能体)会话在接近模型上下文上限时仍能正常工作。token 压力上升时,它会把最旧的历史压缩为摘要并保留近期消息;上下文溢出错误发生后,它会压缩并重试。你也可以通过 `/compact` 按需压缩,并选择先修剪超大工具输出。压缩使用一次额外的模型请求,并且只保留该请求返回的摘要文本。它无法缩减系统提示词、工具或会话前缀,也无法拆分单个不可分单元(例如一次超大工具调用)。
|
||
|
||
## 目录
|
||
|
||
- [使用本包](#use-this-package)
|
||
- [理解实现](#understand-the-implementation)
|
||
- [进一步探索](#further-exploration)
|
||
- [模型体验](#model-experience)
|
||
- [已知限制与暂缓事项](#known-limitations-and-deferred-work)
|
||
- [开发备注](#dev-note)
|
||
|
||
-----
|
||
|
||
<a id="use-this-package"></a>
|
||
## 使用本包
|
||
|
||
在已提供 LLM(大语言模型)、会话存储与 token 测量的组合中挂载本包,即可获得自动会话压缩。随附 `dsh` 基础配置默认启用它;需要控制压缩发生的时机时请显式挂载。
|
||
|
||
### 你会得到什么
|
||
|
||
默认设置下你会获得四种行为:会话向模型上下文上限增长时自动压缩;提供方确认上下文溢出错误后的恢复(先压缩再重试该请求);通过 `/compact` 命令按需压缩;以及——挂载修剪器时——压缩前对超大工具输出的修剪。
|
||
|
||
### 最小可用组合
|
||
|
||
挂载会话存储、token 测量、可选修剪器、本后端,以及可选的按需命令:
|
||
|
||
```yaml
|
||
- name: '@deepseek-ai/dsh-session'
|
||
- name: '@deepseek-ai/dsh-token-meter'
|
||
- name: '@deepseek-ai/dsh-compaction-tool-result-pruner'
|
||
- name: '@deepseek-ai/dsh-compaction-basic'
|
||
- name: '@deepseek-ai/dsh-command-compact'
|
||
```
|
||
|
||
你可以通过观察会话越过本来会溢出的位置继续工作、以及运行 `/compact` 立即压缩一次来确认成功。如果组合缺少 LLM、会话存储、会话投影或 token 测量,插件会加载失败。同一个后端可以服务上下文大小不同的模型;用按模型覆盖为每条路由设置各自的阈值与保留:
|
||
|
||
```yaml
|
||
- name: '@deepseek-ai/dsh-compaction-basic'
|
||
config:
|
||
thresholdRatio: 0.8
|
||
retainRatio: 0.16
|
||
modelPolicies:
|
||
- provider: local
|
||
model: small-context
|
||
thresholdRatio: 0.7
|
||
headroomTokens: 4096
|
||
maxTokens: 4096
|
||
retainTokens: 2048
|
||
```
|
||
|
||
### 调整压缩开始的时机
|
||
|
||
所有设置都可选。设上下文窗口为 `W`、生效请求输出上限为 `O`、余量为 `B`,默认触发阈值为 `floor(min(W × 0.8, W − O − B))`,其中 `B = 65,536` tokens。逐字保留的近期历史预算仍为 `W − O` 的 16%。下表列出全部设置;生成的[配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-compaction-basic)还包含字段类型。
|
||
|
||
| 字段 | 默认值 | 含义 |
|
||
|---|---|---|
|
||
| `thresholdRatio` | `0.8` | 用于 `floor(min(W × thresholdRatio, W − O − headroomTokens))` 的窗口比例。 |
|
||
| `headroomTokens` | `65536` | 路由请求输出预留之外的额外压力余量;必须为非负整数。 |
|
||
| `retainRatio` | `0.16` | 以 `W − O` 的一部分表示逐字保留的近期对话;与 `retainTokens` 互斥。 |
|
||
| `retainTokens` | — | 逐字保留的近期对话绝对预算;与 `retainRatio` 互斥,并且必须低于已解析阈值。 |
|
||
| `summarizationProvider` | `''` | 与 `summarizationModel` 一起设置;空对使用产生最新助手消息的模型,再回退到最新已路由请求目标,最后回退到 `AgentOptions` 对。 |
|
||
| `summarizationModel` | `''` | 与 `summarizationProvider` 一起设置;空对使用产生最新助手消息的模型,再回退到最新已路由请求目标,最后回退到 `AgentOptions` 对。 |
|
||
| `maxTokens` | `headroomTokens`(`65536`) | 正数摘要输出上限,包含提供方计入的推理 token。显式模型上限覆盖显式全局上限;否则跟随解析后的余量。 |
|
||
| `compactionRetries` | `1` | 压力仍高于阈值时,在首次压缩后进行的额外尝试次数。 |
|
||
| `maxOverflowRetries` | `1` | 已确认上下文窗口溢出后的最大重试次数;`0` 只禁用恢复。 |
|
||
| `modelPolicies` | `[]` | 针对个别模型路由的精确 `{ provider, model, ...partialPolicy }` 覆盖。 |
|
||
| `auto` | `true` | 启用自动压缩与溢出恢复;设为 `false` 则仅手动执行。 |
|
||
|
||
配置错误会快速失败:未知设置、重复的按模型覆盖、无效 token 数、两种保留形式同时出现,或保留比例不小于阈值比例,都会在加载时拒绝插件。模型首次使用时,`W − O − B` 必须为正,且解析出的保留预算必须低于触发阈值。余量为零时,必须在全局或对应模型策略中显式设置正数 `maxTokens`。小窗口部署必须配置适合其容量的余量;降低 `thresholdRatio` 可以提早压缩。
|
||
|
||
### 压缩运行时会发生什么
|
||
|
||
最旧的平衡范围会被替换为一条摘要消息,近期尾部保持逐字不变;对话从摘要继续。操作会报告压缩了多少历史项以及估算释放的 token 数。如果没有任何内容可以安全压缩——例如整个对话就是一个不可分单元——则不会有任何改变,也不会向会话日志写入任何内容。如果没有模型可以撰写摘要(既未配置目标,也还没有已路由请求),压缩会失败并给出清晰错误,提示你配置摘要提供方与模型,或先路由一次请求。
|
||
|
||
### 切换模型
|
||
|
||
在提供方或模型发生变化的请求写入日志前,自动压缩会按目标模型的容量、输出预留和压力策略测量现有历史。会话已有助手消息时,每次摘要(包括 `/compact` 和溢出恢复)都发给产生最新一条助手消息的模型,并使用该模型的摘要设置;首条助手消息之前,摘要使用最新请求头,再回退到 `AgentOptions` 对;新选中的模型在给出回答之前不会被使用,显式配置的摘要目标仍然优先。因此,当估算放行了目标模型、而它的第一次请求因过长被拒绝时,溢出恢复会用上一个给出回答的模型生成摘要,再重试目标请求。只有历史降到目标阈值以下,才会继续目标请求。失败会报告 `MODEL_SWITCH_COMPACTION_FAILED`,并保留原请求头;可选择更大窗口的模型,或修正报告的原因后重试。即使后续尝试失败,已经完成的裁剪或压缩仍保留在会话中。检查在下次请求准备时执行,`auto: false` 会禁用它。
|
||
|
||
即使历史很短,目标也必须有已注册的适配器、已声明的上下文容量和有效的压力预算。默认 65,536 token 的余量无法适配同等或更小的窗口;请按上例为该路由设置 `modelPolicies[].headroomTokens`。迁移方法见[升级指南](../../../docs/upgrade-guide/v0.2.1-alpha.4/model-switch-compaction/guide.zh.md)。
|
||
|
||
### 通过 /compact 按需压缩
|
||
|
||
挂载 `dsh-command-compact` 后,在聊天 UI 中输入 `/compact` 即可立即压缩,即使未达到压力阈值。命令会报告压缩了多少历史项以及估算节省的 token 数。当 agent 正在轮次中或压缩已在运行时,`/compact` 会报告压缩暂不可用;运行期间你发送的提示词会被接受,并在压缩结束后才开始。
|
||
|
||
### 修剪超大工具输出
|
||
|
||
在本包之前挂载 `dsh-compaction-tool-result-pruner`,即可在压缩过程中修剪超大工具结果。修剪不发起模型调用,并可能完全省去摘要:当修剪后的对话在阈值之内时,压缩会跳过摘要。修剪只在压缩触发条件满足后运行——低于压力的对话绝不会被触碰。
|
||
|
||
-----
|
||
|
||
<a id="understand-the-implementation"></a>
|
||
## 理解实现
|
||
|
||
<details>
|
||
<summary>实现细节——点击展开</summary>
|
||
|
||
本节解释后端背后的设计决策;可观察行为已在[使用本包](#use-this-package)中完整说明。
|
||
|
||
### 设计理念
|
||
|
||
该后端建立在四项承诺之上:
|
||
|
||
- **一个测量服务为每个决策定价。** 单例 `ctx.tokenMeter` 会在同一个已消费日志 revision 上测量最新规范已记录 envelope 与当前表层。路由适配器声明请求图片定价时,meter 会将其应用于图片历史。模型切换的压力、保留与范围选择使用目标定价;区域缩减验证使用上次已提交路由;已记录的替换影子价仍使用与路由无关的启发式规则,使纯投影 fold 保持一致。
|
||
- **日志记录的标记对就是事务。** 所有入口点共享一个先记录标记的区域事务:验证范围与活动锁,同步追加 `compaction/start`,准备并等待摘要,重新验证,再追加 `compaction/summary` 与替换,最后恰好进行一次闭合尝试。自动调用与显式范围调用要求数字标识的开放轮次归属与整个表层稳定;`compactNow()` 会预留空闲接纳,使用 `turn: null`,允许所选 span 之外追加仅追加上下文,flush 每次已闭合尝试,并在 `finally` 中释放接纳预留。
|
||
- **摘要复用提供方的热前缀。** 逐字回放 surface 节点 0 处 `system/message` 所承载的系统提示词、上次已路由请求的工具与已遮蔽区域消息,使辅助调用成为会话的真正前缀,因此只有尾随指令与摘要输出未缓存。
|
||
- **`summarize()` 是唯一的子类钩子。** 基于模板或远程摘要器的子类可以覆盖它,同时压力、保留、被引用的源事件、缩减验证与已遮蔽 token 计量仍由 token meter 负责。
|
||
|
||
### 自动触发与溢出恢复
|
||
|
||
`agent/request` listener 等待路由 listener 选定目标,再在新 header 记入日志前检查其压力。它直接使用 `compactPressure`,因为 `compactIfNeeded` 读取的是已提交的 header;两条路径都通过 `summarize()` 生成摘要;它先读取最新助手消息上记录的路由,再读取已提交的 header,因为失败的请求已经替换了该 header。仅供宿主使用的会话投影 `compactionAnsweredRoute` 保存这对提供方/模型,因此恢复的会话从检查点读取它;插件在构造时注册该投影,卸载时释放。
|
||
|
||
当 `auto: true` 时,串行 `agent/pre-step` 监听器会在请求派生前检查压力:它通过 `ctx.tokenMeter` 为最新持久路由请求封装定价,当压力越过路由模型的阈值时,先剪枝,再保留已定价的近期尾部并摘要最旧的平衡范围。显式指定的范围也可以从对话中部开始。两端都须保持工具调用与结果配对,且范围不能包含初始系统消息。`agent/request-error` 监听器响应提供方确认的 `CONTEXT_WINDOW_EXCEEDED`:它绕过常规阈值与保留策略,尝试一次最大平衡头部缩减,并且只在 surface 替换 generation 前进后才授权重试。取消全程保持最终决定权。
|
||
|
||
压力策略从拥有持久路由的适配器解析容量。容量缺失、输出预留与余量耗尽窗口,或保留预算不小于阈值时,手动压力路径会抛出目标特定配置错误。`agent/pre-step` listener 会对该精确目标警告一次,并继续本轮;提供方确认溢出后的恢复仍然可用。模型切换检查则以 `MODEL_SWITCH_COMPACTION_FAILED` 拒绝请求,容量或适配器查找失败时亦如此。
|
||
|
||
### 摘要机制
|
||
|
||
直接 `ctx.llm.stream()` 调用使用已配置的提供方/模型对与上限,回退到产生最新助手消息的模型,再回退到最新已记录请求目标,最后回退到 `AgentOptions` 对,而不运行仅用于 agent loop 的 `agent/request` 扩展点。该调用将 surface 节点 0 处派生的 `system/message` 作为 `messages` 的首项回放,后接已遮蔽区域消息(包括位于其 surface 位置的被遮蔽历史内 `system/message`),并提供最新请求 header 的有效工具供路由特定投影使用;摘要发给与该 header 不同的模型时也是如此。所选适配器必须解析回放消息中的图片引用或明确拒绝它们。调用将压缩指令作为最后一条 user 消息追加,在投影允许时保留提供方的热前缀 cache。空内容系统头节点不贡献消息,但仍处于压缩范围之外。最终指令是冻结的 `RequestUserInput`,不含持久身份或来源;回放历史和持久化检查点仍然使用持久消息。调用将 `GenerateOptions.purpose` 设为 `compaction`;只有返回文本进入检查点,推理与工具调用都会被排除。图片输出会以 `UNSUPPORTED_CONTENT` 失败,而不是消失。替换 user 消息用 `<compacted-summary>` 标签框定摘要;原始摘要保留在 `compaction/summary` 事件上。 调用还携带 `Session.toolHistory()`,供运行时投影延迟和保留定义;若前缀缺少更新消息,则使用有效声明且不发送 developer 更新。
|
||
|
||
### 区域事务
|
||
|
||
摘要请求失败后,后端先检查取消和选区稳定性,再触发同步的 `compaction/summary-error`。恢复监听器必须先记录持久的输入变更,才能请求重试。后端重新派生所选消息,更新 token 价格及判断摘要是否缩短输入的基准。图片省略插件负责选图;后续摘要失败或取消后,已经记录的省略仍然有效。
|
||
|
||
事务验证选区和持久锁后追加 `compaction/start`。摘要模型按表层中的内容接收初始系统消息和所选对话。压缩不会求值当前系统来源。系统提示词服务会在下一次对话模型请求尝试前根据当前来源重建指令,包括溢出恢复后的重试。
|
||
|
||
事务检查整个表层(自动调用)或所选范围(手动调用)仍然稳定,并确认框定后的摘要小于所选范围。随后追加相邻的 `compaction/summary` 与替换用的 `user/message` 事件。初始系统消息和所选范围之外的消息保持不变。之后恰好尝试一次 `compaction/end`。较新的 `session/end-seed` 之前未匹配的 start 已过期,该边界之后的未匹配 start 报告 `busy`。清理与持久化结束后,取消仍具有最终决定权。
|
||
|
||
### 配置解析
|
||
|
||
`resolveConfig` 验证并分离默认值,`resolveTargetPolicy` 合并精确的提供方/模型覆盖,`resolveCompactSpec` 要求显式传入适配器容量与路由请求的输出预留,以解析触发阈值和保留预算。预留取自生效信封的 `maxTokens`,否则回退到适配器默认值,再回退到零。策略解析绝不咨询模型发现(`listModels()`);容量来自持久路由,切换模型时则来自拟使用的目标。
|
||
|
||
### 源码地图
|
||
|
||
| 文件 | 职责 |
|
||
|---|---|
|
||
| [`src/index.ts`](src/index.ts) | 插件入口:`BasicCompactionEngine`、自动 listener、入口点分发 |
|
||
| [`src/answered-route.ts`](src/answered-route.ts) | 仅供宿主使用的投影,保存最新助手消息上记录的提供方/模型 |
|
||
| [`src/region.ts`](src/region.ts) | 保留选择与共享的先记录标记压缩事务 |
|
||
| [`src/summarizer.ts`](src/summarizer.ts) | 默认 `ctx.llm.stream()` 摘要、检查点框定、安全摘要投影 |
|
||
| [`src/config.ts`](src/config.ts) | 加载时验证与路由模型策略解析 |
|
||
| [`src/types.ts`](src/types.ts) | `BasicCompactionConfig` 与已解析策略词汇 |
|
||
|
||
包根入口的类型声明将 `compaction` 添加到 `LlmRequestPurposeMap`。直接构造压缩请求的调用方使用 `import type {} from '@deepseek-ai/dsh-compaction-basic'`,使 `GenerateOptions.purpose` 包含该键。
|
||
|
||
</details>
|
||
|
||
-----
|
||
|
||
<a id="further-exploration"></a>
|
||
## 进一步探索
|
||
|
||
当包级约定不够用时阅读以下页面;它们从共享 seam 逐步进入可选配套工具与决策证据。
|
||
|
||
- [压缩 seam](../compaction/README.zh.md)——本后端实现的压缩约定。
|
||
- [压缩子系统参考](../../../docs/subsystems/compaction.zh.md)——压缩词汇、结果与服务行为。
|
||
- [工具结果修剪器](../compaction-tool-result-pruner/README.zh.md)——先修剪超大工具输出的可选配套工具。
|
||
- [人类 /compact 命令](../command-compact/README.zh.md)——无需等待压力的按需压缩。
|
||
- [Token meter](../../llm/token-meter/README.zh.md)——决定何时压缩的测量服务。
|
||
- [生成配置目录](../../../docs/config-catalog.zh.md#deepseek-aidsh-compaction-basic)——每个受支持配置字段及其源声明。
|
||
|
||
-----
|
||
|
||
<a id="model-experience"></a>
|
||
## 模型体验
|
||
|
||
### 会话历史
|
||
|
||
#### 模型看到的内容
|
||
|
||
成功步骤越过阈值后,可选修剪器先改写超大工具结果。如果仍需摘要,下一个请求从头节点接收当前系统指令,并从选区位置接收检查点。检查点由下方前导、一个空行、`<compacted-summary>`、返回的摘要和 `</compacted-summary>` 组成。其他保留的对话消息维持相对顺序。溢出恢复根据这份已记录历史派生立即重试。
|
||
|
||
##### 会话检查点前导
|
||
|
||
```markdown
|
||
This is an automatically generated checkpoint condensing an earlier span of the conversation to free up context. Treat the captured context as established background and build on it without restating it. Continue the task directly from the messages that follow, without acknowledging this checkpoint.
|
||
```
|
||
|
||
#### Token 影响
|
||
|
||
不依赖模型的剪枝可以完全避免辅助调用;否则它会先缩减该调用的文本记录,再用摘要替换较早范围。缩减检查比较框定后的摘要与所选范围,不计入之后的系统提示词重建,因此不保证完整的下一次请求更小。摘要会保留到后续压缩将其替换,但不可分的非工具单元仍可能超出预算。
|
||
|
||
#### KV Cache 影响
|
||
|
||
检查点使从第一个已替换历史 token 起的前缀复用失效。下一次模型尝试还会重建系统头,因此指令变化也可能使选区之前的复用失效。
|
||
|
||
### 辅助摘要器请求
|
||
|
||
#### 模型看到的内容
|
||
|
||
摘要模型接收日志中的系统头、所选对话、该路由的工具声明与 developer 更新,最后是下方的压缩指令。后续请求中的对话模型会收到新的系统头和摘要。压缩指令与摘要模型的推理仅属于辅助请求。
|
||
|
||
##### 压缩指令(最终 user 消息)
|
||
|
||
```markdown
|
||
You are now acting as a compaction engine for this AI coding assistant. Condense the conversation ABOVE into a structured checkpoint that lets another model resume the work with no loss of essential context.
|
||
|
||
Output EXACTLY the Markdown structure below: keep every section, in order. Use terse bullets, not prose paragraphs. Write "(none)" for an empty section — never drop a section.
|
||
|
||
## Primary Request and Intent
|
||
- [the user's original and evolving goals; quote verbatim where the exact wording matters]
|
||
|
||
## Key Technical Concepts
|
||
- [technologies, frameworks, patterns, and conventions in play]
|
||
|
||
## Files and Code
|
||
- [exact path: why it matters, key changes or snippets]
|
||
|
||
## Errors and Fixes
|
||
- [error: how it was resolved, plus any related user feedback]
|
||
|
||
## Pending Jobs
|
||
- [explicitly requested work not yet completed]
|
||
|
||
## Current Work
|
||
- [precisely what was in progress at this checkpoint]
|
||
|
||
## Next Step
|
||
- [the single next action, directly in line with the most recent request, or "(none)"]
|
||
|
||
## Critical Context
|
||
- [decisions and their rationale, constraints, user preferences, open questions, data needed to continue]
|
||
|
||
Rules:
|
||
- Write concise English engineering prose. Preserve exact file paths, commands, error strings, identifiers, numeric values, function signatures, and syntax fragments.
|
||
- Capture user feedback and explicit instructions faithfully, especially corrections.
|
||
- Do NOT mention this summarization request or that the context was compacted.
|
||
- Output only the checkpoint text: do not call any tool or take any other action.
|
||
- If the conversation already contains a <compacted-summary> block, it is a PRIOR checkpoint. Do not copy it forward verbatim: preserve still-true facts, drop stale ones, and merge newer information into a single consolidated summary under the same structure.
|
||
```
|
||
|
||
#### Token 影响
|
||
|
||
这是一次独立模型调用:输入是已回放会话前缀加固定指令,输出受 `maxTokens` 限制。收敛重试可能多次支付这项成本。
|
||
|
||
#### KV Cache 影响
|
||
|
||
已回放系统提示词、工具与已遮蔽区域消息与会话最后一个已路由请求逐字匹配,因此提供方的热前缀 cache 可复用至尾随指令之前;只有该指令与摘要输出未缓存。将摘要器路由到不同提供方/模型,或压缩非头部范围,都会放弃该复用。
|
||
|
||
## 已知限制与暂缓事项
|
||
|
||
<a id="known-limitations-and-deferred-work"></a>
|
||
|
||
|
||
这些限制说明自动压缩何时不合适,或何时需要特别注意;它们是当前包约束。
|
||
|
||
- **计量准确度取决于固定启发式规则**——可复用提供方用量缺失时,会回退到字符数加结构开销,而非精确的 token 化;只有在适配器声明了请求图片定价的路由上,图片出现处才携带提供方精确的视觉 token。
|
||
- **不会跳过已不可用的回答模型**——即使产生最新助手消息的模型已无法处理请求(例如凭据被撤销或额度用尽),摘要仍发给它。在新选中的模型给出第一次回答之前,`/compact` 和压力压缩会在该模型上失败;请发送一条消息让新模型给出回答,或配置 `summarizationModel`。
|
||
- **摘要请求不会拆分**——当摘要模型装不下所选范围加压缩指令时(例如它自己的历史已经溢出),摘要请求失败,不写入检查点;请配置窗口更大的 `summarizationModel`。
|
||
- **溢出分类由适配器维护**——提供方措辞可能改变;两个 DeepSeek 适配器将可识别的上下文限制失败规范化为 `CONTEXT_WINDOW_EXCEEDED`。
|
||
- **部分不可分单元与仅 envelope 溢出仍不在表层压缩范围内**——恢复无法缩减系统/工具/前缀、拆分不可分的非工具节点,或修复不可剪枝剩余部分仍超出窗口的工具单元。可选 pruner 可以缩减原本不可分工具对内的文本型工具结果主体。
|
||
- **`compactRegion` 要求存在未结束的轮次**——在完全关闭的会话上手动调用会抛出异常(「no open turn」),而不是执行压缩。
|
||
- **摘要失败会保留最新持久表层**——步前压力检查会记录警告并继续;模型切换压力检查会拒绝目标请求。两种失败都会保留已完成的剪枝与之前的检查点。因达到 `maxTokens` 而发生的摘要截断(隐藏推理 token 可能会耗尽该额度)遵循同一规则。
|
||
- **跨模型图片定价可能拒绝有效摘要**——切换时按目标定价选择范围,但按已提交路由验证缩减。不同的图片价格可能使摘要未通过缩减验证,即使它能降低目标压力。
|
||
|
||
<a id="dev-note"></a>
|
||
### 开发备注
|
||
|
||
<details>
|
||
<summary>维护者的工作上下文——点击展开</summary>
|
||
|
||
本开发备注是维护者的工作上下文,明确不具权威性;已交付行为以上文、包代码与所链接的 Agent Note 为准。
|
||
|
||
- **默认比例,尚未决定**——`thresholdRatio: 0.8` 与 `retainRatio: 0.16` 是固定默认值;存在通过 `modelPolicies` 进行的按模型调优,但没有基于语料的理想值指引记录。
|
||
- **tokenizer 精确测量,暂缓**——token meter 每 token 四字符的启发式对 CJK 文本与 JSON Schema 定价偏低;精确 token 化仍是测量服务的开放方向。
|
||
- **规范错误之外的溢出恢复,尚未决定**——恢复仅针对 `CONTEXT_WINDOW_EXCEEDED` 触发;其他提供方侧上下文失败不参与分类。
|
||
|
||
</details>
|