| 窗口 | 按轮数或 token 数定义(如最近 10 轮 / 4K token) |
|---|---|
| 常驻 | system 提示与任务目标不参与淘汰 |
| 淘汰 | 窗口外丢弃,或先压成摘要再丢 |
| 注意 | 工具结果(长回包)先折叠再进窗口 |
窗口裁剪(伪代码)
窗口裁剪(伪代码)
def build_messages(system, history, keep_turns=10, max_tokens=4000):
recent = history[-keep_turns:]
while count_tokens(system, recent) > max_tokens and recent:
recent.pop(0)
return [system] + recent硬截断前先折叠工具结果、去掉重复附件:很多“超长”是工具回包堆出来的。