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
+36
View File
@@ -293,6 +293,7 @@ describe('WebFetchTool', () => {
})),
},
isInteractive: () => false,
isAutoDistillationEnabled: vi.fn().mockReturnValue(false),
} as unknown as Config;
});
@@ -1118,5 +1119,40 @@ describe('WebFetchTool', () => {
);
expect(result.error?.type).toBe(ToolErrorType.WEB_FETCH_PROCESSING_ERROR);
});
it('should bypass truncation if isAutoDistillationEnabled is true', async () => {
vi.spyOn(mockConfig, 'isAutoDistillationEnabled').mockReturnValue(true);
const largeContent = 'a'.repeat(300000); // Larger than MAX_CONTENT_LENGTH (250000)
mockFetch('https://example.com/large-text', {
status: 200,
headers: new Headers({ 'content-type': 'text/plain' }),
text: () => Promise.resolve(largeContent),
});
const tool = new WebFetchTool(mockConfig, bus);
const invocation = tool.build({ url: 'https://example.com/large-text' });
const result = await invocation.execute(new AbortController().signal);
expect((result.llmContent as string).length).toBe(300000); // No truncation
});
it('should truncate if isAutoDistillationEnabled is false', async () => {
vi.spyOn(mockConfig, 'isAutoDistillationEnabled').mockReturnValue(false);
const largeContent = 'a'.repeat(300000); // Larger than MAX_CONTENT_LENGTH (250000)
mockFetch('https://example.com/large-text2', {
status: 200,
headers: new Headers({ 'content-type': 'text/plain' }),
text: () => Promise.resolve(largeContent),
});
const tool = new WebFetchTool(mockConfig, bus);
const invocation = tool.build({ url: 'https://example.com/large-text2' });
const result = await invocation.execute(new AbortController().signal);
expect((result.llmContent as string).length).toBeLessThan(300000);
expect(result.llmContent).toContain(
'[Content truncated due to size limit]',
);
});
});
});