Skip to content

feat(memory): integrate mem0 + IExternalMemoryPort abstraction #339

@JustAGhosT

Description

@JustAGhosT

Summary

Integrate managed memory services (mem0 and alternatives) via a new IExternalMemoryPort abstraction. The current IMeshMemoryStore abstraction covers raw storage backends but not higher-level services that provide automatic memory extraction, deduplication, relationship tracking, and cross-session memory graphs.

Problem

8 store backends and 5 vector providers exist, but no integration with managed memory services like mem0. The current IMeshMemoryStore is too low-level for services that handle memory lifecycle (extraction → deduplication → relationship tracking → retrieval).

Architecture

Two-layer integration:

  1. IExternalMemoryPort (new, MetacognitiveLayer) — higher-level port for managed memory services
  2. Mem0Adapter (new, FoundationLayer) — implements IExternalMemoryPort via mem0 REST API
  3. Mem0MemoryStoreAdapter — wraps IExternalMemoryPort to satisfy IMeshMemoryStore for backward compat

New Interface

public interface IExternalMemoryPort
{
    Task<string> AddMemoryAsync(string content, string userId, IDictionary<string, string>? metadata, CancellationToken ct);
    Task<IReadOnlyList<MemorySearchResult>> SearchMemoryAsync(string query, string userId, int limit, CancellationToken ct);
    Task<IReadOnlyList<MemoryEntry>> GetAllMemoriesAsync(string userId, CancellationToken ct);
    Task<MemoryEntry?> GetMemoryAsync(string memoryId, CancellationToken ct);
    Task DeleteMemoryAsync(string memoryId, CancellationToken ct);
    Task<MemoryHistory> GetHistoryAsync(string memoryId, CancellationToken ct);
}

Integration Points

File Change
src/MetacognitiveLayer/Protocols/Common/Memory/Interfaces.cs Add IExternalMemoryPort
src/MetacognitiveLayer/Protocols/Common/Memory/MemoryStoreFactory.cs Add "mem0" to ResolveMemoryStore(), add config props
src/FoundationLayer/Mem0Integration/ (new) Mem0Adapter, Mem0Client, Mem0Options

Dependencies

  • HttpClient via IHttpClientFactory for mem0 REST API
  • Circuit breaker via existing AgentCircuitBreakerPolicy
  • Feature flag EnableMem0 via IFeatureFlagManager

Acceptance Criteria

  • IExternalMemoryPort defined in MetacognitiveLayer
  • Mem0Adapter with circuit breaker in FoundationLayer
  • MemoryStoreFactory supports StoreType: "mem0"
  • Mem0MemoryStoreAdapter wraps port for backward compat
  • Unit tests with mocked HTTP
  • XML docs, 0 warnings
  • Feature flag EnableMem0 gates the integration

Effort Estimate

5–8 days

Enables

  • BacklogCrew and CommsCrew (cross-session memory for conversation/issue context)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions