Skip to content

Repository files navigation

🐦‍🔥 PHOENIX Engine

The PHOENIX engine conceptualises mental health support as a closed-loop workflow that iteratively optimizes the digital intervention proposal based on multi-modal data from previous collection cycles.

Software Tool License GPL v3 Docker Ready Ghent University Master's Thesis


📋 Table of Contents


📄 Abstract

Longitudinal mental health applications collect rich person-specific data, yet translating those data into concrete, personalized intervention decisions remains difficult. PHOENIX addresses this gap with an adaptive approach to idiographic modelling that is built on ontology-based multi-agentic workflows. Starting from a free-text complaint, the engine operationalizes the problem into measurable criteria, constructs an initial observation model, analyses the resulting time-series dynamics, identifies biopsychosocially balanced treatment targets, and generates a digital intervention grounded in the Health Action Process Approach (HAPA). Five sub-ontologies (CRITERION, PREDICTOR, PERSON, CONTEXT, HAPA) constrain every reasoning step, and each generative actor is paired with a critic agent that keeps outputs bounded and auditable. Because the output of each cycle seeds the next, PHOENIX operates as a closed loop in which the weighting of idiographic and nomothetic evidence adapts as more person-specific data become available.


🔁 End-to-End Stage Map

PHOENIX is a modular, multi-agent system that starts from a free-text mental-health complaint, builds an initial observation model, analyses idiographic time-series dynamics through the Hierarchical Updating Algorithm (HUA), proposes biopsychosocially-balanced treatment targets, generates a HAPA-grounded digital intervention, and packages iterative updates for the next cycle. Every generative actor stage is paired with a critic agent that issues a bounded PASS / REVISE decision on a weighted composite score, which gives the full pipeline an auditable trail without sacrificing generative flexibility.

PHOENIX engine: Sequential Flowchart of the Multi-Agent System Architecture (actor-critic per stage; readiness / time-series / impact / candidate-selector flow)


🐦‍🔥 PHOENIX Ontology

Five sub-ontologies constrain all reasoning and output structure across the PHOENIX pipeline: (1) CRITERION (i.e., mental health problem space: DSM-5TR, ICD-10, RDoC-701, non-clinical wellbeing), (2) PREDICTOR (i.e., intervention solution space: BIO / PSYCHO / SOCIAL branches), (3) PERSON (i.e., stable individual-level attributes across 18 domains), (4) CONTEXT (i.e., dynamic situational states: internal and external environment), and (5) HAPA (i.e., behaviour change scaffold: motivation phase, volition phase, barriers taxonomy, coping strategy library). See src/backend/SystemComponents/PHOENIX_ontology/ for the full structured breakdown.

PHOENIX Aggregated Ontology: all five sub-ontologies

🚀 Quick Setup

1. Clone repository

git clone https://github.com/stvsever/ThesisMaster.git
cd MASTERPROEF

2. Create Python environment (3.11+)

python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -r requirements.txt

3. Configure .env for LLM-enabled runs

Create or update .env in repository root:

OPENROUTER_API_KEY=<your_openrouter_key>
OPENAI_BASE_URL=https://openrouter.ai/api/v1

Runtime behavior:

  • OPENROUTER_API_KEY is primary.
  • Runtime mirrors it to OPENAI_API_KEY for backward-compatible scripts.
  • Default model is gpt-5-nano (resolved as openai/gpt-5-nano when routed via OpenRouter).

4. Optional smoke validation

If you want to quickly validate the integrated pipeline on a single profile with minimal iterations, you can run the smoke test:

make pipeline-smoke

Alternative: Docker

PHOENIX ships with a ready-to-use Docker configuration for reproducible execution without a local Python environment:

git clone https://github.com/stvsever/ThesisMaster.git
cd MASTERPROEF

# Optional for LLM-enabled runs; deterministic mode can skip this.
cat > .env <<'EOF'
OPENROUTER_API_KEY=<your_openrouter_key>
OPENAI_BASE_URL=https://openrouter.ai/api/v1
EOF

cd docker
docker compose up --build

The setup bundles all dependencies, mounts pipeline outputs back to the host, and supports CLI runs through the phoenix-cli service. See docker/README.md for the full workflow.


🗂️ Repository Structure

The main codebase is organized around src/ and evaluation/. Inside src/, src/backend/ holds the engine, ontologies, shared runtime utilities, and architecture assets.

MASTERPROEF/
├── src/                            # Canonical application source tree
│   ├── backend/                      # Engine runtime, SystemComponents, utils, orchestrator, overview assets
│   └── README.md                     # Architecture overview for the `src/` tree
├── evaluation/                     # Sequential scripts + integrated pipeline + QA/research
│   ├── sequential/                    # Stage-wise run_step.py scripts (00..08)
│   ├── integrated_pipeline/           # run_pipeline.py and run_engine_pipeline.py
│   └── quality_and_research/          # pytest suites, schema contracts, research reporting
├── docker/                         # Dockerfile + docker-compose for reproducible deployment
├── .github/                        # CI/CD workflows
├── pyproject.toml                  # Python package metadata and constraints
├── requirements.txt                # Dependency baseline
└── README.md                       # Root documentation

💻 Run from CLI

A. Standard integrated run

The following command executes the full PHOENIX pipeline with default settings, processing the synthetic_v1 dataset through all stages and generating comprehensive outputs:

python evaluation/integrated_pipeline/run_pipeline.py --mode synthetic_v1

B. Single profile selection

The following command runs the pipeline on the synthetic_v1 dataset but limits the execution to a single profile matching the pattern pseudoprofile_FTC_ID001. This allows for focused testing and debugging on a specific case:

python evaluation/integrated_pipeline/run_pipeline.py --mode synthetic_v1 \
  --pattern pseudoprofile_FTC_ID001 \
  --max-profiles 1

C. Iterative run (2 cycles)

The following command executes the PHOENIX pipeline for 2 complete cycles, allowing you to observe how the system iteratively refines its outputs based on previous cycle data. The --profile-memory-window 3 flag enables the system to retain information from the last 3 profiles for informed decision-making in subsequent cycles:

python evaluation/integrated_pipeline/run_pipeline.py --mode synthetic_v1 \
  --cycles 2 \
  --profile-memory-window 3

📦 Outputs and Validation

Integrated outputs are saved under:

evaluation/integrated_pipeline/runs/<run_id>/

Key artifacts to inspect:

  • 00_operationalization/ through 10_research_reports/
  • pipeline_summary.json
  • llm_startup_health_check.json
  • Stage logs (stage.log, stage_events.jsonl, stage_trace.json)
  • Profile-specific JSON/CSV outputs per step
  • Profile-specific human-readable summaries:
    • 07_hapa_digital_intervention/<profile_id>/step05_hapa_intervention.md
    • 08_treatment_translation_communication/<profile_id>/treatment_translation_communication.md
  • Time-varying network animation: 04_time_series_analysis/<profile_id>/tv_network_animation.gif
  • Publication-ready PNGs: 09_impact_visualizations/<profile_id>/

✅ Quality Assurance and CI/CD

Run locally:

make qa-unit
make qa-integration
make qa-smoke
make qa-all

Automated workflows:

  • .github/workflows/ci.yml
  • .github/workflows/smoke_pipeline.yml

Schema/contract validation entrypoint:

  • evaluation/quality_and_research/quality_assurance/validate_contract_schemas.py

Contract validation: 7 JSON schemas enforce structural guarantees on every stage output: readiness_report, network_comparison_summary, momentary_impact, step03_target_selection, step04_updated_model, step05_hapa_intervention, pipeline_summary.


📜 License

This project is licensed under GNU General Public License v3.0. See LICENSE.

What this means in practice:

  • You may use, study, modify, and redistribute this code.
  • If you distribute modified versions (or software that includes GPL-covered parts), you must:
    • keep it under GPL-compatible terms,
    • provide corresponding source code,
    • preserve copyright and license notices,
    • document meaningful changes.
  • The software is provided without warranty.

For academic reuse, cite the thesis context appropriately and keep provenance of methodological changes explicit.

Caution

EU MDR / PRE-CLINICAL DISCLAIMER PHOENIX is a Clinical Decision Support System (CDSS) prototype designed for research purposes. It is NOT a certified medical device under the EU Medical Device Regulation (MDR 2017/745) or FDA guidelines. Do not use for primary diagnostic decisions. All outputs must be verified by a qualified clinician.

About

This repository delivers an end-to-end, research-grade platform for personalized mental health optimization, developed in the context of my master’s thesis at Ghent University.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages