feat: 长程任务稳定性改造,支持50+轮次执行
P0: 取消80%上下文使用率硬性限制3轮,改为触发紧急压缩; P0: compressWithLLM预处理截断500→2000字符; P0: handleThinking API异常重试机制(2次指数退避); P1: 增量压缩改为按token使用率30%触发而非消息条数; P1: COMPRESS_KEEP_HEAD/TAIL从2/2调整为5/8; P1: 看门狗从30分钟延长到60分钟; P1: 流式超时改为动态计算(120s+0.5s/1K tokens,上限10分钟); P1: buildContext windowSize从20调整为40; P2: smartTruncate改为token感知,仅在压力>50%时触发; P2: 工具消息硬限制从40条改为token感知(80条/压力大40条); P2: 移除60%软收敛催促(避免误导模型提前结束); AUTO_COMPRESS_THRESHOLD从0.5调整为0.3
This commit is contained in:
@@ -65,11 +65,11 @@ export function getTokenCalibration(): { ratio: number; samples: number } {
|
||||
}
|
||||
|
||||
/** 自动压缩阈值:当消息 token 占 context window 比例超过此值时触发自动压缩 */
|
||||
export const AUTO_COMPRESS_THRESHOLD = 0.5;
|
||||
export const AUTO_COMPRESS_THRESHOLD = 0.3;
|
||||
|
||||
/** 压缩后保留首尾消息数 */
|
||||
const COMPRESS_KEEP_HEAD = 2;
|
||||
const COMPRESS_KEEP_TAIL = 2;
|
||||
const COMPRESS_KEEP_HEAD = 5;
|
||||
const COMPRESS_KEEP_TAIL = 8;
|
||||
|
||||
// ── 消息重要性评分(纯规则,不调用 LLM)──
|
||||
|
||||
@@ -143,8 +143,8 @@ export interface ContextBuildOptions {
|
||||
}
|
||||
|
||||
const DEFAULT_OPTIONS: Required<ContextBuildOptions> = {
|
||||
windowSize: 20,
|
||||
summaryBatchSize: 20,
|
||||
windowSize: 40,
|
||||
summaryBatchSize: 30,
|
||||
maxTokens: 131072,
|
||||
memoryContext: '',
|
||||
workspaceContext: ''
|
||||
@@ -309,7 +309,7 @@ export async function compressWithLLM(
|
||||
const conversationText = uncompressedMiddle.map(m => {
|
||||
const role = m.role === 'user' ? '用户' : 'AI';
|
||||
let content = m.content || '';
|
||||
if (content.length > 500) content = content.slice(0, 500) + '...';
|
||||
if (content.length > 2000) content = content.slice(0, 2000) + '...';
|
||||
if (m.tool_calls?.length) {
|
||||
const toolNames = m.tool_calls.map(t => t.function.name).join(', ');
|
||||
content += ` [工具调用: ${toolNames}]`;
|
||||
|
||||
Reference in New Issue
Block a user