Migrate Memory System to Backend-Agnostic Architecture

t-479·WorkTask·
·
·
·Omni/Agent.hs
Created4 weeks ago·Updated4 weeks ago

Description

Edit

Migrate Memory System to Backend-Agnostic Architecture

Goal

Refactor the memory system (currently telegram/ava-specific) into a generic, backend-agnostic architecture that integrates with the free monad agent implementation in Omni/Agent.

Design

Backend Abstraction

data MemoryBackend m = MemoryBackend
  { mbStore    :: MemoryEntry -> m ()
  , mbSearch   :: Text -> Int -> m [MemoryEntry]  -- semantic search
  , mbRecent   :: Int -> m [MemoryEntry]          -- temporal
  , mbByTag    :: [Tag] -> m [MemoryEntry]
  , mbPrune    :: m ()                            -- cleanup/consolidation
  }

Embedding Provider Abstraction

data EmbeddingProvider m = EmbeddingProvider
  { epEmbed      :: Text -> m (Vector Float)
  , epBatchEmbed :: [Text] -> m [Vector Float]
  }

Implementations: ollama (local), openai, noop (for tests)

Concrete Backends

1. In-memory (IORef, good for dev/testing) 2. SQLite (refactor from current ava implementation) 3. Future: postgres, qdrant, neo4j

Free Monad Integration

Add memory operations to the agent DSL:

data AgentF next
  = ...
  | Remember MemoryEntry next
  | Recall Text Int ([MemoryEntry] -> next)
  | Forget MemoryId next

The interpreter config takes a MemoryBackend:

data AgentConfig = AgentConfig
  { acMemory :: MemoryBackend IO
  , acModel  :: Model
  , ...
  }

Work Items

1. Define MemoryBackend and EmbeddingProvider abstractions in Omni/Agent/Memory.hs 2. Add Remember/Recall/Forget ops to the free monad DSL in Omni/Agent/Engine.hs 3. Implement interpreter cases that delegate to the configured backend 4. Refactor existing sqlite memory code from Ava into a reusable backend 5. Create in-memory backend for testing 6. Update Ava to wire up its sqlite backend via the new abstraction

Notes

  • Adaptive context window already implemented in Memory.hs (t-345)
  • This task is purely about backend abstraction and free monad integration
  • Graph db backend would enable relational queries (what relates X to Y)

Timeline (3)

🔄[human]Open → Done4 weeks ago
💬[human]4 weeks ago

Duplicate of t-477