Architecture
System Overview
MemoryLayer is infrastructure: a memory backend that agents and agent frameworks consume, the way applications use PostgreSQL for relational data or Redis for caching.
┌──────────────────────────────────────────────────────────────────┐│ Agent hosts & frameworks ││ Claude Code · OpenCode · Codex · OpenClaw · LangChain · LlamaIndex│├──────────────────────────────────────────────────────────────────┤│ Clients ││ Python SDK · TypeScript SDK · Go SDK · MCP server (TypeScript) ││ Transport: HTTP, or optionally an Aether relay │├──────────────────────────────────────────────────────────────────┤│ MemoryLayer server (FastAPI) `memorylayer` CLI ││ ┌────────────────────────────────────────────────────────────┐ ││ │ REST API /v1/* │ ││ ├────────────────────────────────────────────────────────────┤ ││ │ Services (plugins) │ ││ │ Memory · Recall · Reflect · Session · Context pack │ ││ │ Association · Ontology · Entity registry · Representation │ ││ │ Graph analysis · Knowledge base · Documents · Chat │ ││ │ Skills · MCP registry · Context environment · Tasks │ ││ ├────────────────────────────────────────────────────────────┤ ││ │ Server plugins: memorylayer-server-rpg (/v1/rpg) │ ││ ├────────────────────────────────────────────────────────────┤ ││ │ Storage: SQLite + sqlite-vec + FTS5 (optional Turso) │ ││ └────────────────────────────────────────────────────────────┘ │├──────────────────────────────────────────────────────────────────┤│ Peers: embedding provider (hash · embed-server · OpenAI · ││ Google) · LLM provider (OpenAI · Anthropic · Google · ││ Fireworks) │└──────────────────────────────────────────────────────────────────┘Editions
MemoryLayer comes in three open-source, self-hosted editions. See Editions & Licensing for the full comparison.
| Edition | License | Role in the architecture |
|---|---|---|
| MemoryLayer (core) | Apache-2.0 | Everything on this page unless marked otherwise: the server, the full retrieval engine, SDKs, the MCP server, agent-host plugins, the embed server, and the RPG plugin |
| MemoryLayer Enterprise | AGPL-3.0-only | Replaces the storage substrate (PostgreSQL + pgvector + Apache AGE + pg_textsearch) and adds background workers, tiering, datasets, collections, trajectories, data connectors, tenant and admin services, and an admin dashboard |
| MemoryLayer Storage | AGPL-3.0-only (Python client Apache-2.0) | Content-addressed object storage and a POSIX filesystem with deduplication and compression. Enterprise uses it for blob storage. |
The retrieval engine is entirely in core: hybrid search, retrieval channels, the knowledge graph, the entity registry, perspective, reflection, temporal recall, the knowledge base, and the context sandbox. Enterprise does not unlock retrieval features. It swaps the storage and task substrate underneath them and adds what you need to run memory as shared production infrastructure.
Clients
All clients wrap the same REST API.
| Client | Package | Notes |
|---|---|---|
| Python SDK | memorylayer-client | Async MemoryLayerClient and SyncMemoryLayerClient; Pydantic models; optional Aether transport |
| TypeScript SDK | @scitrera/memorylayer-sdk | fetch-based; typed errors; browser-safe bundle |
| Go SDK | github.com/scitrera/memorylayer/memorylayer-sdk-go | context.Context-aware; a nested aether/ module provides an Aether-relay transport. See Go SDK. |
| MCP server | @scitrera/memorylayer-mcp-server | A separate process that wraps the TypeScript SDK |
The SDKs expose namespaces for memories, sessions, workspaces, entities, skills, MCP servers, the knowledge base (kb), and RPG (rpg). On-behalf-of authority can be attached per request.
MCP Server
MCP client (Claude, Codex, …) ←→ MCP server ←→ TypeScript SDK ←→ REST API ←→ MemoryLayer serverThe MCP server offers tool profiles, selected with MEMORYLAYER_TOOL_PROFILE:
| Profile | Tools | Contents |
|---|---|---|
cc (default) | 28 | Core memory (remember, recall, reflect, forget, briefing); sessions (session_start, session_end, session_commit, session_status, session_checkpoint); context_pack and context_delta; 8 context-environment tools; 4 chat-thread tools; 4 read-only skills tools |
full | 40 | Everything in cc, plus associate, statistics, graph_query, audit, chat_thread_decompose, chat_thread_delete, skills_save, and 5 MCP-server registry tools |
minimal | 2 | remember, recall |
Agent-Host Plugins
The Claude Code and OpenCode plugins add session briefings, recall hooks, and pre-compaction transcript capture on top of the MCP server. The Codex plugin connects Codex to MemoryLayer through MCP. The OpenClaw plugin backs OpenClaw’s memory capability directly through the TypeScript SDK. See the Integrations pages.
Server
memorylayer serve runs a FastAPI application on port 61001. The same memorylayer CLI also provides export, import, info, version, and the skills and mcp registry command groups (see CLI). memorylayer-eval is the retrieval evaluation harness.
Key Endpoints
| Endpoint | Description |
|---|---|
POST /v1/memories | Store a memory |
POST /v1/memories/recall | Hybrid recall |
POST /v1/memories/reflect | LLM synthesis across memories |
POST /v1/memories/batch | Batch create, update, and delete |
POST /v1/memories/{id}/associate | Create a typed relationship |
POST /v1/memories/{id}/traverse | Graph traversal from a memory |
POST /v1/sessions | Create a working-memory session |
POST /v1/sessions/{id}/commit | Commit a session to long-term memory |
POST /v1/sessions/{id}/context-pack | Budgeted resume bundle (sessions) |
POST /v1/workspaces | Create a workspace |
/v1/entities/* | Entity registry |
POST /v1/representation | Perspective assembly |
/v1/graph/* | Graph analysis |
/v1/knowledgebase/* | Knowledge base generation and export |
/v1/documents/*, POST /v1/ingest/email | Ingestion |
/v1/threads/* | Chat threads |
/v1/skills/*, /v1/mcp-servers/* | Skills and MCP registries |
/v1/context/* | Context environment sandbox |
/v1/rpg/* | Repository Planning Graph (plugin) |
Service Layer
Business logic is organized into focused services. Each is loaded as a plugin through an extension point, and most can be replaced through a MEMORYLAYER_* setting.
| Service | Responsibility |
|---|---|
| MemoryService | Remember, recall, and forget. Coordinates embedding, deduplication, storage, user-scope routing, entity accretion, and the post-store enrichment pipeline. |
| ReflectService | LLM synthesis over recalled memories, with source citations |
| SessionService | Working-memory lifecycle: create, touch, commit, expire. Persistent by default. |
| ContextPackService | Checkpoints, budgeted context packs, and signed delta cursors |
| WorkspaceService | Workspace and context CRUD, export and import, transactional purge |
| AssociationService | Typed relationship graph, auto-association, traversal |
| OntologyService | 85 base relationship types in 12 categories, memory subtypes, and entity types. Plugins can extend all three. |
| EntityRegistryService | Canonical entities, aliases, member accretion, merge, dedup, provenance |
| EntityLinkerService | External knowledge-base linking (a no-op in core; Wikidata in Enterprise) |
| EntityRelationService | Typed entity relations and bounded relational recall |
| RepresentationService | Observer/subject perspective and user self-representation |
| InferenceService | Derived inference insights about entities |
| GraphAnalysisService / GraphQueryService | Communities, centrality, bridges; entity neighbourhoods |
| KnowledgebaseService | Knowledge-base article generation, OKF front matter, coverage |
| EmbeddingService | Pluggable providers: hash (default, lexical), embed_server, openai, google |
| LLMService | Pluggable LLM providers and profiles, gated by the generation policy |
| ExtractionService | Fact decomposition, classification, and entity extraction |
| DeduplicationService | Content-hash and semantic duplicate detection (skip, update, merge, or create) |
| ContradictionService | Contradiction detection and resolution |
| SemanticTieringService | Abstract and overview tiers for progressive detail |
| DecayService | Importance decay; pinned memories are exempt |
| RerankerService | Optional reranking (none by default) and MMR diversification |
| CacheService | Recall-result caching (in-process LRU by default) |
| DocumentService | Document parsing, pages, chunking, ColPali page search |
| ChatService | Chat threads, ownership, decomposition, and idle policy |
| SkillsService / McpServersService | Scoped registries with precedence resolution |
| ContextEnvironmentService | Server-side Python sandbox and RLM |
| TaskService | Background tasks: enrichment, decomposition, tiering, cleanup, decay |
Storage Layer
- SQLite is the default store (
MEMORYLAYER_STORAGE_BACKEND=sqlite). It holds memories, associations, sessions, workspaces, entities, documents, skills, threads, and the rest in a single database file in WAL mode. - sqlite-vec provides vector search. When it is unavailable, the server falls back to Python cosine similarity. Embeddings are stored as plain BLOBs, so the schema does not depend on the embedding dimension. Mixing dimensions in one workspace breaks vector search, however: changing the embedding model means re-embedding.
- FTS5 provides full-text (BM25) search with Porter stemming, including memory aliases.
- Turso / libSQL is an optional backend (
memorylayer-server[turso]) with local, remote, and embedded-replica modes.
Request Flow
Remember (Write Path)
Client → REST API (validate, authenticate, authorize) → MemoryService.remember() → Route scope (workspace, or user → _global_user) → Content hash + embedding → Deduplication: SKIP · UPDATE · MERGE · CREATE → Store (StorageBackend) → Entity accretion (if the entity registry is enabled) → Post-store enrichment (inline or as background tasks; MEMORYLAYER_POST_STORE_ENRICHMENT_ENABLED): semantic tiers · contradiction check · auto-association · fact decomposition · relationship classification ← MemoryRecall (Read Path)
Client → REST API → MemoryService.recall() → Recall cache → Query intent (rule-based: entity / temporal / event / general) softly tunes recency, alias boosts, graph expansion, date window → Candidate channels, fused by Reciprocal Rank Fusion: vector (sqlite-vec) + keyword (FTS5/BM25) [on] entity-anchored [on] fact · graph traversal · cue · registry [off by default] bounded typed-relation recall [on] → Scope, recency, alias, and backlink boosts → Association expansion (BFS) → Rerank or MMR (optional), truncate to limit → Detail level + token budget → match_signals, trust, freshness, retrieval_confidence ← RecallResultllm and hybrid recall modes add LLM query rewriting. agentic is an iterative loop implemented in MemoryLayer Enterprise. See Recall & Retrieval.
Reflect (Synthesis Path)
Client → REST API → ReflectService → recall relevant memories → LLM synthesis → ReflectResult (+ source IDs)Plugin Architecture
Every service is registered against a named extension point and resolved at startup, based on configuration. For example, MEMORYLAYER_STORAGE_BACKEND=sqlite selects the SQLite storage plugin. MemoryLayer Enterprise uses the same seams to swap in PostgreSQL storage, Redis caching, worker-backed tasks, and its own entity-registry and graph-query backends, without changing application code.
Server plugins are Python packages that register the memorylayer_server.plugin_packages entry point. Installing one is enough: the server scans it and registers its API routers, services, task handlers, and ontology contributions. The RPG plugin (memorylayer-server-rpg) works this way. It adds /v1/rpg, its task handlers, 9 memory subtypes, and 12 code_structure relationship types through an OntologyContributorPlugin.
Semantic Tiers
Each memory can be returned at three detail levels: abstract (a brief summary), overview (a high-level overview), and full (the complete content). Tiers are generated after a memory is stored, and recall and briefings choose a level with detail_level to save context.
Deployment
Local Development
Single process, a single SQLite file, no API key:
pip install memorylayer-servermemorylayer serveThe default hash embedding provider is lexical, not semantic. Add a memorylayer-embed-server peer or a cloud embedding provider for real retrieval quality, or run docker compose up to get the server plus a CPU embed-server peer. The official Docker image ships all optional dependencies and the RPG plugin.
Production
MemoryLayer Enterprise (AGPL-3.0, self-hosted) adds the production substrate: PostgreSQL with pgvector, Apache AGE, and pg_textsearch; a Redis cache; dedicated memorylayer-worker processes; hot/cold memory tiering; data connectors; and tenant, user, and admin services with an admin dashboard. It installs as container images. See Enterprise installation.