Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/core/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ export function runTask(
}
}

// Break out of the event loop if task is complete
// Continue yielding remaining events even after completion
if (isComplete) {
break;
continue;
}

// Add response to history
Expand Down Expand Up @@ -459,7 +459,7 @@ export function runTask(
export function internalAddMessage(
messages: ResponseInput,
message: ResponseInput[0],
_source: 'external' | 'metacognition' = 'external'
source: 'external' | 'metacognition' = 'external'
): void {
// Validate the message
if (!message || typeof message !== 'object') {
Expand All @@ -482,7 +482,9 @@ export function internalAddMessage(

// Add the message
messages.push(message);
//console.log(`[Task] ${source === 'metacognition' ? 'Metacognition' : 'External'} message added with role: ${message.role}`);
console.log(
`[Task] ${source === 'metacognition' ? 'Metacognition' : 'External'} message added with role: ${message.role}`
);
}

/**
Expand Down
56 changes: 53 additions & 3 deletions test/metamemory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,57 @@ import {
type MetamemoryState,
type CompactionResult,
type ThreadClass,
} from '../src/metamemory/index.js';
} from '../src/metamemory-old/index.js';

vi.mock('@just-every/ensemble', async (importOriginal) => {
const original: any = await importOriginal();
return {
...original,
ensembleRequest: vi.fn(async function* (_messages: any, agent: any) {
const instr = agent.instructions as string;
if (instr.includes('Analyze the following conversation messages')) {
yield {
type: 'response_output',
message: {
type: 'message',
role: 'assistant',
content: JSON.stringify({
messageAnalysis: [
{ messageId: 'msg1', threadIds: ['thread1'], confidence: 0.9 },
{ messageId: 'msg2', threadIds: ['thread1'], confidence: 0.85 }
],
threadOperations: {
create: [
{ id: 'thread1', name: 'Test Thread', initialMessages: ['msg1'] }
]
},
reasoning: ''
})
}
};
} else if (instr.includes('Summarize the following conversation thread')) {
yield {
type: 'response_output',
message: {
type: 'message',
role: 'assistant',
content: JSON.stringify({
threadId: 'thread1',
title: 'Test Thread Summary',
class: 'active',
keySummary: 'This thread discusses testing the metamemory system.',
keyPoints: ['Created test messages', 'Analyzed thread structure'],
status: 'active',
importance: 75
})
}
};
} else {
yield { type: 'response_output', message: { type: 'message', role: 'assistant', content: '{}' } };
}
})
};
});

// Mock agent for testing
const createMockAgent = () => {
Expand Down Expand Up @@ -244,8 +294,8 @@ describe('Metamemory System', () => {
expect(coreMessage?.isCompacted).toBe(false);

// Ephemeral thread should be summarized
const ephemeralSummary = result.messages.find(m =>
m.content.includes('Thread: Casual Chat') && m.isCompacted
const ephemeralSummary = result.messages.find(m =>
m.content.includes('Brief social interaction') && m.isCompacted
);
expect(ephemeralSummary).toBeDefined();
expect(ephemeralSummary?.isCompacted).toBe(true);
Expand Down