How sparkhello/memory_platform works
Memory Platform is a local-first memory proxy between OpenAI-compatible chat clients and model providers. Its main workflow routes a chat turn through Memory Gateway, recalls relevant memories, sends the request to Model Gateway for provider routing, then conservatively extracts and stores eligible facts after the answer. The product also includes an administrative web console, explicit MCP and REST knowledge access, and an Android-hosted runtime. Some subsystem links are documented in the README; source excerpts and the index support the implementation links shown here, but unsampled internals are not inferred.
Main entry points: main.py HTTP app · chat_gateway.py Chat endpoint · service.py Model API · client.py LLM client
Components 22
Memory Gateway
- HTTP app
services/memory-gateway/app/main.py - Chat endpoint
services/memory-gateway/app/api/chat_gateway.py - Memory search
services/memory-gateway/app/memory/search.py - Fact extraction
services/memory-gateway/app/memory/ingest.py - Memory store
services/memory-gateway/app/memory/store/repository.py - Access tokens
services/memory-gateway/app/auth/tokens.py - LLM client
services/memory-gateway/app/llm/client.py - Model runtime
services/memory-gateway/app/llm/runtime.py - Embedding contract
services/memory-gateway/app/llm/embedding_contract.py - Usage attribution
services/memory-gateway/app/usage/attribution.py
Model Gateway
- Model API
services/model-gateway/model_gateway/service.py - Request routing
services/model-gateway/model_gateway/routing.py - Control plane
services/model-gateway/model_gateway/control_plane.py - Gateway config
services/model-gateway/model_gateway/config_store.py
Knowledge Access
- MCP tools
services/memory-gateway/app/mcp_server/server.py - Knowledge agent
services/memory-gateway/app/knowledge/agent.py - Document retrieval
services/memory-gateway/app/knowledge/retrieval.py
Administration
- Web console
services/memory-gateway/ui/src/App.tsx
Android Runtime
- Background service
apps/android/app/src/main/java/app/memoryplatform/android/GatewayService.kt - Embedded stack
apps/android/app/src/main/python/embedded_stack.py
Other components
- Chat client
- Model provider
Connections 20
- Chat client → HTTP app: sends chat
- HTTP app → Chat endpoint: routes requests
services/memory-gateway/app/main.py - Chat endpoint → Memory search: recalls memories
- Chat endpoint → LLM client: requests completion
- LLM client → Model runtime: resolves route
services/memory-gateway/app/llm/client.py - LLM client → Model API: posts request
services/memory-gateway/app/llm/client.py - Model API → Request routing: routes model
services/model-gateway/model_gateway/service.py - Model API → Control plane: serves control API
services/model-gateway/model_gateway/service.py - Model API → Gateway config: reads configuration
services/model-gateway/model_gateway/service.py - Request routing → Model provider: dispatches upstream
- Chat endpoint → Fact extraction: extracts after answer
- Fact extraction → Memory store: resolves and saves
services/memory-gateway/app/memory/ingest.py - Memory search → Memory store: queries memories
- HTTP app → Access tokens: authenticates requests
services/memory-gateway/app/main.py - HTTP app → Web console: mounts console
services/memory-gateway/app/main.py - Chat client → MCP tools: uses optional tools
- MCP tools → Knowledge agent: uses knowledge tools
services/memory-gateway/app/mcp_server/server.py - MCP tools → Document retrieval: searches documents
services/memory-gateway/app/mcp_server/server.py - Knowledge agent → Document retrieval: selects excerpts
- Background service → Embedded stack: starts and stops
apps/android/app/src/main/java/app/memoryplatform/android/GatewayService.kt