mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
refactor(core): Unified context management settings schema (#24391)
This commit is contained in:
+10
-11
@@ -157,17 +157,16 @@ they appear in the UI.
|
||||
|
||||
### Experimental
|
||||
|
||||
| UI Label | Setting | Description | Default |
|
||||
| -------------------------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
|
||||
| Enable Tool Output Masking | `experimental.toolOutputMasking.enabled` | Enables tool output masking to save tokens. | `true` |
|
||||
| Enable Git Worktrees | `experimental.worktrees` | Enable automated Git worktree management for parallel work. | `false` |
|
||||
| Use OSC 52 Paste | `experimental.useOSC52Paste` | Use OSC 52 for pasting. This may be more robust than the default system when using remote terminal sessions (if your terminal is configured to allow it). | `false` |
|
||||
| Use OSC 52 Copy | `experimental.useOSC52Copy` | Use OSC 52 for copying. This may be more robust than the default system when using remote terminal sessions (if your terminal is configured to allow it). | `false` |
|
||||
| Model Steering | `experimental.modelSteering` | Enable model steering (user hints) to guide the model during tool execution. | `false` |
|
||||
| Direct Web Fetch | `experimental.directWebFetch` | Enable web fetch behavior that bypasses LLM summarization. | `false` |
|
||||
| Memory Manager Agent | `experimental.memoryManager` | Replace the built-in save_memory tool with a memory manager subagent that supports adding, removing, de-duplicating, and organizing memories. | `false` |
|
||||
| Enable Context Management | `experimental.contextManagement` | Enable logic for context management. | `false` |
|
||||
| Topic & Update Narration | `experimental.topicUpdateNarration` | Enable the experimental Topic & Update communication model for reduced chattiness and structured progress reporting. | `false` |
|
||||
| UI Label | Setting | Description | Default |
|
||||
| ------------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
|
||||
| Enable Git Worktrees | `experimental.worktrees` | Enable automated Git worktree management for parallel work. | `false` |
|
||||
| Use OSC 52 Paste | `experimental.useOSC52Paste` | Use OSC 52 for pasting. This may be more robust than the default system when using remote terminal sessions (if your terminal is configured to allow it). | `false` |
|
||||
| Use OSC 52 Copy | `experimental.useOSC52Copy` | Use OSC 52 for copying. This may be more robust than the default system when using remote terminal sessions (if your terminal is configured to allow it). | `false` |
|
||||
| Model Steering | `experimental.modelSteering` | Enable model steering (user hints) to guide the model during tool execution. | `false` |
|
||||
| Direct Web Fetch | `experimental.directWebFetch` | Enable web fetch behavior that bypasses LLM summarization. | `false` |
|
||||
| Memory Manager Agent | `experimental.memoryManager` | Replace the built-in save_memory tool with a memory manager subagent that supports adding, removing, de-duplicating, and organizing memories. | `false` |
|
||||
| Enable Context Management | `experimental.contextManagement` | Enable logic for context management. | `false` |
|
||||
| Topic & Update Narration | `experimental.topicUpdateNarration` | Enable the experimental Topic & Update communication model for reduced chattiness and structured progress reporting. | `false` |
|
||||
|
||||
### Skills
|
||||
|
||||
|
||||
@@ -1587,28 +1587,6 @@ their corresponding top-level category object in your `settings.json` file.
|
||||
|
||||
#### `experimental`
|
||||
|
||||
- **`experimental.toolOutputMasking.enabled`** (boolean):
|
||||
- **Description:** Enables tool output masking to save tokens.
|
||||
- **Default:** `true`
|
||||
- **Requires restart:** Yes
|
||||
|
||||
- **`experimental.toolOutputMasking.toolProtectionThreshold`** (number):
|
||||
- **Description:** Minimum number of tokens to protect from masking (most
|
||||
recent tool outputs).
|
||||
- **Default:** `50000`
|
||||
- **Requires restart:** Yes
|
||||
|
||||
- **`experimental.toolOutputMasking.minPrunableTokensThreshold`** (number):
|
||||
- **Description:** Minimum prunable tokens required to trigger a masking pass.
|
||||
- **Default:** `30000`
|
||||
- **Requires restart:** Yes
|
||||
|
||||
- **`experimental.toolOutputMasking.protectLatestTurn`** (boolean):
|
||||
- **Description:** Ensures the absolute latest turn is never masked,
|
||||
regardless of token count.
|
||||
- **Default:** `true`
|
||||
- **Requires restart:** Yes
|
||||
|
||||
- **`experimental.enableAgents`** (boolean):
|
||||
- **Description:** Enable local and remote subagents.
|
||||
- **Default:** `true`
|
||||
@@ -1834,18 +1812,38 @@ their corresponding top-level category object in your `settings.json` file.
|
||||
- **Default:** `0.25`
|
||||
- **Requires restart:** Yes
|
||||
|
||||
- **`contextManagement.toolDistillation.maxOutputTokens`** (number):
|
||||
- **Description:** Maximum tokens to show when truncating large tool outputs.
|
||||
- **`contextManagement.tools.distillation.maxOutputTokens`** (number):
|
||||
- **Description:** Maximum tokens to show to the model when truncating large
|
||||
tool outputs.
|
||||
- **Default:** `10000`
|
||||
- **Requires restart:** Yes
|
||||
|
||||
- **`contextManagement.toolDistillation.summarizationThresholdTokens`**
|
||||
- **`contextManagement.tools.distillation.summarizationThresholdTokens`**
|
||||
(number):
|
||||
- **Description:** Threshold above which truncated tool outputs will be
|
||||
summarized by an LLM.
|
||||
- **Default:** `20000`
|
||||
- **Requires restart:** Yes
|
||||
|
||||
- **`contextManagement.tools.outputMasking.protectionThresholdTokens`**
|
||||
(number):
|
||||
- **Description:** Minimum number of tokens to protect from masking (most
|
||||
recent tool outputs).
|
||||
- **Default:** `50000`
|
||||
- **Requires restart:** Yes
|
||||
|
||||
- **`contextManagement.tools.outputMasking.minPrunableThresholdTokens`**
|
||||
(number):
|
||||
- **Description:** Minimum prunable tokens required to trigger a masking pass.
|
||||
- **Default:** `30000`
|
||||
- **Requires restart:** Yes
|
||||
|
||||
- **`contextManagement.tools.outputMasking.protectLatestTurn`** (boolean):
|
||||
- **Description:** Ensures the absolute latest turn is never masked,
|
||||
regardless of token count.
|
||||
- **Default:** `true`
|
||||
- **Requires restart:** Yes
|
||||
|
||||
#### `admin`
|
||||
|
||||
- **`admin.secureModeEnabled`** (boolean):
|
||||
|
||||
@@ -983,7 +983,6 @@ export async function loadCliConfig(
|
||||
},
|
||||
modelSteering: settings.experimental?.modelSteering,
|
||||
topicUpdateNarration: settings.experimental?.topicUpdateNarration,
|
||||
toolOutputMasking: settings.experimental?.toolOutputMasking,
|
||||
noBrowser: !!process.env['NO_BROWSER'],
|
||||
summarizeToolOutput: settings.model?.summarizeToolOutput,
|
||||
ideMode,
|
||||
|
||||
@@ -1933,58 +1933,6 @@ const SETTINGS_SCHEMA = {
|
||||
description: 'Setting to enable experimental features',
|
||||
showInDialog: false,
|
||||
properties: {
|
||||
toolOutputMasking: {
|
||||
type: 'object',
|
||||
label: 'Tool Output Masking',
|
||||
category: 'Experimental',
|
||||
requiresRestart: true,
|
||||
ignoreInDocs: false,
|
||||
default: {},
|
||||
description:
|
||||
'Advanced settings for tool output masking to manage context window efficiency.',
|
||||
showInDialog: false,
|
||||
properties: {
|
||||
enabled: {
|
||||
type: 'boolean',
|
||||
label: 'Enable Tool Output Masking',
|
||||
category: 'Experimental',
|
||||
requiresRestart: true,
|
||||
default: true,
|
||||
description: 'Enables tool output masking to save tokens.',
|
||||
showInDialog: true,
|
||||
},
|
||||
toolProtectionThreshold: {
|
||||
type: 'number',
|
||||
label: 'Tool Protection Threshold',
|
||||
category: 'Experimental',
|
||||
requiresRestart: true,
|
||||
default: 50000,
|
||||
description:
|
||||
'Minimum number of tokens to protect from masking (most recent tool outputs).',
|
||||
showInDialog: false,
|
||||
},
|
||||
minPrunableTokensThreshold: {
|
||||
type: 'number',
|
||||
label: 'Min Prunable Tokens Threshold',
|
||||
category: 'Experimental',
|
||||
requiresRestart: true,
|
||||
default: 30000,
|
||||
description:
|
||||
'Minimum prunable tokens required to trigger a masking pass.',
|
||||
showInDialog: false,
|
||||
},
|
||||
protectLatestTurn: {
|
||||
type: 'boolean',
|
||||
label: 'Protect Latest Turn',
|
||||
category: 'Experimental',
|
||||
requiresRestart: true,
|
||||
default: true,
|
||||
description:
|
||||
'Ensures the absolute latest turn is never masked, regardless of token count.',
|
||||
showInDialog: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
enableAgents: {
|
||||
type: 'boolean',
|
||||
label: 'Enable Agents',
|
||||
@@ -2544,33 +2492,86 @@ const SETTINGS_SCHEMA = {
|
||||
},
|
||||
},
|
||||
},
|
||||
toolDistillation: {
|
||||
tools: {
|
||||
type: 'object',
|
||||
label: 'Tool Distillation',
|
||||
label: 'Context Management Tools',
|
||||
category: 'Context Management',
|
||||
requiresRestart: true,
|
||||
default: {},
|
||||
showInDialog: false,
|
||||
properties: {
|
||||
maxOutputTokens: {
|
||||
type: 'number',
|
||||
label: 'Max Output Tokens',
|
||||
distillation: {
|
||||
type: 'object',
|
||||
label: 'Tool Distillation',
|
||||
category: 'Context Management',
|
||||
requiresRestart: true,
|
||||
default: 10_000,
|
||||
description:
|
||||
'Maximum tokens to show when truncating large tool outputs.',
|
||||
default: {},
|
||||
showInDialog: false,
|
||||
properties: {
|
||||
maxOutputTokens: {
|
||||
type: 'number',
|
||||
label: 'Max Output Tokens',
|
||||
category: 'Context Management',
|
||||
requiresRestart: true,
|
||||
default: 10_000,
|
||||
description:
|
||||
'Maximum tokens to show to the model when truncating large tool outputs.',
|
||||
showInDialog: false,
|
||||
},
|
||||
summarizationThresholdTokens: {
|
||||
type: 'number',
|
||||
label: 'Tool Summarization Threshold',
|
||||
category: 'Context Management',
|
||||
requiresRestart: true,
|
||||
default: 20_000,
|
||||
description:
|
||||
'Threshold above which truncated tool outputs will be summarized by an LLM.',
|
||||
showInDialog: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
summarizationThresholdTokens: {
|
||||
type: 'number',
|
||||
label: 'Tool Summarization Threshold',
|
||||
outputMasking: {
|
||||
type: 'object',
|
||||
label: 'Tool Output Masking',
|
||||
category: 'Context Management',
|
||||
requiresRestart: true,
|
||||
default: 20_000,
|
||||
ignoreInDocs: false,
|
||||
default: {},
|
||||
description:
|
||||
'Threshold above which truncated tool outputs will be summarized by an LLM.',
|
||||
'Advanced settings for tool output masking to manage context window efficiency.',
|
||||
showInDialog: false,
|
||||
properties: {
|
||||
protectionThresholdTokens: {
|
||||
type: 'number',
|
||||
label: 'Tool Protection Threshold (Tokens)',
|
||||
category: 'Context Management',
|
||||
requiresRestart: true,
|
||||
default: 50_000,
|
||||
description:
|
||||
'Minimum number of tokens to protect from masking (most recent tool outputs).',
|
||||
showInDialog: false,
|
||||
},
|
||||
minPrunableThresholdTokens: {
|
||||
type: 'number',
|
||||
label: 'Min Prunable Tokens Threshold',
|
||||
category: 'Context Management',
|
||||
requiresRestart: true,
|
||||
default: 30_000,
|
||||
description:
|
||||
'Minimum prunable tokens required to trigger a masking pass.',
|
||||
showInDialog: false,
|
||||
},
|
||||
protectLatestTurn: {
|
||||
type: 'boolean',
|
||||
label: 'Protect Latest Turn',
|
||||
category: 'Context Management',
|
||||
requiresRestart: true,
|
||||
default: true,
|
||||
description:
|
||||
'Ensures the absolute latest turn is never masked, regardless of token count.',
|
||||
showInDialog: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -45,11 +45,10 @@ describe('ToolOutputMaskingService', () => {
|
||||
},
|
||||
getSessionId: () => 'mock-session',
|
||||
getUsageStatisticsEnabled: () => false,
|
||||
getToolOutputMaskingEnabled: () => true,
|
||||
getToolOutputMaskingConfig: async () => ({
|
||||
enabled: true,
|
||||
toolProtectionThreshold: 50000,
|
||||
minPrunableTokensThreshold: 30000,
|
||||
protectionThresholdTokens: 50000,
|
||||
minPrunableThresholdTokens: 30000,
|
||||
protectLatestTurn: true,
|
||||
}),
|
||||
} as unknown as Config;
|
||||
@@ -66,8 +65,8 @@ describe('ToolOutputMaskingService', () => {
|
||||
it('should respect remote configuration overrides', async () => {
|
||||
mockConfig.getToolOutputMaskingConfig = async () => ({
|
||||
enabled: true,
|
||||
toolProtectionThreshold: 100, // Very low threshold
|
||||
minPrunableTokensThreshold: 50,
|
||||
protectionThresholdTokens: 100, // Very low threshold
|
||||
minPrunableThresholdTokens: 50,
|
||||
protectLatestTurn: false,
|
||||
});
|
||||
|
||||
|
||||
@@ -53,13 +53,13 @@ export interface MaskingResult {
|
||||
*
|
||||
* It implements a "Hybrid Backward Scanned FIFO" algorithm to balance context relevance with
|
||||
* token savings:
|
||||
* 1. **Protection Window**: Protects the newest `toolProtectionThreshold` (default 50k) tool tokens
|
||||
* 1. **Protection Window**: Protects the newest `protectionThresholdTokens` (default 50k) tool tokens
|
||||
* from pruning. Optionally skips the entire latest conversation turn to ensure full context for
|
||||
* the model's next response.
|
||||
* 2. **Global Aggregation**: Scans backwards past the protection window to identify all remaining
|
||||
* tool outputs that haven't been masked yet.
|
||||
* 3. **Batch Trigger**: Trigger masking only if the total prunable tokens exceed
|
||||
* `minPrunableTokensThreshold` (default 30k).
|
||||
* `minPrunableThresholdTokens` (default 30k).
|
||||
*
|
||||
* @remarks
|
||||
* Effectively, this means masking only starts once the conversation contains approximately 80k
|
||||
@@ -71,11 +71,11 @@ export class ToolOutputMaskingService {
|
||||
history: readonly Content[],
|
||||
config: Config,
|
||||
): Promise<MaskingResult> {
|
||||
const maskingConfig = await config.getToolOutputMaskingConfig();
|
||||
if (!maskingConfig.enabled || history.length === 0) {
|
||||
if (history.length === 0) {
|
||||
return { newHistory: history, maskedCount: 0, tokensSaved: 0 };
|
||||
}
|
||||
|
||||
const maskingConfig = await config.getToolOutputMaskingConfig();
|
||||
let cumulativeToolTokens = 0;
|
||||
let protectionBoundaryReached = false;
|
||||
let totalPrunableTokens = 0;
|
||||
@@ -124,7 +124,7 @@ export class ToolOutputMaskingService {
|
||||
|
||||
if (!protectionBoundaryReached) {
|
||||
cumulativeToolTokens += partTokens;
|
||||
if (cumulativeToolTokens > maskingConfig.toolProtectionThreshold) {
|
||||
if (cumulativeToolTokens > maskingConfig.protectionThresholdTokens) {
|
||||
protectionBoundaryReached = true;
|
||||
// The part that crossed the boundary is prunable.
|
||||
totalPrunableTokens += partTokens;
|
||||
@@ -151,12 +151,12 @@ export class ToolOutputMaskingService {
|
||||
|
||||
// Trigger pruning only if we have accumulated enough savings to justify the
|
||||
// overhead of masking and file I/O (batch pruning threshold).
|
||||
if (totalPrunableTokens < maskingConfig.minPrunableTokensThreshold) {
|
||||
if (totalPrunableTokens < maskingConfig.minPrunableThresholdTokens) {
|
||||
return { newHistory: history, maskedCount: 0, tokensSaved: 0 };
|
||||
}
|
||||
|
||||
debugLogger.debug(
|
||||
`[ToolOutputMasking] Triggering masking. Prunable tool tokens: ${totalPrunableTokens.toLocaleString()} (> ${maskingConfig.minPrunableTokensThreshold.toLocaleString()})`,
|
||||
`[ToolOutputMasking] Triggering masking. Prunable tool tokens: ${totalPrunableTokens.toLocaleString()} (> ${maskingConfig.minPrunableThresholdTokens.toLocaleString()})`,
|
||||
);
|
||||
|
||||
// Perform masking and offloading
|
||||
|
||||
@@ -220,8 +220,12 @@ describe('Gemini Client (client.ts)', () => {
|
||||
getSessionMemory: vi.fn().mockReturnValue(''),
|
||||
isJitContextEnabled: vi.fn().mockReturnValue(false),
|
||||
getContextManager: vi.fn().mockReturnValue(undefined),
|
||||
getToolOutputMaskingEnabled: vi.fn().mockReturnValue(false),
|
||||
getDisableLoopDetection: vi.fn().mockReturnValue(false),
|
||||
getToolOutputMaskingConfig: vi.fn().mockReturnValue({
|
||||
protectionThresholdTokens: 50000,
|
||||
minPrunableThresholdTokens: 30000,
|
||||
protectLatestTurn: true,
|
||||
}),
|
||||
|
||||
getSessionId: vi.fn().mockReturnValue('test-session-id'),
|
||||
getProxy: vi.fn().mockReturnValue(undefined),
|
||||
|
||||
@@ -1231,9 +1231,6 @@ export class GeminiClient {
|
||||
* Masks bulky tool outputs to save context window space.
|
||||
*/
|
||||
private async tryMaskToolOutputs(history: readonly Content[]): Promise<void> {
|
||||
if (!this.config.getToolOutputMaskingEnabled()) {
|
||||
return;
|
||||
}
|
||||
const result = await this.toolOutputMaskingService.mask(
|
||||
history,
|
||||
this.config,
|
||||
|
||||
@@ -2748,44 +2748,6 @@
|
||||
"default": {},
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"toolOutputMasking": {
|
||||
"title": "Tool Output Masking",
|
||||
"description": "Advanced settings for tool output masking to manage context window efficiency.",
|
||||
"markdownDescription": "Advanced settings for tool output masking to manage context window efficiency.\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `{}`",
|
||||
"default": {},
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"enabled": {
|
||||
"title": "Enable Tool Output Masking",
|
||||
"description": "Enables tool output masking to save tokens.",
|
||||
"markdownDescription": "Enables tool output masking to save tokens.\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `true`",
|
||||
"default": true,
|
||||
"type": "boolean"
|
||||
},
|
||||
"toolProtectionThreshold": {
|
||||
"title": "Tool Protection Threshold",
|
||||
"description": "Minimum number of tokens to protect from masking (most recent tool outputs).",
|
||||
"markdownDescription": "Minimum number of tokens to protect from masking (most recent tool outputs).\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `50000`",
|
||||
"default": 50000,
|
||||
"type": "number"
|
||||
},
|
||||
"minPrunableTokensThreshold": {
|
||||
"title": "Min Prunable Tokens Threshold",
|
||||
"description": "Minimum prunable tokens required to trigger a masking pass.",
|
||||
"markdownDescription": "Minimum prunable tokens required to trigger a masking pass.\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `30000`",
|
||||
"default": 30000,
|
||||
"type": "number"
|
||||
},
|
||||
"protectLatestTurn": {
|
||||
"title": "Protect Latest Turn",
|
||||
"description": "Ensures the absolute latest turn is never masked, regardless of token count.",
|
||||
"markdownDescription": "Ensures the absolute latest turn is never masked, regardless of token count.\n\n- Category: `Experimental`\n- Requires restart: `yes`\n- Default: `true`",
|
||||
"default": true,
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"enableAgents": {
|
||||
"title": "Enable Agents",
|
||||
"description": "Enable local and remote subagents.",
|
||||
@@ -3190,25 +3152,65 @@
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"toolDistillation": {
|
||||
"title": "Tool Distillation",
|
||||
"tools": {
|
||||
"title": "Context Management Tools",
|
||||
"markdownDescription": "Description not provided.\n\n- Category: `Context Management`\n- Requires restart: `yes`\n- Default: `{}`",
|
||||
"default": {},
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"maxOutputTokens": {
|
||||
"title": "Max Output Tokens",
|
||||
"description": "Maximum tokens to show when truncating large tool outputs.",
|
||||
"markdownDescription": "Maximum tokens to show when truncating large tool outputs.\n\n- Category: `Context Management`\n- Requires restart: `yes`\n- Default: `10000`",
|
||||
"default": 10000,
|
||||
"type": "number"
|
||||
"distillation": {
|
||||
"title": "Tool Distillation",
|
||||
"markdownDescription": "Description not provided.\n\n- Category: `Context Management`\n- Requires restart: `yes`\n- Default: `{}`",
|
||||
"default": {},
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"maxOutputTokens": {
|
||||
"title": "Max Output Tokens",
|
||||
"description": "Maximum tokens to show to the model when truncating large tool outputs.",
|
||||
"markdownDescription": "Maximum tokens to show to the model when truncating large tool outputs.\n\n- Category: `Context Management`\n- Requires restart: `yes`\n- Default: `10000`",
|
||||
"default": 10000,
|
||||
"type": "number"
|
||||
},
|
||||
"summarizationThresholdTokens": {
|
||||
"title": "Tool Summarization Threshold",
|
||||
"description": "Threshold above which truncated tool outputs will be summarized by an LLM.",
|
||||
"markdownDescription": "Threshold above which truncated tool outputs will be summarized by an LLM.\n\n- Category: `Context Management`\n- Requires restart: `yes`\n- Default: `20000`",
|
||||
"default": 20000,
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"summarizationThresholdTokens": {
|
||||
"title": "Tool Summarization Threshold",
|
||||
"description": "Threshold above which truncated tool outputs will be summarized by an LLM.",
|
||||
"markdownDescription": "Threshold above which truncated tool outputs will be summarized by an LLM.\n\n- Category: `Context Management`\n- Requires restart: `yes`\n- Default: `20000`",
|
||||
"default": 20000,
|
||||
"type": "number"
|
||||
"outputMasking": {
|
||||
"title": "Tool Output Masking",
|
||||
"description": "Advanced settings for tool output masking to manage context window efficiency.",
|
||||
"markdownDescription": "Advanced settings for tool output masking to manage context window efficiency.\n\n- Category: `Context Management`\n- Requires restart: `yes`\n- Default: `{}`",
|
||||
"default": {},
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"protectionThresholdTokens": {
|
||||
"title": "Tool Protection Threshold (Tokens)",
|
||||
"description": "Minimum number of tokens to protect from masking (most recent tool outputs).",
|
||||
"markdownDescription": "Minimum number of tokens to protect from masking (most recent tool outputs).\n\n- Category: `Context Management`\n- Requires restart: `yes`\n- Default: `50000`",
|
||||
"default": 50000,
|
||||
"type": "number"
|
||||
},
|
||||
"minPrunableThresholdTokens": {
|
||||
"title": "Min Prunable Tokens Threshold",
|
||||
"description": "Minimum prunable tokens required to trigger a masking pass.",
|
||||
"markdownDescription": "Minimum prunable tokens required to trigger a masking pass.\n\n- Category: `Context Management`\n- Requires restart: `yes`\n- Default: `30000`",
|
||||
"default": 30000,
|
||||
"type": "number"
|
||||
},
|
||||
"protectLatestTurn": {
|
||||
"title": "Protect Latest Turn",
|
||||
"description": "Ensures the absolute latest turn is never masked, regardless of token count.",
|
||||
"markdownDescription": "Ensures the absolute latest turn is never masked, regardless of token count.\n\n- Category: `Context Management`\n- Requires restart: `yes`\n- Default: `true`",
|
||||
"default": true,
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
||||
Reference in New Issue
Block a user