MoralStack Module Documentation
This directory contains detailed documentation for each module of the MoralStack system.
For readers : The documentation is intended for developers, testers and stakeholders who need to understand what
each
component does, how it integrates into the flow and how to verify it. Each module is described with interfaces, data
structures and
usage examples.
Module
File
Description
Orchestrator
moralstack/runtime/orchestrator.py
Deliberative flow coordination
Risk Estimator
moralstack/models/risk/
Semantic risk classification
Policy LLM
moralstack/models/policy.py
Text generation and revision
Decision Explainability
moralstack/models/decision_explanation.py
Structured decision explainability
Module
File
Description
Constitution Store
moralstack/constitution/store.py
Ethical principle management
Module
File
Description
Benchmark
scripts/benchmark_moralstack.py
Policy-aware benchmark; judge model config, independence
Persistence
moralstack/persistence/
SQLite storage, run/request context, llm_calls, decision_traces
Web UI
moralstack/ui/app.py
FastAPI dashboard; form login at /login, dashboard at /runs
OpenAI Params
moralstack/utils/openai_params.py
Model-specific API params (max_tokens vs max_completion_tokens)
env_loader
moralstack/utils/env_loader.py
Loads .env from project root at startup (moralstack, moralstack-ui, benchmark)
clean_start
moralstack/utils/clean_start.py
Removes reports, benchmark_outputs, logs, debug artifacts (CLI)
Request
│
▼
┌──────────────┐
│Risk Estimator│ ──► Classify risk, determine path
└──────────────┘
│
├─── risk < 0.3 ───► FAST PATH ──► Direct Generation
│
└─── risk ≥ 0.3 ───► DELIBERATIVE PATH
│
▼
┌─────────────────┐
│ Orchestrator │
└─────────────────┘
│
┌───────────────┼───────────────┬───────────────┐
▼ ▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ Critic │ │Simulator │ │Hindsight │ │Perspect. │
└──────────┘ └──────────┘ └──────────┘ └──────────┘
│ │ │ │
└───────────────┴───────────────┴───────────────┘
│
▼
Aggregated Guidance
│
▼
┌─────────────────┐
│ Policy LLM │ ──► Guided revision
└─────────────────┘
│
▼
Convergence Check
│
▼
Final Response
How to Read the Documentation
Each module document includes:
Overview - Module purpose and functionality
Output Structure - Dataclass and output types
Usage - Code examples
Integration - How the module interacts with the Orchestrator
See Also - Links to related modules
← README.md