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' }>, strategy: Extract<ContextStrategy, { type: 'compact' }>,
): LLMMessage[] { ): LLMMessage[] {
const estimated = estimateTokens(messages) const estimated = estimateTokens(messages)
if (estimated <= strategy.maxTokens || messages.length < 4) { if (estimated <= strategy.maxTokens) {
return messages return messages
} }

View File

@ -70,18 +70,18 @@ export type ContextStrategy =
| { type: 'sliding-window'; maxTurns: number } | { type: 'sliding-window'; maxTurns: number }
| { type: 'summarize'; maxTokens: number; summaryModel?: string } | { type: 'summarize'; maxTokens: number; summaryModel?: string }
| { | {
type: 'compact' type: 'compact'
/** Estimated token threshold that triggers compaction. Compaction is skipped when below this. */ /** Estimated token threshold that triggers compaction. Compaction is skipped when below this. */
maxTokens: number maxTokens: number
/** Number of recent turn pairs (assistant+user) to keep intact. Default: 4. */ /** Number of recent turn pairs (assistant+user) to keep intact. Default: 4. */
preserveRecentTurns?: number preserveRecentTurns?: number
/** Minimum chars in a tool_result content to qualify for compaction. Default: 200. */ /** Minimum chars in a tool_result content to qualify for compaction. Default: 200. */
minToolResultChars?: number minToolResultChars?: number
/** Minimum chars in an assistant text block to qualify for truncation. Default: 2000. */ /** Minimum chars in an assistant text block to qualify for truncation. Default: 2000. */
minTextBlockChars?: number minTextBlockChars?: number
/** Maximum chars to keep from a truncated text block (head excerpt). Default: 200. */ /** Maximum chars to keep from a truncated text block (head excerpt). Default: 200. */
textBlockExcerptChars?: number textBlockExcerptChars?: number
} }
| { | {
type: 'custom' type: 'custom'
compress: ( compress: (