Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/services/compact/compact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
getDeferredToolsDeltaAttachment,
getMcpInstructionsDeltaAttachment,
} from '../../utils/attachments.js'
import { getMemoryPath } from '../../utils/config.js'
import { getGlobalConfig, getMemoryPath } from '../../utils/config.js'
import { COMPACT_MAX_OUTPUT_TOKENS } from '../../utils/context.js'
import { createChildAbortController } from '../../utils/abortController.js'
import {
Expand Down Expand Up @@ -459,7 +459,11 @@ export async function compactConversation(
// The GB flag is kept as a kill-switch.
// streamCompactSummary() (below) follows the same gate; see also the
// provider-gate tests in src/services/compact/compact.test.ts.
const compactModel = getGlobalConfig().compactModel
const modelChangesForCompaction =
compactModel !== undefined && compactModel !== context.options.mainLoopModel
const promptCacheSharingEnabled =
!modelChangesForCompaction &&
isCompactionCacheSharingCompatible(context.options.mainLoopModel) &&
getFeatureValue_CACHED_MAY_BE_STALE(
'tengu_compact_cache_prefix',
Expand Down Expand Up @@ -1186,10 +1190,14 @@ async function streamCompactSummary({
// prompt cache; other 3P providers are incompatible and would send
// Anthropic-only params that they reject. The shared predicate makes this
// safe to call from 3P provider paths.
const compactModel = getGlobalConfig().compactModel
const modelChangesForCompaction =
compactModel !== undefined && compactModel !== context.options.mainLoopModel
const cacheSharingAvailable = isCompactionCacheSharingCompatible(
context.options.mainLoopModel,
)
const promptCacheSharingEnabled =
!modelChangesForCompaction &&
cacheSharingAvailable &&
getFeatureValue_CACHED_MAY_BE_STALE(
'tengu_compact_cache_prefix',
Expand Down Expand Up @@ -1402,13 +1410,13 @@ async function streamCompactSummary({
const appState = context.getAppState()
return appState.toolPermissionContext
},
model: context.options.mainLoopModel,
model: compactModel ?? context.options.mainLoopModel,
toolChoice: undefined,
isNonInteractiveSession: context.options.isNonInteractiveSession,
hasAppendSystemPrompt: !!context.options.appendSystemPrompt,
maxOutputTokensOverride: Math.min(
COMPACT_MAX_OUTPUT_TOKENS,
getMaxOutputTokensForModel(context.options.mainLoopModel),
getMaxOutputTokensForModel(compactModel ?? context.options.mainLoopModel),
),
querySource: 'compact',
agents: context.options.agentDefinitions.activeAgents,
Expand Down
5 changes: 5 additions & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,10 @@ export type GlobalConfig = {
// When enabled, triggers forced compaction if the message count exceeds the
// chosen threshold, regardless of token usage.
maxMessagesCompactionThreshold?: MaxMessagesCompactionThreshold

// Use a different (e.g. cheaper/faster) model for compaction.
// Defaults to mainLoopModel when unset.
compactModel?: string
}

/**
Expand Down Expand Up @@ -774,6 +778,7 @@ export const GLOBAL_CONFIG_KEYS = [
'knowledgeGraphEnabled',
'logoColor',
'maxMessagesCompactionThreshold',
'compactModel',
] as const

export type GlobalConfigKey = (typeof GLOBAL_CONFIG_KEYS)[number]
Expand Down