fix: remove redundant length guard and fix compact type indentation

This commit is contained in:
JackChen 2026-04-16 23:34:28 +08:00
parent d21d4e035a
commit 60163ccf50
2 changed files with 13 additions and 13 deletions

View File

@ -879,7 +879,7 @@ export class AgentRunner {
strategy: Extract<ContextStrategy, { type: 'compact' }>,
): LLMMessage[] {
const estimated = estimateTokens(messages)
if (estimated <= strategy.maxTokens || messages.length < 4) {
if (estimated <= strategy.maxTokens) {
return messages
}

View File

@ -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: (