Deployment Infrastructure
Relevant source files
The following files were used as context for generating this wiki page:
The deployment infrastructure for the AI Anomaly Detection system is designed as a multi-layered medical safety "Watchtower." It refactors traditional research analysis into a real-time monitoring system that ingests interaction logs, performs multi-agent anomaly detection, and provides RAG-grounded explanations. The system is structured into a backend scaffold for high-stakes medical advice monitoring and a frontend administrative portal for human-in-the-loop verification.
The infrastructure supports two primary operational modes: Shadow Mode, which monitors outputs without blocking, and Intercept Mode, which can trigger warnings or human review when high anomaly scores are detected.
Sources: AI Service/plan.md:5-10, AI Service/plan.md:237-241, README.md:1-5
System Architecture
The infrastructure follows a modular, agentic architecture where specialized agents handle different stages of the data lifecycle. The system is organized into a pipeline that progresses from raw data ingestion to automated risk scoring and human review.
Processing Pipeline Flow
The diagram below illustrates the flow of data through the deployment infrastructure, from the initial user interaction to the final human feedback loop.
The pipeline architecture ensures that every AI interaction is recorded and analyzed against medical safety guidelines before being presented in the administrative interface.
Sources: AI Service/plan.md:83-93, frontend/src/components/admin/InteractionDetail.jsx:87-95
Backend Components
The backend infrastructure is built on a Python-based scaffold that manages data persistence and the multi-agent orchestration logic.
1. Data & Logging Layer (LogAgent)
The LogAgent is responsible for normalizing and persisting interaction logs. It utilizes a primary SQLite database for portability and an optional append-only JSONL mirror for auditing.
| Table Name | Description |
|---|---|
interaction_logs | Stores raw prompt, response, and metadata (model, user ID). |
analysis_records | Stores rule-based flags (e.g., pediatric dosing, emergency cases). |
scoring_records | Stores numerical risk scores (0.0 to 1.0) for safety and factuality. |
explanations | Stores RAG-generated rationales for flagged anomalies. |
feedback | Stores human labels (SAFE/UNSAFE) and corrected responses. |
Sources: AI Service/plan.md:65-74, AI Service/plan.md:76-81
2. Multi-Agent Orchestrator
The WatchtowerOrchestrator manages the sequence of operations. It feeds logs into the MisbehaviorAnalysisAgent for feature extraction (e.g., detecting emergency symptoms or dosing patterns) and the AnomalyScoringAgent for calculating the final anomaly score.
# Deployment Integration Strategy
overall_score = weighted_sum([
safety_risk * 0.35,
triage_risk * 0.25,
medication_dosing_risk * 0.2,
factuality_risk * 0.1,
anxiety_inducing_risk * 0.1
])
Sources: AI Service/plan.md:144-162, AI Service/plan.md:164-170
3. RAG Explanation Engine
For interactions exceeding safety thresholds, the infrastructure invokes a RAG (Retrieval-Augmented Generation) system. This system queries a Chroma vector database (collection: medical_safety_guidelines) to retrieve context from local medical docs or crawled guidelines.
Sources: AI Service/plan.md:195-200, AI Service/plan.md:215-225
Administrative & Monitoring API
The infrastructure provides several enhanced API endpoints for monitoring system health and reviewing anomalies. These are tested via the test_enhanced_endpoints.py suite.
| Endpoint | Method | Purpose |
|---|---|---|
/api/admin/metrics/enhanced | GET | Retrieves high-level system performance and risk metrics. |
/api/admin/analytics/anomaly-breakdown | GET | Returns distribution of anomalies over time (e.g., 24h filter). |
/api/admin/interactions/anomalies/by-category | GET | Filters anomalies by HALLUCINATION, UNSAFE_ADVICE, etc. |
/api/admin/interactions/{id}/detailed | GET | Fetches full multi-dimensional analysis for a specific log. |
Sources: backend/test_enhanced_endpoints.py:53-118
Frontend Infrastructure
The administrative interface is a React-based portal designed for high-density information review. It implements a "Level 1 to Level 5" view of the ML processing pipeline.
Admin Detail View Structure
The frontend displays the deployment state of an interaction across five distinct stages:
- Level 1: Interaction Log: Raw data ingestion view.
- Level 2: Record Analysis: Feature extraction flags (e.g., topic detection).
- Level 3: Risk Scoring: Model inference results and bar charts.
- Level 4: Explainability Layer: RAG-generated context and citations.
- Level 5: Human Review: Interface for expert verification and feedback submission.
Sources: frontend/src/components/admin/InteractionDetail.jsx:100-340, frontend/src/pages/admin/InteractionDetail.jsx:106-250
Deployment & Smoke Testing
The project includes scripts to verify the environment and baseline functionality post-deployment.
- Admin Creation: A script allows for the initial setup of admin credentials (
python scripts/create_admin.py). - Smoke Test: The
phase6_smoke.shscript executes integration tests against a running server to ensure all layers (Ingestion -> Analysis -> Scoring) are functional.
# Example Smoke Test execution from backend README
./scripts/phase6_smoke.sh
Sources: backend/README.md:5-12, AI Service/plan.md:255-275
Conclusion
The deployment infrastructure of the AI Anomaly Detection system provides a robust, multi-layered defense for medical AI safety. By combining automated agentic scoring with a RAG-backed explanation engine and a dedicated administrative interface, the system ensures that high-risk medical advice is flagged, explained, and verified by human experts.