MemoryService

from mango.memory import MemoryService

Abstract base class for all memory backends. Implement this to use any vector store.

Interface

class MemoryService(ABC):

    # Tool-usage memory
    @abstractmethod
    async def store(self, entry: MemoryEntry) -> None: ...

    @abstractmethod
    async def retrieve(
        self,
        question: str,
        top_k: int = 3,
        similarity_threshold: float = 0.6,
    ) -> list[MemoryEntry]: ...

    @abstractmethod
    async def delete(self, entry_id: str) -> None: ...

    # Text memory
    @abstractmethod
    async def save_text(self, text: str) -> str: ...

    @abstractmethod
    async def search_text(
        self,
        query: str,
        top_k: int = 3,
        similarity_threshold: float = 0.6,
    ) -> list[TextMemoryEntry]: ...

    # Sync
    @abstractmethod
    def count(self) -> int: ...

Data types

MemoryEntry

@dataclass
class MemoryEntry:
    id: str
    question: str        # original natural language question
    tool_name: str       # tool that was called
    tool_args: dict      # exact arguments that worked
    result_summary: str  # first 300 chars of the result
    similarity: float    # filled by retrieve(), cosine similarity
    timestamp: str       # ISO timestamp

TextMemoryEntry

@dataclass
class TextMemoryEntry:
    id: str
    text: str
    similarity: float    # filled by search_text()

make_entry_id

from mango.memory import make_entry_id

entry_id = make_entry_id()   # str(uuid.uuid4())

Built-in implementation

ClassImport
ChromaAgentMemorymango.integrations.chromadb

→ See Custom Memory Backend to implement your own.