Installation & Setup
Relevant source files
The following files were used as context for generating this wiki page:
This page provides the technical requirements and procedural steps to initialize the AI Anomaly Detection system. The project is designed as a multi-agent watchtower that monitors medical AI outputs, flags safety risks, and provides RAG-grounded explanations. It consists of a FastAPI backend using SQLite for persistence and a React-based frontend for administrative monitoring and human review.
Sources: AI Service/plan.md:1-10, backend/README.md:1-5
Backend Environment Setup
The backend serves as the core orchestration layer, managing the LogAgent, MisbehaviorAnalysisAgent, and the RAGSystem. It requires a Python environment capable of running FastAPI and interfacing with the SQLite database.
Prerequisites & Dependencies
The backend requires administrative configuration and specific environment variables, particularly for the Gemini-based anomaly detection agents.
| Component | Description |
|---|---|
| Python | 3.10+ (suggested for FastAPI compatibility) |
| Database | SQLite (Primary store for logs, scores, and feedback) |
| LLM Access | API Key for Gemini (for analysis and scoring prompts) |
| Admin Access | JWT-based Bearer Token for protected endpoints |
Sources: AI Service/plan.md:85-92, backend/test_enhanced_endpoints.py:16-24, backend/app/utils/prompts.py:1-5
Administrative Initialization
To access the system's management features, an administrative account must be created. This is done via a dedicated script.
# Create an admin user
python scripts/create_admin.py --email admin@example.com --username admin --password admin123
Sources: backend/README.md:8-11
Frontend Application Setup
The frontend is a React application that provides a "Watchtower UI." This interface allows administrators to view the ML processing pipeline, inspect multi-level anomaly detections, and perform human-in-the-loop review.
UI Architecture
The UI is structured around a multi-stage pipeline view (Levels 1 through 5), ranging from raw ingestion to human verification.
The diagram above shows the logical progression of data visualization within the InteractionDetail component.
Sources: frontend/src/pages/admin/InteractionDetail.jsx:87-290, AI Service/plan.md:195-215
Database & Storage Configuration
The system utilizes a primary SQLite database with specific tables designed for the multi-agent workflow.
| Table Name | Description | Key Fields |
|---|---|---|
interaction_logs | Raw user prompts and AI responses | id, prompt, response, model_name |
analysis_records | Flags for topics and risk contexts | interaction_id, risk_context_flags |
scoring_records | Quantitative risk scores (0.0 - 1.0) | safety_risk, triage_risk, overall_anomaly_score |
explanations | RAG-backed reasoning for flags | risk_type, explanation, citations |
feedback | Human-labeled audit data | human_label, corrected_response |
Sources: AI Service/plan.md:85-95, AI Service/plan.md:13-75
Verification and Testing
Once the environment is configured, the system can be validated using the provided smoke tests and endpoint verification scripts.
Running Smoke Tests
A smoke test is available to verify the integration between the LogAgent and WatchtowerOrchestrator.
# Ensure the server is running before execution
./scripts/phase6_smoke.sh
Sources: backend/README.md:13-16
Enhanced API Testing
For detailed verification of anomaly detection features, use the test_enhanced_endpoints.py script. This requires an active admin token acquired during the setup phase.
# test_enhanced_endpoints.py snippet
BASE_URL = "http://localhost:8000"
API_PREFIX = "/api/admin"
ADMIN_TOKEN = "YOUR_ADMIN_TOKEN_HERE"
headers = {
"Authorization": f"Bearer {ADMIN_TOKEN}",
"Content-Type": "application/json"
}
Sources: backend/test_enhanced_endpoints.py:16-24
Summary of Agent Workflow
The installation enables a four-phase pipeline:
- Data Ingestion:
LogAgentcaptures interactions. - Analysis:
MisbehaviorAnalysisAgentapplies medical safety rules. - Scoring:
AnomalyScoringAgentcalculates safety, triage, and factuality risks. - Explainability:
RAGSystemgenerates explanations from medical guidelines.
Sources: AI Service/plan.md:143-155, backend/app/utils/prompts.py:7-140