29 lines
931 B
JavaScript
29 lines
931 B
JavaScript
|
|
class MemoryOptimizer {
|
|
constructor(options = {}) {
|
|
this.threshold = options.threshold || 0.3;
|
|
this.decayRate = options.decayRate || 0.01;
|
|
this.lastRun = Date.now();
|
|
this.blackboard = options.blackboard || null;
|
|
}
|
|
|
|
optimize(memories) {
|
|
const now = Date.now();
|
|
const elapsed = (now - this.lastRun) / 1000;
|
|
this.lastRun = now;
|
|
|
|
const result = memories.map(m => {
|
|
const decay = (m.importance || 1) * this.decayRate * elapsed;
|
|
return { ...m, strength: Math.max(0, (m.strength || 1) - decay) };
|
|
}).filter(m => m.strength > this.threshold || m.locked);
|
|
|
|
if (this.blackboard) {
|
|
this.blackboard.write('memory_count', result.length, 'MemoryOptimizer');
|
|
this.blackboard.write('optimization_last_run', now, 'MemoryOptimizer');
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
export default MemoryOptimizer;
|