fix(memory): use auto-incrementing id as tick proxy for recency scoring
Events recorded with tick: 0 now get a meaningful tick value from the service's internal counter, ensuring selectForPrompt recency scoring works correctly. Also fixed preferTypes to accept readonly arrays. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ export interface EventMemoryService {
|
||||
getRecentEvents(entityId: EntityId, count: number): MemoryEvent[];
|
||||
selectForPrompt(entityId: EntityId, opts: {
|
||||
maxCount: number;
|
||||
preferTypes?: MemoryEventType[];
|
||||
preferTypes?: readonly MemoryEventType[];
|
||||
preferEntityId?: EntityId;
|
||||
}): MemoryEvent[];
|
||||
onEventRecorded: ((entityId: EntityId, event: MemoryEvent) => void) | null;
|
||||
@@ -29,9 +29,12 @@ export function createEventMemoryService(maxEvents = 50): EventMemoryService {
|
||||
onEventRecorded: null,
|
||||
|
||||
record(entityId: EntityId, eventData: Omit<MemoryEvent, 'id'>): MemoryEvent {
|
||||
const id = nextId++;
|
||||
const event: MemoryEvent = {
|
||||
id: nextId++,
|
||||
id,
|
||||
...eventData,
|
||||
// Use auto-incrementing id as tick proxy when caller passes 0
|
||||
tick: eventData.tick || id,
|
||||
};
|
||||
|
||||
const buf = getBuffer(entityId);
|
||||
|
||||
@@ -166,7 +166,7 @@ function describeRecentEvents(
|
||||
|
||||
const events = eventMemoryService.selectForPrompt(entityId, {
|
||||
maxCount: 5,
|
||||
preferTypes: preferTypes as any,
|
||||
preferTypes,
|
||||
});
|
||||
if (events.length > 0) {
|
||||
return events.map(e => `- ${e.detail}`).join('\n');
|
||||
|
||||
Reference in New Issue
Block a user