Forget Something
by @roryyu
Implement forgetting mechanisms for AI systems to manage memory overload, improve performance, and maintain data privacy. Use when working with long-term AI...
clawhub install forget-something📖 About This Skill
name: forget-something description: Implement forgetting mechanisms for AI systems to manage memory overload, improve performance, and maintain data privacy. Use when working with long-term AI systems, memory management, or privacy-preserving AI.
Forget Something Skill
遗忘机制技能
This skill enables implementation of forgetting mechanisms for AI systems, particularly for OpenClaw agents, to manage memory overload, improve performance, and maintain data privacy. 该技能为AI系统(特别是OpenClaw智能体)实现遗忘机制,用于管理内存过载、提高性能和维护数据隐私。
Overview
概述
Forgetting mechanisms are essential for AI systems that accumulate large amounts of data over time. They help:
遗忘机制对于随时间积累大量数据的AI系统至关重要。它们有助于:
Forgetting Strategies
遗忘策略
1. Time-Based Forgetting
1. 基于时间的遗忘
Remove data after a specified time period. 在指定时间段后移除数据。
// Example: Remove memories older than 30 days
// 示例:删除超过30天的记忆
const forgetOldMemories = (memoryStore, days = 30) => {
const cutoffTime = Date.now() - (days * 24 * 60 * 60 * 1000);
memoryStore.filter(memory => memory.timestamp > cutoffTime);
};
2. Relevance-Based Forgetting
2. 基于相关性的遗忘
Remove data based on relevance score. 基于相关性分数移除数据。
// Example: Remove memories with relevance score below threshold
// 示例:删除相关性分数低于阈值的记忆
const forgetIrrelevantMemories = (memoryStore, threshold = 0.3) => {
memoryStore.filter(memory => memory.relevance >= threshold);
};
3. Frequency-Based Forgetting
3. 基于访问频率的遗忘
Remove data based on access frequency. 基于访问频率移除数据。
// Example: Remove memories accessed less than N times
// 示例:删除访问次数少于N次的记忆
const forgetInfrequentMemories = (memoryStore, minAccessCount = 2) => {
memoryStore.filter(memory => memory.accessCount >= minAccessCount);
};
4. Explicit Forgetting
4. 显式遗忘
Remove specific data based on user requests. 根据用户请求移除特定数据。
// Example: Remove specific memory by ID
// 示例:通过ID删除特定记忆
const forgetSpecificMemory = (memoryStore, memoryId) => {
memoryStore.filter(memory => memory.id !== memoryId);
};
5. Context-Based Forgetting
5. 基于上下文的遗忘
Remove data based on current context relevance. 基于当前上下文相关性移除数据。
// Example: Remove memories unrelated to current task
// 示例:删除与当前任务无关的记忆
const forgetContextIrrelevant = (memoryStore, currentContext) => {
memoryStore.filter(memory => {
return memory.topics.some(topic => currentContext.topics.includes(topic));
});
};
Implementation for OpenClaw
OpenClaw实现
Memory Store Structure
记忆存储结构
// Example memory structure
// 示例记忆结构
const memory = {
id: "unique-id-123",
content: "This is a memory content",
timestamp: Date.now(),
relevance: 0.8,
accessCount: 5,
topics: ["project", "meeting", "action-item"],
source: "user-input",
sensitivity: "low" // low, medium, high
// 敏感度:低、中、高
};
Forgetting Configuration
遗忘配置
// OpenClaw forgetting configuration
// OpenClaw遗忘配置
const forgettingConfig = {
strategies: [
{
type: "time-based",
days: 30,
enabled: true
},
{
type: "relevance-based",
threshold: 0.3,
enabled: true
},
{
type: "frequency-based",
minAccessCount: 2,
enabled: true
}
],
runInterval: "daily", // daily, weekly, monthly
// 运行间隔:每日、每周、每月
dryRun: false, // preview what would be deleted
// 模拟运行:预览将要删除的内容
backupBeforeForgetting: true
// 遗忘前备份:是
};
Integration with OpenClaw
与OpenClaw集成
// Example integration with OpenClaw agent
// 与OpenClaw智能体集成示例
const OpenClawForgettingMechanism = {
init(agent) {
this.agent = agent;
this.memoryStore = agent.memory;
this.config = agent.config.forgettingMechanism || {};
this.setupScheduler();
},
setupScheduler() {
const interval = this.config.runInterval || "daily";
const cronExpression = this.getCronExpression(interval);
// Schedule forgetting based on configuration
// 根据配置安排遗忘任务
this.agent.scheduler.addJob({
name: "forgetting-mechanism",
cron: cronExpression,
task: () => this.runForgetting()
});
},
getCronExpression(interval) {
const expressions = {
daily: "0 0 * * *",
weekly: "0 0 * * 0",
monthly: "0 0 1 * *"
};
return expressions[interval] || "0 0 * * *";
},
async runForgetting() {
this.agent.logger.info("Running forgetting mechanism...");
const originalCount = this.memoryStore.size;
// Apply all enabled strategies
// 应用所有启用的策略
this.config.strategies?.forEach(strategy => {
if (strategy.enabled) {
this.applyStrategy(strategy);
}
});
const finalCount = this.memoryStore.size;
const removedCount = originalCount - finalCount;
this.agent.logger.info(Forgetting mechanism completed: Removed ${removedCount} memories);
return {
originalCount,
finalCount,
removedCount
};
},
applyStrategy(strategy) {
switch (strategy.type) {
case "time-based":
this.forgetTimeBased(strategy.days);
break;
case "relevance-based":
this.forgetRelevanceBased(strategy.threshold);
break;
case "frequency-based":
this.forgetFrequencyBased(strategy.minAccessCount);
break;
case "context-based":
this.forgetContextBased(strategy.context);
break;
default:
this.agent.logger.warn(Unknown forgetting strategy: ${strategy.type});
}
},
forgetTimeBased(days = 30) {
const cutoffTime = Date.now() - (days * 24 * 60 * 60 * 1000);
this.memoryStore.filter(memory => memory.timestamp > cutoffTime);
},
forgetRelevanceBased(threshold = 0.3) {
this.memoryStore.filter(memory => memory.relevance >= threshold);
},
forgetFrequencyBased(minAccessCount = 2) {
this.memoryStore.filter(memory => memory.accessCount >= minAccessCount);
},
forgetContextBased(context) {
this.memoryStore.filter(memory => {
return memory.topics.some(topic => context.topics.includes(topic));
});
},
// Manual forgetting methods
// 手动遗忘方法
forgetSpecificMemory(memoryId) {
return this.memoryStore.filter(memory => memory.id !== memoryId);
},
forgetByTopic(topic) {
return this.memoryStore.filter(memory => !memory.topics.includes(topic));
},
forgetAll() {
return this.memoryStore.clear();
}
};
Usage Examples
使用示例
1. Configure Forgetting Mechanism
1. 配置遗忘机制
// In agent configuration
// 在智能体配置中
const agentConfig = {
// ... other config
// ... 其他配置
forgettingMechanism: {
strategies: [
{
type: "time-based",
days: 30,
enabled: true
},
{
type: "relevance-based",
threshold: 0.4,
enabled: true
}
],
runInterval: "daily",
backupBeforeForgetting: true
}
};
2. Manual Forgetting
2. 手动遗忘
// In agent code
// 在智能体代码中
await agent.forgettingMechanism.forgetSpecificMemory("memory-id-123");
await agent.forgettingMechanism.forgetByTopic("confidential");
3. Run Forgetting on Demand
3. 按需运行遗忘
// Trigger forgetting manually
// 手动触发遗忘
const result = await agent.forgettingMechanism.runForgetting();
console.log(Removed ${result.removedCount} memories);
Best Practices
最佳实践
1. Backup Strategy: Always backup memories before running forgetting operations 1. 备份策略:在运行遗忘操作前始终备份记忆
2. Dry Run First: Use dryRun mode to preview what would be deleted 2. 先模拟运行:使用dryRun模式预览将要删除的内容
3. Gradual Implementation: Start with conservative settings and adjust over time 3. 逐步实施:从保守设置开始,随着时间推移进行调整
4. Monitor Impact: Track performance and user experience after forgetting operations 4. 监控影响:在遗忘操作后跟踪性能和用户体验
5. Combine Strategies: Use multiple strategies for more effective memory management 5. 组合策略:使用多种策略进行更有效的记忆管理
6. Privacy Compliance: Ensure forgetting mechanisms comply with data protection regulations 6. 隐私合规:确保遗忘机制符合数据保护法规
Privacy Considerations
隐私考虑
Performance Benefits
性能优势
Testing and Validation
测试与验证
// Example test for forgetting mechanism
// 遗忘机制测试示例
const testForgettingMechanism = () => {
// Create test memories
// 创建测试记忆
const testMemories = [
{
id: "mem1",
content: "Old memory",
timestamp: Date.now() - (40 * 24 * 60 * 60 * 1000), // 40 days old
// 40天前
relevance: 0.2,
accessCount: 1
},
{
id: "mem2",
content: "Recent relevant memory",
timestamp: Date.now() - (10 * 24 * 60 * 60 * 1000), // 10 days old
// 10天前
relevance: 0.8,
accessCount: 5
},
{
id: "mem3",
content: "Recent irrelevant memory",
timestamp: Date.now() - (5 * 24 * 60 * 60 * 1000), // 5 days old
// 5天前
relevance: 0.1,
accessCount: 1
}
];
// Initialize memory store
// 初始化记忆存储
const memoryStore = new MemoryStore(testMemories);
// Create forgetting mechanism
// 创建遗忘机制
const forgetting = new OpenClawForgettingMechanism();
forgetting.memoryStore = memoryStore;
forgetting.config = {
strategies: [
{ type: "time-based", days: 30, enabled: true },
{ type: "relevance-based", threshold: 0.3, enabled: true }
]
};
// Run forgetting
// 运行遗忘
forgetting.runForgetting();
// Verify results
// 验证结果
const remainingMemories = memoryStore.getAll();
console.log(Remaining memories: ${remainingMemories.length});
console.log(remainingMemories.map(m => m.content));
// Should only keep mem2
// 应该只保留mem2
return remainingMemories.length === 1 && remainingMemories[0].id === "mem2";
};
Integration Points
集成点
Future Enhancements
未来增强
References
参考资料
📋 Tips & Best Practices
最佳实践
1. Backup Strategy: Always backup memories before running forgetting operations 1. 备份策略:在运行遗忘操作前始终备份记忆
2. Dry Run First: Use dryRun mode to preview what would be deleted 2. 先模拟运行:使用dryRun模式预览将要删除的内容
3. Gradual Implementation: Start with conservative settings and adjust over time 3. 逐步实施:从保守设置开始,随着时间推移进行调整
4. Monitor Impact: Track performance and user experience after forgetting operations 4. 监控影响:在遗忘操作后跟踪性能和用户体验
5. Combine Strategies: Use multiple strategies for more effective memory management 5. 组合策略:使用多种策略进行更有效的记忆管理
6. Privacy Compliance: Ensure forgetting mechanisms comply with data protection regulations 6. 隐私合规:确保遗忘机制符合数据保护法规