fix(memory): wire auto_extract through orchestrator compaction
This commit is contained in:
@@ -3,6 +3,7 @@ import { compactHistory, DEFAULT_COMPACTION_CONFIG } from './compaction.js';
|
||||
import type { CompactionConfig } from './compaction.js';
|
||||
import type { AgentOrchestrator } from '../backends/native/orchestrator.js';
|
||||
import type { Message } from '../models/types.js';
|
||||
import type { MemoryStore } from '../memory/store.js';
|
||||
|
||||
function makeMockOrchestrator(summaryText = 'Summary of conversation'): AgentOrchestrator {
|
||||
return {
|
||||
@@ -146,4 +147,51 @@ describe('compactHistory', () => {
|
||||
expect(result.messages.some(msg => typeof msg.content === 'string' && msg.content.includes('[Summary of earlier conversation]'))).toBe(true);
|
||||
expect(result.messages.length).toBeGreaterThan(5);
|
||||
});
|
||||
|
||||
it('auto-extracts memory facts by default when memoryStore is provided', async () => {
|
||||
const messages = makeMessages(10);
|
||||
const memoryStore = {
|
||||
write: vi.fn(),
|
||||
} as unknown as MemoryStore;
|
||||
const orchestrator = {
|
||||
getDelegationTier: vi.fn().mockReturnValue('fast'),
|
||||
delegate: vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce({
|
||||
content: 'Compacted summary',
|
||||
usage: { inputTokens: 100, outputTokens: 50 },
|
||||
tier: 'fast',
|
||||
})
|
||||
.mockResolvedValueOnce({
|
||||
content: '- User prefers concise answers.',
|
||||
usage: { inputTokens: 40, outputTokens: 20 },
|
||||
tier: 'fast',
|
||||
}),
|
||||
} as unknown as AgentOrchestrator;
|
||||
|
||||
await compactHistory({ messages, orchestrator, config, memoryStore });
|
||||
|
||||
expect(orchestrator.getDelegationTier).toHaveBeenCalledWith('memory_extraction');
|
||||
expect(memoryStore.write).toHaveBeenCalledWith('global', '- User prefers concise answers.', 'append');
|
||||
});
|
||||
|
||||
it('skips auto-extraction when autoExtract is false', async () => {
|
||||
const messages = makeMessages(10);
|
||||
const memoryStore = {
|
||||
write: vi.fn(),
|
||||
} as unknown as MemoryStore;
|
||||
const orchestrator = {
|
||||
getDelegationTier: vi.fn().mockReturnValue('fast'),
|
||||
delegate: vi.fn().mockResolvedValue({
|
||||
content: 'Compacted summary',
|
||||
usage: { inputTokens: 100, outputTokens: 50 },
|
||||
tier: 'fast',
|
||||
}),
|
||||
} as unknown as AgentOrchestrator;
|
||||
|
||||
await compactHistory({ messages, orchestrator, config, memoryStore, autoExtract: false });
|
||||
|
||||
expect(orchestrator.getDelegationTier).not.toHaveBeenCalledWith('memory_extraction');
|
||||
expect(memoryStore.write).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user