Skill

Implement LLM Conversation Memory Systems

Persistent memory systems for LLM conversations - tiered short/long-term/entity memory, memory-aware prompting, and strict per-user isolation.

Works with mem0langchainredis

73
Spark score
out of 100
Updated last month
Version 13.4.0
Models
universal

Add to Favorites

Why it matters

Enhance conversational AI by implementing persistent memory systems. This asset provides short-term, long-term, and entity-based memory to improve context retention and recall across LLM interactions.

Outcomes

What it gets done

01

Manage short-term conversation history for immediate context.

02

Implement long-term memory for persistent recall across sessions.

03

Track and retrieve specific facts about entities (people, places, things).

04

Integrate memory retrieval into LLM prompts for context-aware responses.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/ag-conversation-memory | bash

Overview

Conversation Memory

A skill for persistent LLM conversation memory covering tiered storage, entity extraction, relevance-filtered retrieval, and per-user isolation. Use for conversation memory, memory persistence, long-term memory, or chat history needs; not for knowledge graph construction or database administration.

What it does

This skill covers persistent memory systems for LLM conversations, including short-term, long-term, and entity-based memory, focused on storage and retrieval patterns rather than knowledge graph construction, semantic search implementation, or database administration.

Its tiered memory system defines four layers: a buffer (current in-context conversation), short-term memory (recent session interactions), long-term memory (persistent across sessions), and entity memory (facts about people, places, and things). Every message is added to the buffer and scanned for entities to upsert; messages judged memory-worthy are scored for importance and added to short-term memory. A consolidation step periodically moves short-term memories older than 24 hours into long-term storage if their importance exceeds 0.7 or they've been referenced more than twice, then removes them from short-term. Building context for a query pulls the top relevant long-term memories, relevant known entities, and recent conversation into a structured prompt section.

Its entity memory pattern uses an LLM to extract named entities and facts from each message, then upserts them - merging new facts into an existing entity record (avoiding duplicate facts, updating last-mentioned time and mention count) or creating a new entity record with confidence-scored facts tied to their source message and timestamp. Its memory-aware prompting pattern retrieves relevant long-term memories and entities plus recent buffer context, assembles them into a structured prompt (a User Context section of known entity facts, a Relevant past interactions section, recent conversation, then the current query), and stores the resulting response back into memory.

It documents three sharp edges with fixes. Unbounded memory growth (HIGH severity - every message stored with no cleanup, causing slow retrieval and rising storage costs) is fixed with lifecycle management: score importance before storing (skip anything below 0.3), cap short-term memory size, and on overflow consolidate the top 70% by importance while discarding the rest (promoting items above 0.7 importance to long-term). Irrelevant retrieved memories (HIGH severity - simple keyword matching with no relevance scoring produces confusing, seemingly random context) is fixed by combining semantic search with an LLM relevance-scoring pass that filters out anything below 0.5 relevance before sorting and limiting results. Cross-user memory leakage (CRITICAL severity - one user seeing another user's stored information, a privacy and compliance violation) is fixed with strict per-user namespacing on every key, a mandatory userId filter on every search, ownership verification before delete, and GDPR-compliant per-user data export and deletion methods.

Its validation checks flag: no user isolation in memory operations (CRITICAL - a privacy vulnerability, fixed by adding userId to all operations and filtering by user on retrieval); no importance filtering before storing (WARNING - risks memory explosion); memory storage with no retrieval logic (WARNING - stored memories never get used); and no memory cleanup mechanism (INFO - storage grows unbounded without age/importance-based consolidation). It delegates to context-window-management for token/context needs, rag-implementation for retrieval/vector needs, and prompt-caching for caching strategies, forming a complete memory system together with those skills.

class IsolatedMemory {
    private getKey(userId: string, memoryId: string): string {
        return `user:${userId}:memory:${memoryId}`;
    }

    async add(userId: string, memory: Memory): Promise<void> {
        if (!isValidUserId(userId)) {
            throw new Error('Invalid user ID');
        }
        const key = this.getKey(userId, memory.id);
        memory.userId = userId;
        await this.store.set(key, memory);
    }

    async search(userId: string, query: string): Promise<Memory[]> {
        return await this.store.search({
            query,
            filter: { userId: userId },
            limit: 10
        });
    }
}

When to use - and when NOT to

Use this skill when you need conversation memory, remembering user information across sessions, memory persistence, long-term memory, or chat history handling.

Does not cover knowledge graph construction, semantic search implementation, or database administration - those belong to related skills like rag-implementation.

Inputs and outputs

Inputs: an ongoing LLM conversation whose facts, entities, or important interactions need to persist across turns or sessions.

Outputs: a tiered memory store (buffer/short-term/long-term/entity) with importance-scored consolidation, relevance-filtered retrieval into prompts, and strict per-user isolation with GDPR export/deletion support.

Integrations

Mem0, LangChain Memory, Redis. Related skills: context-window-management, rag-implementation, prompt-caching, llm-npc-dialogue.

Who it's for

Developers building conversational AI that needs to remember user facts and past interactions across sessions, safely isolated per user.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.