Memory Consolidation Flow for AI Agents

ML & AI · sequence diagram · MIT

Illustrates the process of an AI agent's working memory being consolidated into episodic memory within a MemoryMesh, including vector index management and

Source: https://github.com/vinoth2vinoth/Orchestra/blob/06e0a340f90d486d2f729cc8473921845af9622e/readme/memory-layer.md
Curated by vinoth2vinoth
AI Agent Memory Management Consolidation Sequence Diagram Vector Database Event Log

Mermaid source

sequenceDiagram
    participant Agent
    participant MemoryMesh
    participant globalEventStore

    Agent->>MemoryMesh: addWorkingMemory(threadId, content)
    MemoryMesh->>MemoryMesh: store('WORKING', content)
    MemoryMesh->>MemoryMesh: checkConsolidation(threadId)
    
    alt Working memories > 5
        MemoryMesh->>MemoryMesh: filter WORKING memories for thread
        MemoryMesh->>MemoryMesh: generate summary string (heuristic)
        MemoryMesh->>MemoryMesh: addEpisodicMemory('SYSTEM', {originThread, summary})
        MemoryMesh->>MemoryMesh: purge old WORKING memories
        MemoryMesh->>MemoryMesh: rebuildVectorIndex()
        MemoryMesh->>globalEventStore: append({type: 'MEMORY_STORED', action: 'CONSOLIDATION'})
    end
    
    MemoryMesh->>MemoryMesh: garbageCollect()
    
    alt Retention < 0.1
        MemoryMesh->>MemoryMesh: move to coldMemories
        MemoryMesh->>MemoryMesh: tombstone in active array
        MemoryMesh->>globalEventStore: append({action: 'COLD_STORAGE_MOVE'})
        MemoryMesh->>MemoryMesh: rebuildVectorIndex()
    end

What this diagram shows

This diagram details how an Agent adds working memory to a MemoryMesh, which then stores and periodically checks for consolidation. If working memories exceed a threshold (e.g., 5), they are filtered, summarized into episodic memory, and old working memories are purged. The vector index is rebuilt, and events are logged. It also depicts garbage collection and moving memories to cold storage based on retention.

When to use it

Use this diagram when designing, documenting, or explaining the memory management and consolidation strategies for AI agents, conversational systems, or any application requiring intelligent summarization and retention of interaction history.

How to adapt it for your project

This flow can be adapted by modifying consolidation triggers (e.g., time-based, event-driven), changing summarization heuristics, implementing different memory types (e.g., semantic, procedural), or integrating with external knowledge bases. The cold storage criteria and vector index rebuilding frequency can also be adjusted.

Key concepts