Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Persistent memory systems for LLM conversations including short-term, long-term, and entity-based memory
.claude/skills/conversation-memory/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-03 | ✗→✓ | ▲ Improved | 88% | 0% |
| case-01 | ✗→✓ | ▲ Improved | 144% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 97% | 0% |
| case-09 | ✗→✓ | ▲ Improved | 159% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 218% | 0% |
Persistent memory systems for LLM conversations including short-term, long-term, and entity-based memory
Different memory tiers for different purposes
When to use: Building any conversational AI
typescriptinterface MemorySystem { // Buffer: Current conversation (in context) buffer: ConversationBuffer; // Short-term: Recent interactions (session) shortTerm: ShortTermMemory; // Long-term: Persistent across sessions longTerm: LongTermMemory; // Entity: Facts about people, places, things entity: EntityMemory; } class TieredMemory implements MemorySystem { async addMessage(message: Message): Promise<void> { // Always add to buffer this.buffer.add(message); // Extract entities const entities = await extractEntities(message); for (const entity of entities) { await this.entity.upsert(entity); } // Check for memorable content if (await isMemoryWorthy(message)) { await this.shortTerm.add({ content: message.content, timestamp: Date.now(), importance: await scoreImportance(message) }); } } async consolidate(): Promise<void> { // Move important short-term to long-term const memories = await this.shortTerm.getOld(24 * 60 * 60 * 1000); for (const memory of memories) { if (memory.importance > 0.7 || memory.referenced > 2) { await this.longTerm.add(memory); } await this.shortTerm.remove(memory.id); } } async buildContext(query: string): Promise<string> { const parts: string[] = []; // Relevant long-term memories const longTermRelevant = await this.longTerm.search(query, 3); if (longTermRelevant.length) { parts.push('## Relevant Memories\n' + longTermRelevant.map(m => `- ${m.content}`).join('\n')); } // Relevant entities const entities = await this.entity.getRelevant(query); if (entities.length) { parts.push('## Known Entities\n' + entities.map(e => `- ${e.name}: ${e.facts.join(', ')}`).join('\n')); } // Recent conversation const recent = this.buffer.getRecent(10); parts.push('## Recent Conversation\n' + formatMessages(recent)); return parts.join('\n\n'); } }
Store and update facts about entities
When to use: Need to remember details about people, places, things
typescriptinterface Entity { id: string; name: string; type: 'person' | 'place' | 'thing' | 'concept'; facts: Fact[]; lastMentioned: number; mentionCount: number; } interface Fact { content: string; confidence: number; source: string; // Which message this came from timestamp: number; } class EntityMemory { async extractAndStore(message: Message): Promise<void> { // Use LLM to extract entities and facts const extraction = await llm.complete(` Extract entities and facts from this message. Return JSON: { "entities": [ { "name": "...", "type": "...", "facts": ["..."] } ]} Message: "${message.content}" `); const { entities } = JSON.parse(extraction); for (const entity of entities) { await this.upsert(entity, message.id); } } async upsert(entity: ExtractedEntity, sourceId: string): Promise<void> { const existing = await this.store.get(entity.name.toLowerCase()); if (existing) { // Merge facts, avoiding duplicates for (const fact of entity.facts) { if (!this.hasSimilarFact(existing.facts, fact)) { existing.facts.push({ content: fact, confidence: 0.9, source: sourceId, timestamp: Date.now() }); } } existing.lastMentioned = Date.now(); existing.mentionCount++; await this.store.set(existing.id, existing); } else { // Create new entity await this.store.set(entity.name.toLowerCase(), { id: generateId(), name: entity.name, type: entity.type, facts: entity.facts.map(f => ({ content: f, confidence: 0.9, source: sourceId, timestamp: Date.now() })), lastMentioned: Date.now(), mentionCount: 1 }); } } }
Include relevant memories in prompts
When to use: Making LLM calls with memory context
typescriptasync function promptWithMemory( query: string, memory: MemorySystem, systemPrompt: string ): Promise<string> { // Retrieve relevant memories const relevantMemories = await memory.longTerm.search(query, 5); const entities = await memory.entity.getRelevant(query); const recentContext = memory.buffer.getRecent(5); // Build memory-augmented prompt const prompt = ` ${systemPrompt} ## User Context ${entities.length ? `Known about user:\n${entities.map(e => `- ${e.name}: ${e.facts.map(f => f.content).join('; ')}` ).join('\n')}` : ''} ${relevantMemories.length ? `Relevant past interactions:\n${relevantMemories.map(m => `- [${formatDate(m.timestamp)}] ${m.content}` ).join('\n')}` : ''} ## Recent Conversation ${formatMessages(recentContext)} ## Current Query ${query} `.trim(); const response = await llm.complete(prompt); // Extract any new memories from response await memory.addMessage({ role: 'assistant', content: response }); return response; }
Severity: HIGH
Situation: System slows over time, costs increase
Symptoms:
Why this breaks: Every message stored as memory. No cleanup or consolidation. Retrieval over millions of items.
Recommended fix:
typescript// Implement memory lifecycle management class ManagedMemory { // Limits private readonly SHORT_TERM_MAX = 100; private readonly LONG_TERM_MAX = 10000; private readonly CONSOLIDATION_INTERVAL = 24 * 60 * 60 * 1000; async add(memory: Memory): Promise<void> { // Score importance before storing const score = await this.scoreImportance(memory); if (score < 0.3) return; // Don't store low-importance memory.importance = score; await this.shortTerm.add(memory); // Check limits await this.enforceShortTermLimit(); } async enforceShortTermLimit(): Promise<void> { const count = await this.shortTerm.count(); if (count > this.SHORT_TERM_MAX) { // Consolidate: move important to long-term, delete rest const memories = await this.shortTerm.getAll(); memories.sort((a, b) => b.importance - a.importance); const toKeep = memories.slice(0, this.SHORT_TERM_MAX * 0.7); const toConsolidate = memories.slice(this.SHORT_TERM_MAX * 0.7); for (const m of toConsolidate) { if (m.importance > 0.7) { await this.longTerm.add(m); } await this.shortTerm.remove(m.id); } } } async scoreImportance(memory: Memory): Promise<number> { const factors = { hasUserPreference: /prefer|like|don't like|hate|love/i.test(memory.content) ? 0.3 : 0, hasDecision: /decided|chose|will do|won't do/i.test(memory.content) ? 0.3 : 0, hasFactAboutUser: /my|I am|I have|I work/i.test(memory.content) ? 0.2 : 0, length: memory.content.length > 100 ? 0.1 : 0, userMessage: memory.role === 'user' ? 0.1 : 0, }; return Object.values(factors).reduce((a, b) => a + b, 0); } }
Severity: HIGH
Situation: Memories included in context but don't help
Symptoms:
Why this breaks: Simple keyword matching. No relevance scoring. Including all retrieved memories.
Recommended fix:
typescript// Intelligent memory retrieval async function retrieveRelevant( query: string, memories: MemoryStore, maxResults: number = 5 ): Promise<Memory[]> { // 1. Semantic search const candidates = await memories.semanticSearch(query, maxResults * 3); // 2. Score relevance with context const scored = await Promise.all(candidates.map(async (m) => { const relevanceScore = await llm.complete(` Rate 0-1 how relevant this memory is to the query. Query: "${query}" Memory: "${m.content}" Return just the number. `); return { ...m, relevance: parseFloat(relevanceScore) }; })); // 3. Filter low relevance const relevant = scored.filter(m => m.relevance > 0.5); // 4. Sort and limit return relevant .sort((a, b) => b.relevance - a.relevance) .slice(0, maxResults); }
Severity: CRITICAL
Situation: User sees information from another user's sessions
Symptoms:
Why this breaks: No user isolation in memory store. Shared memory namespace. Cross-user retrieval.
Recommended fix:
typescript// Strict user isolation in memory class IsolatedMemory { private getKey(userId: string, memoryId: string): string { // Namespace all keys by user return `user:${userId}:memory:${memoryId}`; } async add(userId: string, memory: Memory): Promise<void> { // Validate userId is authenticated if (!isValidUserId(userId)) { throw new Error('Invalid user ID'); } const key = this.getKey(userId, memory.id); memory.userId = userId; // Tag with user await this.store.set(key, memory); } async search(userId: string, query: string): Promise<Memory[]> { // CRITICAL: Filter by user in query return await this.store.search({ query, filter: { userId: userId }, // Mandatory filter limit: 10 }); } async delete(userId: string, memoryId: string): Promise<void> { const memory = await this.get(userId, memoryId); // Verify ownership before delete if (memory.userId !== userId) { throw new Error('Access denied'); } await this.store.delete(this.getKey(userId, memoryId)); } // User data export (GDPR compliance) async exportUserData(userId: string): Promise<Memory[]> { return await this.store.getAll({ userId }); } // User data deletion (GDPR compliance) async deleteUserData(userId: string): Promise<void> { const memories = await this.exportUserData(userId); for (const m of memories) { await this.store.delete(this.getKey(userId, m.id)); } } }
Severity: CRITICAL
Message: Memory operations without user isolation. Privacy vulnerability.
Fix action: Add userId to all memory operations, filter by user on retrieval
Severity: WARNING
Message: Storing memories without importance filtering. May cause memory explosion.
Fix action: Score importance before storing, filter low-importance content
Severity: WARNING
Message: Storing memories but no retrieval logic. Memories won't be used.
Fix action: Implement memory retrieval and include in prompts
Severity: INFO
Message: No memory cleanup mechanism. Storage will grow unbounded.
Fix action: Implement consolidation and cleanup based on age/importance
Skills: conversation-memory, context-window-management, rag-implementation
Workflow:
1. Design memory tiers
2. Implement storage and retrieval
3. Integrate with context management
4. Add consolidation and cleanupWorks well with: context-window-management, rag-implementation, prompt-caching, llm-npc-dialogue
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-04 | pass→pass | 12,522 | 8,139 | -35% | 1 | 1 | 0% | 2,179 | 4,960 | +128% | 0 | 0 | — |
case-05 | pass→pass | 16,179 | 11,644 | -28% | 1 | 1 | 0% | 2,830 | 5,539 | +96% | 0 | 0 | — |
case-06 | pass→pass | 13,490 | 13,787 | +2% | 1 | 1 | 0% | 2,380 | 6,268 | +163% | 0 | 0 | — |
case-03 | fail→pass | 18,087 | 16,544 | -9% | 1 | 1 | 0% | 3,483 | 6,534 | +88% | 0 | 0 | — |
case-01 | fail→pass | 13,245 | 10,616 | -20% | 1 | 1 | 0% | 2,310 | 5,625 | +144% | 0 | 0 | — |
case-02 | fail→pass | 15,914 | 8,539 | -46% | 1 | 1 | 0% | 2,617 | 5,145 | +97% | 0 | 0 | — |
case-07 | pass→pass | 14,374 | 12,813 | -11% | 1 | 1 | 0% | 2,382 | 5,998 | +152% | 0 | 0 | — |
case-08 | pass→pass | 16,824 | 13,070 | -22% | 1 | 1 | 0% | 3,045 | 6,083 | +100% | 0 | 0 | — |
case-09 | fail→pass | 11,367 | 6,518 | -43% | 1 | 1 | 0% | 1,881 | 4,869 | +159% | 0 | 0 | — |
case-10 | pass→pass | 11,591 | 6,177 | -47% | 1 | 1 | 0% | 1,988 | 4,618 | +132% | 0 | 0 | — |
case-11 | fail→pass | 7,459 | 2,910 | -61% | 1 | 1 | 0% | 1,291 | 4,103 | +218% | 0 | 0 | — |
case-17 | pass→pass | 16,116 | 14,153 | -12% | 1 | 1 | 0% | 2,968 | 6,179 | +108% | 0 | 0 | — |
case-12 | fail→pass | 7,644 | 3,939 | -48% | 1 | 1 | 0% | 1,380 | 4,273 | +210% | 0 | 0 | — |
case-13 | pass→pass | 13,660 | 12,265 | -10% | 1 | 1 | 0% | 2,737 | 6,140 | +124% | 0 | 0 | — |
case-14 | pass→pass | 4,029 | 2,821 | -30% | 1 | 1 | 0% | 664 | 4,075 | +514% | 0 | 0 | — |
case-15 | pass→pass | 13,325 | 8,173 | -39% | 1 | 1 | 0% | 2,449 | 5,174 | +111% | 0 | 0 | — |
case-16 | pass→pass | 7,795 | 3,122 | -60% | 1 | 1 | 0% | 1,196 | 4,135 | +246% | 0 | 0 | — |
case-18 | pass→pass | 15,123 | 9,454 | -37% | 1 | 1 | 0% | 2,772 | 5,440 | +96% | 0 | 0 | — |
case-19 | fail→pass | 15,846 | 11,947 | -25% | 1 | 1 | 0% | 2,719 | 5,788 | +113% | 0 | 0 | — |
case-20 | pass→pass | 10,465 | 5,705 | -45% | 1 | 1 | 0% | 1,803 | 4,496 | +149% | 0 | 0 | — |
case-21 | fail→pass | 12,767 | 6,283 | -51% | 1 | 1 | 0% | 2,435 | 4,688 | +93% | 0 | 0 | — |
case-22 | fail→pass | 13,719 | 8,937 | -35% | 1 | 1 | 0% | 2,467 | 5,189 | +110% | 0 | 0 | — |
case-23 | pass→pass | 21,409 | 15,547 | -27% | 1 | 1 | 0% | 3,875 | 6,340 | +64% | 0 | 0 | — |
case-24 | pass→pass | 15,387 | 13,753 | -11% | 1 | 1 | 0% | 2,798 | 6,058 | +117% | 0 | 0 | — |
case-25 | pass→pass | 13,634 | 9,413 | -31% | 1 | 1 | 0% | 2,563 | 5,324 | +108% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 25 cases were attempted. The headline lift of +36 percentage points is the difference between those two pass rates over the 25 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
| Model | Method | Date | Lift |
|---|---|---|---|
| gemini-3.6-flash | verified | 7/28/2026 | +50% |
Other measured skills in the registry, with their headline benchmark lift.