拓展阅读
压缩保真:状态与否定不能丢
把原始任务标成结构化命题,与故意错误的压缩状态比较,检查缺失、确定性、执行状态和版本差异。
沿着对象与状态理解本章
压缩最危险的不是少一句背景,而是把“未执行”写成“已完成”,把“禁止”写成“准备做”。先对照本图保留命题、版本、否定与未决状态,再考虑缩短多少Token。
下方图解的固定输入在“输入与适用条件”中声明。它用于解释本章机制,不与本章其他独立例子的数值暗中接续。
动态图解 · F27
压缩要保留行动所依赖的事实
把一百轮历史压成几句话,最容易丢什么?
像交班给另一位同事:对方最需要目标、禁止事项、已经做完的事、还没核实的事,以及到哪里看原证据。原始日志可以外置,但决定下一步动作的区别不能抹平。摘要也不是执行数据库,不应凭它判定不可重复动作是否已完成。
截断直接删掉一部分上下文。
摘要压缩用新文本概括旧信息,可能引入改写错误。
快照明确字段的当前状态记录。
证据引用重新获取原文的定位信息。
输入与适用条件:构造的exclude修复场景;有意保留“集成测试尚未运行”这一否定状态。错误摘要只作为反例,禁止当作推荐模板。
1 / 5 · 原历史有很多噪声
第1步,共5步
窄屏可左右滑动图形,或点击“放大图形”。文字解释紧随图后。
工具输出、失败尝试和重复讨论可以很长。压缩的目标是减少历史占用,不是美化成“进度不错”。
可恢复快照默认静止。用“下一步”看完解释再继续;播放到最后一步自动停止。键盘聚焦播放器后,可用左右键逐步查看、空格播放/暂停。图中颜色辅助区分,含义同时用文字注明。
为什么需要
有限窗口无法一直保留全部原始对话,但任务需要连续推进。
怎样实现
保留必要状态与引用,压缩后核对,再从原始来源恢复细节。
可能的代价与误解
摘要重写可能把猜测变结论,多轮摘要还可能累计偏移。
如何判断是否做对
比较压缩前后允许的下一步动作是否一致,而不只是文本相似度。
怎样观察与验证
错误样例会缺少public_api,并出现4处字段变化。它不是自然语言理解器;真实摘要需先可靠抽取命题,并继续执行任务验证。
运行命令
python3 reading-notes/experiments/05_compaction_fidelity.py完整教学代码
"""结构化命题保真检查。不是自然语言理解器,也不是 LLM 压缩实现。"""
from copy import deepcopy
CANONICAL = {
"public_api": {"value":"unchanged", "certainty":"required", "version":"all"},
"config_loaded": {"value":True, "certainty":"verified", "evidence":"T1"},
"path_cause": {"value":"base_mismatch", "certainty":"hypothesis", "evidence":None},
"patch": {"value":"not_applied", "certainty":"observed", "version":"v3"},
"tests": {"value":"pending", "certainty":"observed", "version":"v3"},
}
def compare_claims(reference: dict, candidate: dict) -> dict:
if not isinstance(reference,dict) or not isinstance(candidate,dict):
raise TypeError("输入必须是结构化命题字典")
missing = sorted(set(reference)-set(candidate))
extra = sorted(set(candidate)-set(reference))
changes=[]
for key in sorted(set(reference)&set(candidate)):
if not isinstance(reference[key],dict) or not isinstance(candidate[key],dict):
raise TypeError("每条命题必须包含字段字典")
for field in sorted(set(reference[key])|set(candidate[key])):
if reference[key].get(field) != candidate[key].get(field):
changes.append({"claim":key,"field":field,
"expected":reference[key].get(field),
"actual":candidate[key].get(field)})
return {"preserved": not missing and not extra and not changes,
"missing":missing,"extra":extra,"changed":changes}
def bad_summary() -> dict:
wrong=deepcopy(CANONICAL)
del wrong["public_api"]
wrong["path_cause"]["certainty"]="verified"
wrong["patch"]["value"]="applied"
wrong["tests"]={"value":"passed","certainty":"observed","version":"v2"}
return wrong
def self_test() -> None:
assert compare_claims(CANONICAL,deepcopy(CANONICAL))["preserved"]
result=compare_claims(CANONICAL,bad_summary())
assert not result["preserved"]
assert result["missing"] == ["public_api"]
assert len(result["changed"]) == 4
def run_demo() -> dict:
return {"性质":"人工标注命题上的确定性校验,不会自动判断自然语言",
"基准":CANONICAL,"错误压缩":bad_summary(),
"差异":compare_claims(CANONICAL,bad_summary()),
"限制":"真实压缩仍需人工/模型抽取校准,以及继续执行任务的测试"}
if __name__ == "__main__":
import json
self_test()
print(json.dumps(run_demo(),ensure_ascii=False,indent=2))
运行结果示例
以下结果由随包脚本产生。它们不是LLM或产品性能数据。
{
"性质": "人工标注命题上的确定性校验,不会自动判断自然语言",
"基准": {
"public_api": {
"value": "unchanged",
"certainty": "required",
"version": "all"
},
"config_loaded": {
"value": true,
"certainty": "verified",
"evidence": "T1"
},
"path_cause": {
"value": "base_mismatch",
"certainty": "hypothesis",
"evidence": null
},
"patch": {
"value": "not_applied",
"certainty": "observed",
"version": "v3"
},
"tests": {
"value": "pending",
"certainty": "observed",
"version": "v3"
}
},
"错误压缩": {
"config_loaded": {
"value": true,
"certainty": "verified",
"evidence": "T1"
},
"path_cause": {
"value": "base_mismatch",
"certainty": "verified",
"evidence": null
},
"patch": {
"value": "applied",
"certainty": "observed",
"version": "v3"
},
"tests": {
"value": "passed",
"certainty": "observed",
"version": "v2"
}
},
"差异": {
"preserved": false,
"missing": [
"public_api"
],
"extra": [],
"changed": [
{
"claim": "patch",
"field": "value",
"expected": "not_applied",
"actual": "applied"
},
{
"claim": "path_cause",
"field": "certainty",
"expected": "hypothesis",
"actual": "verified"
},
{
"claim": "tests",
"field": "value",
"expected": "pending",
"actual": "passed"
},
{
"claim": "tests",
"field": "version",
"expected": "v3",
"actual": "v2"
}
]
},
"限制": "真实压缩仍需人工/模型抽取校准,以及继续执行任务的测试"
}