功能:回合结束自动压缩——In token 超阈值自动执行一次摘要压缩(agent.auto_compress_tokens,默认 60k,0=关)
- config.js:agent 默认段新增 auto_compress_tokens: 60000(deepMerge 保留用户覆盖值含 0;无热重载,改后重启生效,同其他 agent 参数) - engine.js:runLoopInner 各模型轮记录 run.turnMaxPt(prompt_tokens 峰值,工具迭代只会越滚越大);runLoop finally(循环完全停止 + finalize 之后)调 maybeAutoCompress——AI↔tools 交互途中绝不触发 - maybeAutoCompress 护栏:压缩回合自身不复查(防递归);取消/异常收尾/非 held 状态不触发;先发 auto_compress SSE 事件再启动压缩(同连接事件有序,早于任何流式帧) - 前端:设置页「Agent 会话」组新增「自动压缩 In 阈值(0=关)」int 项;auto_compress 监听复用手动摘要链路(pendingSummary + 摘要卡片 + 旧消息淡出存档)并 toast 提示
This commit is contained in:
@@ -1741,6 +1741,14 @@
|
||||
fillToolResult(d.tool_call_id, d.content, d.is_error, d.image_url, d.msg_id);
|
||||
maybeAutoScroll();
|
||||
});
|
||||
// 后端回合结束后自动压缩触发:挂上与手动「摘要」同一套收尾链路(摘要卡片 + 旧消息淡出存档)
|
||||
es.addEventListener('auto_compress', ev => {
|
||||
const d = JSON.parse(ev.data);
|
||||
state.pendingSummary = true;
|
||||
const btn = $('compress-btn');
|
||||
if (btn) btn.disabled = true;
|
||||
toast('本轮 In ' + fmtTok(d.prompt_tokens) + ' 超过阈值 ' + fmtTok(d.threshold) + ',自动压缩上下文中…');
|
||||
});
|
||||
es.addEventListener('done', ev => {
|
||||
removeTyping(); // 本轮结束,占位亦终止(如模型报错无回复)
|
||||
// 压缩回合异常结束的兜底(模型报错回合直接 break / 被终止 → 不会有带 is_summary 的最终消息):
|
||||
@@ -3242,6 +3250,7 @@
|
||||
{ path: 'agent.max_tool_iterations', label: '单会话最大工具轮次', type: 'int' },
|
||||
{ path: 'agent.max_retries', label: '上游失败重试次数', type: 'int' },
|
||||
{ path: 'agent.language', label: '回复语言(留空不限)', type: 'text' },
|
||||
{ path: 'agent.auto_compress_tokens', label: '自动压缩 In 阈值(0=关)', type: 'int' },
|
||||
] },
|
||||
{ group: '终端工具', items: [
|
||||
{ path: 'terminal.default_timeout_ms', label: '命令默认超时(ms)', type: 'int' },
|
||||
|
||||
Reference in New Issue
Block a user