diff --git a/src/agent/runner.ts b/src/agent/runner.ts index fd8305d..92b482c 100644 --- a/src/agent/runner.ts +++ b/src/agent/runner.ts @@ -879,7 +879,7 @@ export class AgentRunner { strategy: Extract, ): LLMMessage[] { const estimated = estimateTokens(messages) - if (estimated <= strategy.maxTokens || messages.length < 4) { + if (estimated <= strategy.maxTokens) { return messages } diff --git a/src/types.ts b/src/types.ts index 765d9fe..e4f928b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -70,18 +70,18 @@ export type ContextStrategy = | { type: 'sliding-window'; maxTurns: number } | { type: 'summarize'; maxTokens: number; summaryModel?: string } | { - type: 'compact' - /** Estimated token threshold that triggers compaction. Compaction is skipped when below this. */ - maxTokens: number - /** Number of recent turn pairs (assistant+user) to keep intact. Default: 4. */ - preserveRecentTurns?: number - /** Minimum chars in a tool_result content to qualify for compaction. Default: 200. */ - minToolResultChars?: number - /** Minimum chars in an assistant text block to qualify for truncation. Default: 2000. */ - minTextBlockChars?: number - /** Maximum chars to keep from a truncated text block (head excerpt). Default: 200. */ - textBlockExcerptChars?: number - } + type: 'compact' + /** Estimated token threshold that triggers compaction. Compaction is skipped when below this. */ + maxTokens: number + /** Number of recent turn pairs (assistant+user) to keep intact. Default: 4. */ + preserveRecentTurns?: number + /** Minimum chars in a tool_result content to qualify for compaction. Default: 200. */ + minToolResultChars?: number + /** Minimum chars in an assistant text block to qualify for truncation. Default: 2000. */ + minTextBlockChars?: number + /** Maximum chars to keep from a truncated text block (head excerpt). Default: 200. */ + textBlockExcerptChars?: number + } | { type: 'custom' compress: (