refactor(core): Unified context management settings schema (#24391)

This commit is contained in:
joshualitt
2026-04-01 10:24:45 -07:00
committed by GitHub
parent f9585a43b2
commit 25934cf52b
10 changed files with 215 additions and 212 deletions
+46 -42
View File
@@ -206,6 +206,12 @@ export interface OutputSettings {
format?: OutputFormat;
}
export interface ToolOutputMaskingConfig {
protectionThresholdTokens: number;
minPrunableThresholdTokens: number;
protectLatestTurn: boolean;
}
export interface ContextManagementConfig {
enabled: boolean;
historyWindow: {
@@ -217,19 +223,15 @@ export interface ContextManagementConfig {
retainedMaxTokens: number;
normalizationHeadRatio: number;
};
toolDistillation: {
maxOutputTokens: number;
summarizationThresholdTokens: number;
tools: {
distillation: {
maxOutputTokens: number;
summarizationThresholdTokens: number;
};
outputMasking: ToolOutputMaskingConfig;
};
}
export interface ToolOutputMaskingConfig {
enabled: boolean;
toolProtectionThreshold: number;
minPrunableTokensThreshold: number;
protectLatestTurn: boolean;
}
export interface GemmaModelRouterSettings {
enabled?: boolean;
classifier?: {
@@ -711,7 +713,7 @@ export interface ConfigParameters {
experimentalAgentHistorySummarization?: boolean;
memoryBoundaryMarkers?: string[];
topicUpdateNarration?: boolean;
toolOutputMasking?: Partial<ToolOutputMaskingConfig>;
disableLLMCorrection?: boolean;
plan?: boolean;
tracker?: boolean;
@@ -913,7 +915,7 @@ export class Config implements McpContext, AgentLoopContext {
private pendingIncludeDirectories: string[];
private readonly enableHooks: boolean;
private readonly enableHooksUI: boolean;
private readonly toolOutputMasking: ToolOutputMaskingConfig;
private hooks: { [K in HookEventName]?: HookDefinition[] } | undefined;
private projectHooks:
| ({ [K in HookEventName]?: HookDefinition[] } & { disabled?: string[] })
@@ -1162,12 +1164,27 @@ export class Config implements McpContext, AgentLoopContext {
params.contextManagement?.messageLimits?.normalizationHeadRatio ??
0.25,
},
toolDistillation: {
maxOutputTokens:
params.contextManagement?.toolDistillation?.maxOutputTokens ?? 10000,
summarizationThresholdTokens:
params.contextManagement?.toolDistillation
?.summarizationThresholdTokens ?? 20000,
tools: {
distillation: {
maxOutputTokens:
params.contextManagement?.tools?.distillation?.maxOutputTokens ??
10000,
summarizationThresholdTokens:
params.contextManagement?.tools?.distillation
?.summarizationThresholdTokens ?? 20000,
},
outputMasking: {
protectionThresholdTokens:
params.contextManagement?.tools?.outputMasking
?.protectionThresholdTokens ?? DEFAULT_TOOL_PROTECTION_THRESHOLD,
minPrunableThresholdTokens:
params.contextManagement?.tools?.outputMasking
?.minPrunableThresholdTokens ??
DEFAULT_MIN_PRUNABLE_TOKENS_THRESHOLD,
protectLatestTurn:
params.contextManagement?.tools?.outputMasking?.protectLatestTurn ??
DEFAULT_PROTECT_LATEST_TURN,
},
},
};
this.topicUpdateNarration = params.topicUpdateNarration ?? false;
@@ -1176,18 +1193,6 @@ export class Config implements McpContext, AgentLoopContext {
this.isModelSteeringEnabled(),
);
ExecutionLifecycleService.setInjectionService(this.injectionService);
this.toolOutputMasking = {
enabled: params.toolOutputMasking?.enabled ?? true,
toolProtectionThreshold:
params.toolOutputMasking?.toolProtectionThreshold ??
DEFAULT_TOOL_PROTECTION_THRESHOLD,
minPrunableTokensThreshold:
params.toolOutputMasking?.minPrunableTokensThreshold ??
DEFAULT_MIN_PRUNABLE_TOKENS_THRESHOLD,
protectLatestTurn:
params.toolOutputMasking?.protectLatestTurn ??
DEFAULT_PROTECT_LATEST_TURN,
};
this.maxSessionTurns = params.maxSessionTurns ?? -1;
this.acpMode = params.acpMode ?? false;
this.listSessions = params.listSessions ?? false;
@@ -2415,10 +2420,6 @@ export class Config implements McpContext, AgentLoopContext {
return this.modelSteering;
}
getToolOutputMaskingEnabled(): boolean {
return this.toolOutputMasking.enabled;
}
async getToolOutputMaskingConfig(): Promise<ToolOutputMaskingConfig> {
await this.ensureExperimentsLoaded();
@@ -2440,17 +2441,19 @@ export class Config implements McpContext, AgentLoopContext {
: undefined;
return {
enabled: this.toolOutputMasking.enabled,
toolProtectionThreshold:
protectionThresholdTokens:
parsedProtection !== undefined && !isNaN(parsedProtection)
? parsedProtection
: this.toolOutputMasking.toolProtectionThreshold,
minPrunableTokensThreshold:
: this.contextManagement.tools.outputMasking
.protectionThresholdTokens,
minPrunableThresholdTokens:
parsedPrunable !== undefined && !isNaN(parsedPrunable)
? parsedPrunable
: this.toolOutputMasking.minPrunableTokensThreshold,
: this.contextManagement.tools.outputMasking
.minPrunableThresholdTokens,
protectLatestTurn:
remoteProtectLatest ?? this.toolOutputMasking.protectLatestTurn,
remoteProtectLatest ??
this.contextManagement.tools.outputMasking.protectLatestTurn,
};
}
@@ -3301,11 +3304,12 @@ export class Config implements McpContext, AgentLoopContext {
}
getToolMaxOutputTokens(): number {
return this.contextManagement.toolDistillation.maxOutputTokens;
return this.contextManagement.tools.distillation.maxOutputTokens;
}
getToolSummarizationThresholdTokens(): number {
return this.contextManagement.toolDistillation.summarizationThresholdTokens;
return this.contextManagement.tools.distillation
.summarizationThresholdTokens;
}
getNextCompressionTruncationId(): number {