How shadow-weave/hms works
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: memory_engine.py MemoryEngine · http.py HTTP & MCP APIs · ops_postgresql.py PostgreSQL + pgvector · orchestrator.py Retain orchestration
Components 21
Entry Points
- LongMemEval benchmark · Orchestrates retrieval, evidence, answers, and judging modes.
lab/evaluation/benchmarks/longmemeval/longmemeval_benchmark.py - Automatic memory demo
examples/automatic_memory/openai_responses.py - Embedded deployment API
core/local-suite/hms/embedded.py
API & Clients
- Dataplane server
core/dataplane/hms_api/server.py - HTTP & MCP APIs
core/dataplane/hms_api/api/http.py - SDKs, CLI & console
interface/sdk/python/hms_client/hms_client.py - Agent adapters · Expose memory tools and automatic context/retention wrappers.
interface/adapters/litellm/hms_litellm/wrappers.py
Memory Engine
- MemoryEngine · Coordinates bank-scoped retain, recall, and reflect operations.
core/dataplane/hms_api/engine/memory_engine.py - Engine contracts & schemas
core/dataplane/hms_api/engine/interface.py - Config & extensions · Resolves providers and tenant or operation customizations.
core/dataplane/hms_api/config_resolver.py
Memory Pipelines
- Retain orchestration · Turns source text and files into durable structured memory.
core/dataplane/hms_api/engine/retain/orchestrator.py - Facts, entities & links
core/dataplane/hms_api/engine/retain/fact_extraction.py - File parsing & storage · Parses files and supports database or object storage.
core/dataplane/hms_api/engine/parsers/base.py - Recall composition · Combines search modules, fusion, and result selection.
core/dataplane/hms_api/engine/search/retrieval.py - Graph retrieval & reranking
core/dataplane/hms_api/engine/search/graph_retrieval.py - Reflection agent · Derives observations and applies mental-model deltas.
core/dataplane/hms_api/engine/reflect/agent.py
Persistence & Operations
- Async operation worker · Polls persisted long-running operations including async retain.
core/dataplane/hms_api/worker/poller.py - PostgreSQL + pgvector · Stores banks, memory, entities, links, operations, audit data, and vectors.
core/dataplane/hms_api/engine/db/ops_postgresql.py - LLM & embedding providers · Supplies extraction, generation, embeddings, and reranking.
core/dataplane/hms_api/engine/providers/openai_compatible_llm.py - Webhooks & observability · Emits metrics, traces, audits, and webhooks.
core/dataplane/hms_api/metrics.py - Compose & Helm deployment · Deploys API, worker, database, and optional TEI services.
docker-compose.yml
Connections 26
- 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