feat(core): Unified Context Management and Tool Distillation. (#24157)

This commit is contained in:
joshualitt
2026-03-30 15:29:59 -07:00
committed by GitHub
parent 117a2d3844
commit dfba0e91e2
22 changed files with 1717 additions and 314 deletions
@@ -75,6 +75,7 @@ function createMockConfig(overrides: Partial<Config> = {}): Config {
({
check: async () => ({ decision: 'allow' }),
}) as unknown as PolicyEngine,
isAutoDistillationEnabled: () => false,
} as unknown as Config;
const mockConfig = Object.assign({}, baseConfig, overrides) as Config;
@@ -75,6 +75,7 @@ describe('ToolExecutor', () => {
vi.mocked(fileUtils.formatTruncatedToolOutput).mockReturnValue(
'TruncatedContent...',
);
vi.spyOn(config, 'isAutoDistillationEnabled').mockReturnValue(false);
});
afterEach(() => {
@@ -19,6 +19,7 @@ import {
import { isAbortError } from '../utils/errors.js';
import { SHELL_TOOL_NAME } from '../tools/tool-names.js';
import { DiscoveredMCPTool } from '../tools/mcp-tool.js';
import { ToolOutputDistillationService } from '../services/toolDistillationService.js';
import { executeToolWithHooks } from '../core/coreToolHookTriggers.js';
import {
saveTruncatedToolOutput,
@@ -196,6 +197,15 @@ export class ToolExecutor {
call: ToolCall,
content: PartListUnion,
): Promise<{ truncatedContent: PartListUnion; outputFile?: string }> {
if (this.config.isAutoDistillationEnabled()) {
const distiller = new ToolOutputDistillationService(
this.config,
this.context.geminiClient,
this.context.promptId,
);
return distiller.distill(call.request.name, call.request.callId, content);
}
const toolName = call.request.name;
const callId = call.request.callId;
let outputFile: string | undefined;