Skip to content

Memlink system · detailed

flowchart TD
  subgraph API["Inbound API · http_router + handlers · scope-HMAC auth (memlink-scope, RFC 0091)"]
    direction TB
    EP_ING["POST /ingest"]
    EP_RET["POST /retrieve"]
    EP_DISP["POST /dispatch-derivation"]
    EP_CONS["POST /v1/morpheus/consolidate · run_luna_consolidation"]
    EP_SAGE["POST /sage-writer-persist"]
    EP_ADMIN["admin · reconcile-singular-facts · repair-owner-memory · detect-anomalies"]
  end

  subgraph WR["Ingest / write path"]
    direction TB
    ING["IngestEventUseCase"]
    RAW["store raw event"]
    FAST["Fast-lane derivation · sync<br/>derive_fast_lane_records"]
    FCAND["fact candidates · slot/value"]
    ECAND["entity candidates + dedupe"]
    RCAND["relation candidates · gated"]
    PERS["persist_derived_records<br/>+ object_provenance"]
    ENQ["enqueue async jobs<br/>derive_event · embed_object"]
    ING --> RAW --> FAST
    FAST --> FCAND --> PERS
    FAST --> ECAND --> PERS
    FAST --> RCAND --> PERS
    PERS --> ENQ
  end

  subgraph WK["Async derivation workers · poll asc_jobs"]
    direction TB
    DWORK["DerivationWorkerService<br/>claim job"]
    DERV["derive_event → DispatchDerivationUseCase<br/>LLM extraction · sanitize · resolve relations"]
    EMBJ["embed_object → EmbedObjectUseCase"]
    EPROV["EmbeddingProvider<br/>OpenAI text-embedding-3 · 3072-d · content_hash"]
    DWORK --> DERV --> EMBJ --> EPROV
  end

  subgraph RD["Retrieve / read path"]
    direction TB
    RBUN["RetrieveSupportBundleUseCase"]
    RROUTE["RetrievalRouter · opt<br/>classify → RouteKind → executor"]
    RPOL["retrieval_policy<br/>class: identity / profile / fact / event / entity"]
    subgraph HS["Hybrid candidate search · consolidations_repository.search_support"]
      direction TB
      LEX["Lexical · FTS (GIN search_tsv)"]
      SEM["Semantic · pgvector HNSW cosine<br/>(embed query once)"]
      PPR["Personalized PageRank<br/>edges_from_relations · ≤2 hops · decay"]
      RRF["RRF fusion · k=60"]
      LEX --> RRF
      SEM --> RRF
      PPR --> RRF
    end
    RANK["Ranker · 7-signal blend<br/>lexical · semantic · recency · importance<br/>provenance · kind · subkind"]
    RERANK["Reranker · EmbeddingCosine ·or· Null"]
    TRUST["Trust-grade · structured beats raw<br/>fact > entity/relation > episode > chat"]
    CREC["Comprehensive recall · RFC 0102<br/>evidence-gated graph walk"]
    HYD["Hydrate + assemble_runtime_context<br/>SupportEvidence · budget cap · group by kind"]
    RESP["RetrievalSupportBundleResponse<br/>objects · provenance · metadata"]
    RBUN --> RROUTE --> RPOL --> LEX
    RRF --> RANK --> RERANK --> TRUST --> CREC --> HYD --> RESP
  end

  subgraph CS["Luna · consolidation · SAGE · self-heal · auto (LUNA_AUTO)"]
    direction TB
    CONS["RunLunaConsolidationUseCase"]
    CLLM["Luna LLM · Anthropic · luna_consolidation_llm<br/>deterministic fallback"]
    SAGER["sage_reader_signals"]
    SAGEP["sage_writer_proposals"]
    SAGEW["sage_writer_persist<br/>≤3/pass · origin=sage_reinforcement · gated"]
    RECON["reconcile_singular_facts<br/>reconcile_owner_memory_quality"]
    ANOM["detect_memory_anomalies · read-only"]
    CONS --> CLLM
    CONS --> SAGER --> SAGEP --> SAGEW
    CONS --> RECON
    CONS --> ANOM
  end

  subgraph ST["Postgres + pgvector · ONE database · multiple schemas"]
    direction TB
    subgraph SWO["world.* — memory graph · 27 tables"]
      direction TB
      T1[("events_raw")]
      T2[("facts · candidate→current→superseded")]
      T3[("entities · canonical")]
      T4[("relations · typed · bitemporal")]
      T5[("episodes")]
      T6[("consolidations")]
      T7[("object_embeddings · HNSW")]
      T8[("object_provenance")]
      T9[("asc_jobs queue")]
      T1 ~~~ T2 ~~~ T3 ~~~ T4 ~~~ T5 ~~~ T6 ~~~ T7 ~~~ T8 ~~~ T9
    end
    subgraph SST["steelmoth.* — AGENT / runtime · 57 tables"]
      direction TB
      A1[("chat_turns · stream_events · reasoning · hints · affordances · memlink_links")]
      A2[("agent_self_events")]
      A3[("living_documents + revisions")]
      A4[("morpheus_memories · morpheus_run_audit")]
      A5[("governance_decisions · settings_audit · write_action_audit · write_approval_tokens · runtime_context_audit")]
      A6[("mail_* · messages · threads · folders · flags · labels · send_intents · approval_grants · audit · cursors · triage")]
      A7[("clients · access_requests · provisioning_jobs · teardown_jobs · pool_slots · agreements")]
      A8[("provider_accounts · provider_grants · mail_accounts")]
      A9[("channel_bindings · telegram_* routes / idempotency / nonces")]
      A10[("llm_usage_event · notification_outbox · skills · attachments · sidecar_runs · user_settings_profile · runtime_overrides")]
      A1 ~~~ A2 ~~~ A3 ~~~ A4 ~~~ A5 ~~~ A6 ~~~ A7 ~~~ A8 ~~~ A9 ~~~ A10
    end
    subgraph SCO["core.* — identity / infra · 11 tables"]
      direction TB
      C1[("owner_identity")]
      C2[("lane_policy · owner/shared/system/agent")]
      C3[("browser_client + context + blob")]
      C4[("telegram_dashboard_connection · operator_link")]
      C5[("vault_lookup_audit")]
      C6[("terminal_runs · terminal_bridge_state")]
      C7[("eval_goldens")]
      C1 ~~~ C2 ~~~ C3 ~~~ C4 ~~~ C5 ~~~ C6 ~~~ C7
    end
    subgraph SOA["operator_authority.* — agent authority · 7 tables"]
      direction TB
      O1[("scope_manifests")]
      O2[("approval_requests · task_plans")]
      O3[("sessions · settings · projector_health")]
      O4[("violations")]
      O1 ~~~ O2 ~~~ O3 ~~~ O4
    end
    subgraph SMO["moth.* — legacy"]
      direction TB
      MO1[("legacy · reminders · google identity")]
    end
  end

  OAI["OpenAI embeddings<br/>key via prontera broker"]
  ANT["Anthropic<br/>via observability proxy"]

  EP_ING --> ING
  EP_RET --> RBUN
  EP_DISP --> DWORK
  EP_CONS --> CONS
  EP_SAGE --> SAGEW
  EP_ADMIN --> RECON
  EP_ADMIN --> ANOM

  RAW --> T1
  PERS -->|facts · entities · relations · provenance| T2
  ENQ --> T9
  T9 -.poll.-> DWORK
  EPROV --> T7
  EPROV -.embed call.-> OAI

  LEX -.reads.-> T2
  SEM -.reads.-> T7
  PPR -.reads.-> T4
  HYD -.hydrate.-> T8

  CONS -.reads.-> A2
  CONS --> A3
  CONS --> A4
  SAGEW --> T4
  CLLM -.generate.-> ANT

  style API fill:#ecfeff,stroke:#0c8ea4,stroke-width:2px,color:#0c8ea4
  style WR fill:#eef9f2,stroke:#1f9d63,stroke-width:2px,color:#1f9d63
  style WK fill:#f5f4f2,stroke:#78716c,stroke-width:2px,color:#78716c
  style RD fill:#eef3ff,stroke:#2f6df6,stroke-width:2px,color:#2f6df6
  style HS fill:#eef3ff,stroke:#2f6df6,stroke-width:1px,color:#2f6df6
  style CS fill:#fdf2f8,stroke:#be185d,stroke-width:2px,color:#be185d
  style ST fill:#f4f1ff,stroke:#7c5cff,stroke-width:2px,color:#7c5cff
  style SWO fill:#f4f1ff,stroke:#7c5cff,stroke-width:1px,color:#7c5cff
  style SST fill:#f4f1ff,stroke:#7c5cff,stroke-width:1px,color:#7c5cff
  style SCO fill:#f4f1ff,stroke:#7c5cff,stroke-width:1px,color:#7c5cff
  style SOA fill:#f4f1ff,stroke:#7c5cff,stroke-width:1px,color:#7c5cff
  style SMO fill:#f4f1ff,stroke:#7c5cff,stroke-width:1px,color:#7c5cff
  classDef apiN fill:#ffffff,stroke:#0c8ea4,color:#27272a,stroke-width:1px
  classDef wrN fill:#ffffff,stroke:#1f9d63,color:#27272a,stroke-width:1px
  classDef wkN fill:#ffffff,stroke:#78716c,color:#27272a,stroke-width:1px
  classDef rdN fill:#ffffff,stroke:#2f6df6,color:#27272a,stroke-width:1px
  classDef csN fill:#ffffff,stroke:#be185d,color:#27272a,stroke-width:1px
  classDef stN fill:#ffffff,stroke:#7c5cff,color:#27272a,stroke-width:1px
  classDef exN fill:#ffffff,stroke:#475569,color:#27272a,stroke-width:1px
  class EP_ING,EP_RET,EP_DISP,EP_CONS,EP_SAGE,EP_ADMIN apiN
  class ING,RAW,FAST,FCAND,ECAND,RCAND,PERS,ENQ wrN
  class DWORK,DERV,EMBJ,EPROV wkN
  class RBUN,RROUTE,RPOL,LEX,SEM,PPR,RRF,RANK,RERANK,TRUST,CREC,HYD,RESP rdN
  class CONS,CLLM,SAGER,SAGEP,SAGEW,RECON,ANOM csN
  class T1,T2,T3,T4,T5,T6,T7,T8,T9,A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,C1,C2,C3,C4,C5,C6,C7,O1,O2,O3,O4,MO1 stN
  class OAI,ANT exN