# shadow-weave/hms architecture

> Architecture diagram of the GitHub repository shadow-weave/hms, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shadow-weave/hms
- Repository: https://github.com/shadow-weave/hms

## Overview

#### Purpose and Primary Entry Points
HMS is a structured long-term memory platform and LongMemEval research harness. It retains conversations/documents as structured memory, recalls evidence, organizes it for grounded LLM answers, and can judge benchmark outputs.

Primary runtime entry points:
- Benchmark orchestration: `.aaaSCRIPT/run_benchmark.sh`, `lab/evaluation/benchmarks/longmemeval/longmemeval_benchmark.py`
- Python dataplane service: `core/dataplane/hms_api/main.py`, `core/dataplane/hms_api/server.py`
- Automatic-memory demo: `scripts/run_memory_demo.sh`, `examples/automatic_memory/openai_responses.py`
- Embedded/local deployment API: `core/local-suite/hms/embedded.py`, `core/local-suite/hms/server.py`

#### API and Client Boundary
The dataplane exposes HTTP and MCP-facing APIs, with request models and service wiring separated from the memory engine. External consumers can use generated SDKs, a Rust CLI, framework adapters, or the Next.js console.
- API surfaces: `core/dataplane/hms_api/api/http.py`, `core/dataplane/hms_api/api/mcp.py`, `core/dataplane/hms_api/mcp_tools.py`
- Clients/interfaces: `interface/sdk/python/hms_client/hms_client.py`, `interface/cli/src/main.rs`, `interface/console/src/lib/hms-client.ts`
- Agent integrations wrap or expose retain/recall/reflect tools across ecosystems; the LiteLLM wrapper supports automatic context injection and exchange retention: `interface/adapters/litellm/hms_litellm/wrappers.py`, `interface/adapters/openai-agents/hms_openai_agents/tools.py`

#### Core Memory Engine
`MemoryEngine` is the application-level coordination boundary between API operations and storage/LLM capabilities. It manages banks (per-user or per-tenant memory partitions), request/response schemas, operation metadata, and policy/config resolution.
- Engine contracts and coordinator: `core/dataplane/hms_api/engine/interface.py`, `core/dataplane/hms_api/engine/memory_engine.py`, `core/dataplane/hms_api/engine/schema.py`
- Runtime configuration and provider selection: `core/dataplane/hms_api/config.py`, `core/dataplane/hms_api/config_resolver.py`
- Extension hooks provide tenant, HTTP, MCP, and operation-validation customization: `core/dataplane/hms_api/extensions/loader.py`, `core/dataplane/hms_api/extensions/tenant.py`

#### Retain/Ingestion Pipeline
Retain transforms text or files into durable memory: parse documents where applicable, chunk content, extract facts/entities via LLM, generate embeddings, store facts/chunks, and create memory links. This is the write-path boundary where raw source material becomes searchable structured knowledge.
- Orchestration: `core/dataplane/hms_api/engine/retain/orchestrator.py`
- Fact/entity/link stages: `core/dataplane/hms_api/engine/retain/fact_extraction.py`, `core/dataplane/hms_api/engine/retain/entity_processing.py`, `core/dataplane/hms_api/engine/retain/link_creation.py`
- File parsing and storage abstraction: `core/dataplane/hms_api/engine/parsers/base.py`, `core/dataplane/hms_api/engine/storage/base.py`

#### Recall, Evidence Organization, and Reflection
Recall combines vector, graph/link-expansion, temporal, tag, query-rewrite, fusion, and reranking strategies. The benchmark’s ledger/self-evolution modes consume retrieved material to construct answer-time evidence and grounded answers. Reflection is a separate LLM-agent path that derives or updates observations/mental models using structured tools.
- Search strategy composition: `core/dataplane/hms_api/engine/search/module_manager.py`, `core/dataplane/hms_api/engine/search/retrieval.py`, `core/dataplane/hms_api/engine/search/fusion.py`
- Graph and reranking stages: `core/dataplane/hms_api/engine/search/graph_retrieval.py`, `core/dataplane/hms_api/engine/search/reranking.py`
- Reflect agent and delta application: `core/dataplane/hms_api/engine/reflect/agent.py`, `core/dataplane/hms_api/engine/reflect/delta_ops.py`

#### Persistence, Async Work, and External Services
PostgreSQL with pgvector is the principal system of record for banks, memory units, entities, links, operations, audit data, and vector indexes. Database access abstracts PostgreSQL and Oracle; Alembic owns schema evolution. Async retain and other long operations are persisted then executed by a poller/worker. Files can reside in PostgreSQL, S3, GCS, or Azure storage.
- DB abstraction: `core/dataplane/hms_api/engine/db/base.py`, `core/dataplane/hms_api/engine/db/ops_postgresql.py`, `core/dataplane/hms_api/alembic/env.py`
- Worker lifecycle: `core/dataplane/hms_api/worker/main.py`, `core/dataplane/hms_api/worker/poller.py`
- LLM/embedding providers include OpenAI-compatible, Anthropic, Gemini, LiteLLM, llama.cpp, and local rerankers: `core/dataplane/hms_api/engine/providers/openai_compatible_llm.py`, `core/dataplane/hms_api/engine/embeddings.py`

#### Deployment and Observability
The system is deployable as Docker Compose or Helm workloads: API, worker, PostgreSQL, and optional TEI embedding/reranking services. Webhooks, auditing, metrics, tracing, and Grafana dashboards support operational integration.
- Helm topology: `deploy/charts/hms/templates/api-deployment.yaml`, `deploy/charts/hms/templates/worker-statefulset.yaml`, `deploy/charts/hms/templates/tei-embedding-deployment.yaml`
- Docker entry deployment: `docker-compose.yml`, `deploy/containers/standalone/start-all.sh`
- Operational signals: `core/dataplane/hms_api/metrics.py`, `core/dataplane/hms_api/tracing.py`, `core/dataplane/hms_api/webhooks/manager.py`

Main entry points: [`core/dataplane/hms_api/engine/memory_engine.py`](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/memory_engine.py) (MemoryEngine), [`core/dataplane/hms_api/api/http.py`](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/api/http.py) (HTTP & MCP APIs), [`core/dataplane/hms_api/engine/db/ops_postgresql.py`](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/db/ops_postgresql.py) (PostgreSQL + pgvector), [`core/dataplane/hms_api/engine/retain/orchestrator.py`](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/retain/orchestrator.py) (Retain orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entrypoints["Entry Points"]
  node_benchmark["LongMemEval benchmark<br/>evaluation harness"]
  node_memory_demo["Automatic memory demo<br/>example client"]
  node_embedded_api["Embedded deployment API<br/>local runtime<br/>[embedded.py]"]
end

subgraph group_interfaces["API &amp; Clients"]
  node_dataplane_server["Dataplane server<br/>Python service<br/>[server.py]"]
  node_http_mcp_api["HTTP &amp; MCP APIs<br/>API surface<br/>[http.py]"]
  node_client_interfaces["SDKs, CLI &amp; console<br/>consumer interfaces<br/>[hms_client.py]"]
  node_agent_adapters["Agent adapters<br/>integration tools<br/>[wrappers.py]"]
end

subgraph group_engine["Memory Engine"]
  node_memory_engine{{"MemoryEngine<br/>application coordinator<br/>[memory_engine.py]"}}
  node_engine_contracts["Engine contracts &amp; schemas<br/>operation models<br/>[interface.py]"]
  node_config_extensions["Config &amp; extensions<br/>runtime policy<br/>[config_resolver.py]"]
end

subgraph group_pipelines["Memory Pipelines"]
  node_retain_pipeline["Retain orchestration<br/>ingestion pipeline<br/>[orchestrator.py]"]
  node_fact_entity_linking["Facts, entities &amp; links<br/>knowledge extraction<br/>[fact_extraction.py]"]
  node_file_storage["File parsing &amp; storage<br/>content abstraction<br/>[base.py]"]
  node_recall_pipeline["Recall composition<br/>retrieval pipeline<br/>[retrieval.py]"]
  node_graph_reranking["Graph retrieval &amp; reranking<br/>evidence refinement<br/>[graph_retrieval.py]"]
  node_reflect_agent["Reflection agent<br/>LLM agent<br/>[agent.py]"]
end

subgraph group_platform["Persistence &amp; Operations"]
  node_operation_worker["Async operation worker<br/>background worker<br/>[poller.py]"]
  node_database[("PostgreSQL + pgvector<br/>system of record<br/>[ops_postgresql.py]")]
  node_llm_providers["LLM &amp; embedding providers<br/>AI providers"]
  node_observability["Webhooks &amp; observability<br/>operational signals<br/>[metrics.py]"]
  node_deployment["Compose &amp; Helm deployment<br/>deployment topology<br/>[docker-compose.yml]"]
end

node_benchmark -->|"exercises"| node_http_mcp_api
node_memory_demo -->|"uses"| node_agent_adapters
node_embedded_api -->|"embeds"| node_memory_engine
node_client_interfaces -->|"calls"| node_http_mcp_api
node_agent_adapters -->|"invokes tools"| node_http_mcp_api
node_dataplane_server -->|"serves"| node_http_mcp_api
node_http_mcp_api -->|"dispatches operations"| node_memory_engine
node_memory_engine -->|"uses"| node_engine_contracts
node_config_extensions -.->|"configures"| node_memory_engine
node_memory_engine -->|"retain"| node_retain_pipeline
node_memory_engine -->|"recall"| node_recall_pipeline
node_memory_engine -->|"reflect"| node_reflect_agent
node_retain_pipeline -->|"parses source"| node_file_storage
node_retain_pipeline -->|"extracts"| node_fact_entity_linking
node_fact_entity_linking -->|"persists memory graph"| node_database
node_recall_pipeline -->|"refines evidence"| node_graph_reranking
node_graph_reranking -->|"searches"| node_database
node_reflect_agent -->|"applies deltas"| node_database
node_retain_pipeline -->|"extracts &amp; embeds"| node_llm_providers
node_recall_pipeline -->|"rewrites &amp; reranks"| node_llm_providers
node_memory_engine -->|"queues long operations"| node_operation_worker
node_operation_worker -->|"polls &amp; updates"| node_database
node_dataplane_server -.->|"emits signals"| node_observability
node_deployment -->|"deploys"| node_dataplane_server
node_deployment -->|"deploys"| node_operation_worker
node_deployment -->|"provisions"| node_database

click node_benchmark "https://github.com/shadow-weave/hms/blob/main/lab/evaluation/benchmarks/longmemeval/longmemeval_benchmark.py"
click node_memory_demo "https://github.com/shadow-weave/hms/blob/main/examples/automatic_memory/openai_responses.py"
click node_embedded_api "https://github.com/shadow-weave/hms/blob/main/core/local-suite/hms/embedded.py"
click node_dataplane_server "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/server.py"
click node_http_mcp_api "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/api/http.py"
click node_client_interfaces "https://github.com/shadow-weave/hms/blob/main/interface/sdk/python/hms_client/hms_client.py"
click node_agent_adapters "https://github.com/shadow-weave/hms/blob/main/interface/adapters/litellm/hms_litellm/wrappers.py"
click node_memory_engine "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/memory_engine.py"
click node_engine_contracts "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/interface.py"
click node_config_extensions "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/config_resolver.py"
click node_retain_pipeline "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/retain/orchestrator.py"
click node_fact_entity_linking "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/retain/fact_extraction.py"
click node_file_storage "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/parsers/base.py"
click node_recall_pipeline "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/search/retrieval.py"
click node_graph_reranking "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/search/graph_retrieval.py"
click node_reflect_agent "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/reflect/agent.py"
click node_operation_worker "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/worker/poller.py"
click node_database "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/db/ops_postgresql.py"
click node_llm_providers "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/providers/openai_compatible_llm.py"
click node_observability "https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/metrics.py"
click node_deployment "https://github.com/shadow-weave/hms/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_benchmark,node_memory_demo,node_embedded_api toneBlue
class node_dataplane_server,node_http_mcp_api,node_client_interfaces,node_agent_adapters toneAmber
class node_memory_engine,node_engine_contracts,node_config_extensions toneMint
class node_retain_pipeline,node_fact_entity_linking,node_file_storage,node_recall_pipeline,node_graph_reranking,node_reflect_agent toneRose
class node_operation_worker,node_database,node_llm_providers,node_observability,node_deployment toneIndigo
```

## Components

### Entry Points

- [LongMemEval benchmark](https://github.com/shadow-weave/hms/blob/main/lab/evaluation/benchmarks/longmemeval/longmemeval_benchmark.py): evaluation harness · Orchestrates retrieval, evidence, answers, and judging modes. · `lab/evaluation/benchmarks/longmemeval/longmemeval_benchmark.py`
- [Automatic memory demo](https://github.com/shadow-weave/hms/blob/main/examples/automatic_memory/openai_responses.py): example client · `examples/automatic_memory/openai_responses.py`
- [Embedded deployment API](https://github.com/shadow-weave/hms/blob/main/core/local-suite/hms/embedded.py): local runtime · `core/local-suite/hms/embedded.py`

### API & Clients

- [Dataplane server](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/server.py): Python service · `core/dataplane/hms_api/server.py`
- [HTTP & MCP APIs](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/api/http.py): API surface · `core/dataplane/hms_api/api/http.py`
- [SDKs, CLI & console](https://github.com/shadow-weave/hms/blob/main/interface/sdk/python/hms_client/hms_client.py): consumer interfaces · `interface/sdk/python/hms_client/hms_client.py`
- [Agent adapters](https://github.com/shadow-weave/hms/blob/main/interface/adapters/litellm/hms_litellm/wrappers.py): integration tools · Expose memory tools and automatic context/retention wrappers. · `interface/adapters/litellm/hms_litellm/wrappers.py`

### Memory Engine

- [MemoryEngine](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/memory_engine.py): application coordinator · Coordinates bank-scoped retain, recall, and reflect operations. · `core/dataplane/hms_api/engine/memory_engine.py`
- [Engine contracts & schemas](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/interface.py): operation models · `core/dataplane/hms_api/engine/interface.py`
- [Config & extensions](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/config_resolver.py): runtime policy · Resolves providers and tenant or operation customizations. · `core/dataplane/hms_api/config_resolver.py`

### Memory Pipelines

- [Retain orchestration](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/retain/orchestrator.py): ingestion pipeline · Turns source text and files into durable structured memory. · `core/dataplane/hms_api/engine/retain/orchestrator.py`
- [Facts, entities & links](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/retain/fact_extraction.py): knowledge extraction · `core/dataplane/hms_api/engine/retain/fact_extraction.py`
- [File parsing & storage](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/parsers/base.py): content abstraction · Parses files and supports database or object storage. · `core/dataplane/hms_api/engine/parsers/base.py`
- [Recall composition](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/search/retrieval.py): retrieval pipeline · Combines search modules, fusion, and result selection. · `core/dataplane/hms_api/engine/search/retrieval.py`
- [Graph retrieval & reranking](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/search/graph_retrieval.py): evidence refinement · `core/dataplane/hms_api/engine/search/graph_retrieval.py`
- [Reflection agent](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/reflect/agent.py): LLM agent · Derives observations and applies mental-model deltas. · `core/dataplane/hms_api/engine/reflect/agent.py`

### Persistence & Operations

- [Async operation worker](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/worker/poller.py): background worker · Polls persisted long-running operations including async retain. · `core/dataplane/hms_api/worker/poller.py`
- [PostgreSQL + pgvector](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/db/ops_postgresql.py): system of record · Stores banks, memory, entities, links, operations, audit data, and vectors. · `core/dataplane/hms_api/engine/db/ops_postgresql.py`
- [LLM & embedding providers](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/engine/providers/openai_compatible_llm.py): AI providers · Supplies extraction, generation, embeddings, and reranking. · `core/dataplane/hms_api/engine/providers/openai_compatible_llm.py`
- [Webhooks & observability](https://github.com/shadow-weave/hms/blob/main/core/dataplane/hms_api/metrics.py): operational signals · Emits metrics, traces, audits, and webhooks. · `core/dataplane/hms_api/metrics.py`
- [Compose & Helm deployment](https://github.com/shadow-weave/hms/blob/main/docker-compose.yml): deployment topology · Deploys API, worker, database, and optional TEI services. · `docker-compose.yml`

## Connections

- LongMemEval benchmark → HTTP & MCP APIs: exercises
- Automatic memory demo → Agent adapters: uses
- Embedded deployment API → MemoryEngine: embeds
- SDKs, CLI & console → HTTP & MCP APIs: calls
- Agent adapters → HTTP & MCP APIs: invokes tools
- Dataplane server → HTTP & MCP APIs: serves
- HTTP & MCP APIs → MemoryEngine: dispatches operations
- MemoryEngine → Engine contracts & schemas: uses
- Config & extensions → MemoryEngine: configures
- MemoryEngine → Retain orchestration: retain
- MemoryEngine → Recall composition: recall
- MemoryEngine → Reflection agent: reflect
- Retain orchestration → File parsing & storage: parses source
- Retain orchestration → Facts, entities & links: extracts
- Facts, entities & links → PostgreSQL + pgvector: persists memory graph
- Recall composition → Graph retrieval & reranking: refines evidence
- Graph retrieval & reranking → PostgreSQL + pgvector: searches
- Reflection agent → PostgreSQL + pgvector: applies deltas
- Retain orchestration → LLM & embedding providers: extracts & embeds
- Recall composition → LLM & embedding providers: rewrites & reranks
- MemoryEngine → Async operation worker: queues long operations
- Async operation worker → PostgreSQL + pgvector: polls & updates
- Dataplane server → Webhooks & observability: emits signals
- Compose & Helm deployment → Dataplane server: deploys
- Compose & Helm deployment → Async operation worker: deploys
- Compose & Helm deployment → PostgreSQL + pgvector: provisions
