This commit is contained in:
Your Name
2026-04-08 22:07:44 +00:00
parent b39b74ee09
commit 9b9ed0c803
6 changed files with 15 additions and 18 deletions
@@ -39,11 +39,13 @@ export class EmergencyTruncationProcessor implements ContextProcessor {
readonly id = 'EmergencyTruncationProcessor';
readonly name = 'EmergencyTruncationProcessor';
private readonly env: ContextEnvironment;
readonly options: EmergencyTruncationProcessorOptions;
constructor(
_env: ContextEnvironment,
env: ContextEnvironment,
options: EmergencyTruncationProcessorOptions,
) {
this.env = env;
this.options = options;
}
@@ -109,14 +109,12 @@ export class HistorySquashingProcessor implements ContextProcessor {
}
if (modified) {
const newTokens = this.env.tokenCalculator.estimateTokensForParts(
newParts.map(p => {
if (p.type === 'text') return { text: p.text };
if (p.type === 'inline_data') return { inlineData: { mimeType: p.mimeType, data: p.data } };
if (p.type === 'file_data') return { fileData: { mimeType: p.mimeType, fileUri: p.fileUri } };
return (p as Extract<import('../ir/types.js').SemanticPart, { type: 'raw_part' }>).part;
})
);
});
returnedNodes.push({
...prompt,
id: this.env.idGenerator.generateId(),
@@ -73,19 +73,16 @@ describe('SemanticCompressionProcessor', () => {
expect(compressedPrompt.id).not.toBe(prompt.id);
expect(compressedPrompt.semanticParts[0].type).toBe('text');
expect((compressedPrompt.semanticParts[0] as any).text).toBe('Mocked Summary!');
expect(compressedPrompt.metadata.transformations.length).toBe(1);
// 2. Agent Thought
const compressedThought = result[1] as AgentThought;
expect(compressedThought.id).toBe('mock-uuid-2');
expect(compressedThought.id).not.toBe(thought.id);
expect(compressedThought.text).toBe('Mocked Summary!');
expect(compressedThought.metadata.transformations.length).toBe(1);
const compressedTool = result[2] as ToolExecution;
expect(compressedTool.id).toBe('mock-uuid-3');
expect(compressedTool.id).not.toBe(tool.id);
expect(compressedTool.observation).toEqual({ summary: 'Mocked Summary!' });
expect(compressedTool.metadata.transformations.length).toBe(1);
expect(mockLlmClient.generateContent).toHaveBeenCalledTimes(3);
});
@@ -133,7 +133,6 @@ export class StateSnapshotProcessor implements ContextProcessor, ContextWorker {
try {
const snapshotText = await this.synthesizeSnapshot(nodesToSummarize);
const newId = this.env.idGenerator.generateId();
const tokens = this.env.tokenCalculator.estimateTokensForString(snapshotText);
const snapshotNode: Snapshot = {
id: newId,
logicalParentId: newId,
@@ -17,6 +17,7 @@ describe('ToolMaskingProcessor', () => {
// 1 token = 1 char for simplicity
// Fake token calculator says new tokens are 5
env.tokenCalculator.estimateTokensForParts = vi.fn().mockReturnValue(5);
env.tokenCalculator.getTokenCost = vi.fn().mockReturnValue(150);
const processor = ToolMaskingProcessor.create(env, {
stringLengthThresholdTokens: 10,
@@ -133,28 +133,28 @@ exports[`System Lifecycle Golden Tests > Scenario 1: Organic Growth with Huge To
],
"tokenTrajectory": [
{
"tokensAfterBackground": 12,
"tokensBeforeBackground": 12,
"tokensAfterBackground": 14,
"tokensBeforeBackground": 14,
"turnIndex": 0,
},
{
"tokensAfterBackground": 25,
"tokensBeforeBackground": 25,
"tokensAfterBackground": 29,
"tokensBeforeBackground": 29,
"turnIndex": 1,
},
{
"tokensAfterBackground": 10070,
"tokensBeforeBackground": 10070,
"tokensAfterBackground": 10137,
"tokensBeforeBackground": 10137,
"turnIndex": 2,
},
{
"tokensAfterBackground": 13353,
"tokensBeforeBackground": 13353,
"tokensAfterBackground": 13422,
"tokensBeforeBackground": 13422,
"turnIndex": 3,
},
{
"tokensAfterBackground": 13367,
"tokensBeforeBackground": 13367,
"tokensAfterBackground": 13438,
"tokensBeforeBackground": 13438,
"turnIndex": 4,
},
],