A comprehensive AI-powered multiagent system for Parkinson's disease analysis using MRI scans. This system implements explicit triggering only - all prediction and report generation occurs only when explicitly requested, while maintaining robust chat functionality.
- π€ Multiagent Architecture: Supervisor, AI/ML, and RAG agents coordinate via shared memory action flags
- π§ AI-Powered Analysis: TensorFlow/Keras model for Parkinson's disease probability assessment from MRI scans
- π Dual Report Generation: Separate professional doctor reports and patient-friendly reports
- πΌοΈ MRI Processing: Professional medical image processing with feature extraction and quality assessment
- π Medical Knowledge Base: Semantic search through Parkinson's clinical guidelines and research
- π¬ Interactive Chat: Full conversational interface without triggering any processing
- π PDF Report Generation: Professional medical reports with embedded MRI images
- πΎ Complete Data Persistence: SQLite database with session history, predictions, reports, and binary MRI storage
- π Health Monitoring: Real-time system health checks and component status monitoring
- π Explicit Triggering: No automatic processing - all analysis requires explicit user requests
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Supervisor β β AI/ML Agent β β RAG Agent β
β Agent β β β β β
β β β β’ MRI Processing β β β’ Knowledge β
β β’ Chat Handling β β β’ Feature Extractβ β Base Search β
β β’ Intent β β β’ ML Prediction β β β’ Report β
β Detection β β β β Generation β
β β’ Flag Creation β β Triggers ONLY on β β Triggers ONLY onβ
β β β PREDICT_PARKINSONSβ β GENERATE_REPORT β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
β
βββββββββββββββββββββββ
β Shared Memory β
β β
β β’ Action Flags β
β β’ Event Bus β
β β’ Session Data β
β β’ Database Access β
βββββββββββββββββββββββ
- π Explicit Triggering Only: Agents process ONLY when action flags are explicitly set by user requests
- π« No Direct Communication: Agents communicate exclusively via shared memory action flags
- π― Supervisor Orchestration: All user interaction goes through Supervisor Agent for intent detection
- π·οΈ Flag-Based Workflow:
PREDICT_PARKINSONSβGENERATE_REPORTβREPORT_COMPLETE - π¬ Chat Mode Support: Full conversational capability without triggering any processing workflows
- Python 3.9+
- Groq API Key (get from Groq Console)
- 4GB+ RAM (for TensorFlow model loading)
- Windows/Linux/macOS (tested on Windows 10/11)
-
Clone the repository
git clone <repository-url> cd ParkinsonsMultiagentSystem
-
Create virtual environment
python -m venv .venv .venv\Scripts\activate # Windows # source .venv/bin/activate # Linux/Mac
-
Install dependencies
pip install -r requirements.txt
-
Configure environment
cp .env.example .env # Edit .env and add your GROQ_API_KEY -
Start the system
python main.py
What happens:
-
System Initialization (15-30 seconds):
- Loads TensorFlow/Keras Parkinson's prediction model
- Initializes SQLite database with migration support
- Starts shared memory event bus
- Loads Groq service for AI chat/responses
- Initializes MRI processor for medical imaging
- Loads sentence transformer embeddings for knowledge base
- Starts all three agents (Supervisor, AI/ML, RAG)
- Loads 13+ medical documents into knowledge base
-
Patient/Doctor Information Collection:
=== Patient Information === Patient name: John Doe Generated Patient ID: patient_a1b2c3d4 === Doctor Information === Doctor name (optional): Dr. Smith Generated Doctor ID: doctor_e5f6g7h8 -
Interactive Mode Ready:
Parkinson's Multiagent System is ready! Type 'quit' to exit, 'health' for health check, or enter a message: >
What happens when you type general questions:
> What are the symptoms of Parkinson's disease?
System: Parkinson's disease symptoms include tremors, rigidity, bradykinesia...
Internally:
- Supervisor Agent detects no processing keywords
- Routes to Groq API for conversational response
- No action flags set - pure chat mode
- Response generated via Llama 3.8B model
What happens when you type:
> generate report on "C:\path\to\mri_scan.jpg"
Complete workflow triggered:
- Intent Detection: Supervisor detects MRI file + "generate report"
- Session Creation: New session with patient/doctor metadata
- MRI Storage: Binary MRI data stored in database
- Flag Creation:
PREDICT_PARKINSONSflag set - AI/ML Processing:
- MRI preprocessing (skull stripping, normalization)
- Feature extraction (anatomical, intensity, texture)
- TensorFlow model prediction (57.25% Parkinson's probability)
- Results stored in database
- Prediction Complete:
PREDICTION_COMPLETEflag set - Report Generation Triggered:
GENERATE_REPORTflag set - RAG Processing:
- Retrieves prediction data from shared memory
- Searches knowledge base for relevant medical info
- Generates dual reports via Groq API
- Creates PDF reports with embedded MRI images
- Completion:
REPORT_COMPLETEflag set
Output:
- Doctor PDF:
doctor_report_session_xyz_20250920_011913.pdf - Patient PDF:
patient_report_session_xyz_20250920_011913.pdf - Both stored in
data/reports/directory
What happens when you type:
> health
System response:
{
"system_status": "healthy",
"initialization_complete": true,
"components": {
"database": {"status": "healthy", "connections": 5},
"shared_memory": {"status": "healthy", "cache_size": 42},
"groq_service": {"status": "healthy", "api_responsive": true},
"supervisor_agent": {"status": "healthy", "active_sessions": 3},
"aiml_agent": {"status": "healthy", "model_loaded": true},
"rag_agent": {"status": "healthy", "knowledge_entries": 113}
}
}What happens when you type:
> quit
Graceful shutdown sequence:
- Stops all agent monitoring loops
- Closes database connections
- Shuts down shared memory event bus
- Closes Groq API connections
- Saves any pending data
- Logs final system state
- Trigger: General questions, conversation
- Processing: Supervisor β Groq API β Response
- Flags Set: None
- Data Stored: None
- Example: "What is Parkinson's disease?"
- Trigger: "analyze mri [file]" or "predict [file]"
- Processing: Supervisor β AI/ML Agent β MRI Processing β Prediction
- Flags:
PREDICT_PARKINSONSβPREDICTION_COMPLETE - Output: Prediction results displayed
- Data Stored: MRI binary data, prediction results
- Trigger: "generate report" (with existing prediction data)
- Processing: Supervisor β RAG Agent β Knowledge Search β Report Generation
- Flags:
GENERATE_REPORTβREPORT_COMPLETE - Output: PDF reports generated
- Data Stored: Medical reports
- Trigger: "generate report on [MRI file]"
- Processing: Full pipeline (analysis + report)
- Flags:
PREDICT_PARKINSONSβPREDICTION_COMPLETEβGENERATE_REPORTβREPORT_COMPLETE - Output: Prediction results + PDF reports
- Data Stored: Everything (MRI, prediction, reports)
- Invalid MRI: Graceful error, cleanup flags
- API Failures: Retry with exponential backoff
- Model Errors: Fallback responses, flag cleanup
- Database Issues: Connection retry, data integrity checks
# Required: Groq API Configuration
GROQ_API_KEY=your_api_key_here
GROQ_MODEL_CHAT=llama3-8b-8192
GROQ_MODEL_ANALYSIS=llama3-70b-8192
GROQ_MODEL_REPORT=llama3-70b-8192
# Optional: Database Configuration
DATABASE_URL=sqlite:///./data/parkinsons_system.db
DATABASE_ECHO=false
DATABASE_POOL_SIZE=10
# Optional: Model Configuration
PARKINSON_MODEL_PATH=models/parkinsons_model.keras
ENABLE_MOCK_PREDICTIONS=false
# Optional: Logging
LOG_LEVEL=INFO
DEBUG_MODE=falseMRI Processing:
- Target dimensions: (256, 256, 128)
- Supported formats: DICOM, PNG, JPEG, NIfTI
- Quality thresholds: 0.6 minimum score
AI/ML Agent:
- Processing timeout: 120 seconds
- Model confidence threshold: 0.7
- Feature validation: 0.6 minimum
RAG Agent:
- Knowledge search limit: 5 results
- Relevance threshold: 0.7
- Generation timeout: 60 seconds
Shared Memory:
- Cache size: 1000 items
- TTL: 3600 seconds (1 hour)
- Cleanup interval: 300 seconds (5 minutes)
ParkinsonsMultiagentSystem/
βββ main.py # π System entry point & interactive CLI
βββ config.py # βοΈ Configuration management
βββ requirements.txt # π¦ Python dependencies
βββ README.md # π This documentation
β
βββ agents/ # π€ Agent implementations
β βββ supervisor_agent.py # π― Main orchestrator - intent detection & chat
β βββ aiml_agent.py # π§ MRI processing & ML predictions
β βββ rag_agent.py # π Report generation & knowledge search
β
βββ core/ # π§ Core system components
β βββ database.py # πΎ SQLite database operations
β βββ shared_memory.py # π‘ Inter-agent communication
β
βββ models/ # π Data structures
β βββ data_models.py # ποΈ Core data classes (User, Session, MRI, etc.)
β βββ agent_interfaces.py # π Base agent classes & interfaces
β
βββ services/ # π External integrations
β βββ groq_service.py # π€ Groq API (Llama models)
β βββ mri_processor.py # πΌοΈ Medical image processing
β
βββ knowledge_base/ # π Medical knowledge
β βββ embeddings_manager.py # π Text embeddings & semantic search
β
βββ utils/ # π οΈ Utilities
β βββ pdf_generator.py # π PDF report creation
β βββ report_generator.py # π Report formatting
β
βββ data/ # π½ Data storage
β βββ parkinsons_system.db # ποΈ SQLite database
β βββ mri_scans/ # πΌοΈ MRI scan storage
β βββ reports/ # π Generated PDF reports
β βββ embeddings/ # π Knowledge base vectors
β
βββ logs/ # π System logs
βββ system.log # π Application logging
# Health check (built-in)
python main.py
> health
# Simple validation test
python -c "
import asyncio
from main import ParkinsonsMultiagentSystem
async def test():
system = ParkinsonsMultiagentSystem()
await system.initialize()
health = await system.health_check()
print('System healthy:', health['system_status'] == 'healthy')
asyncio.run(test())
"- β Explicit Triggering: Verifies no automatic processing occurs
- β Chat Functionality: Confirms conversational responses work
- β MRI Processing: Validates image preprocessing and feature extraction
- β Model Prediction: Tests TensorFlow model loading and inference
- β Report Generation: Validates PDF creation and content accuracy
- β Database Operations: Tests data persistence and retrieval
- β Error Handling: Validates graceful failure handling
Core Tables:
users- Patient/doctor informationpatients- Extended patient medical datasessions- User interaction sessionsmri_scans- Binary MRI data storagepredictions- AI model prediction resultsmedical_reports- Generated report contentaction_flags- Inter-agent communication flags
Security Features:
- Binary MRI data encryption-ready
- Session-based access control
- Audit logging for all operations
- Automatic cleanup of expired sessions
- Input: User provides patient info, MRI file, analysis request
- Processing: MRI β preprocessing β feature extraction β AI prediction
- Storage: All data persisted with session tracking
- Output: Dual PDF reports with embedded images
- Cleanup: Automatic removal of expired sessions (24h default)
Main Log: logs/system.log
2025-09-20 01:18:13,144 [INFO] parkinsons_system.main: Starting Parkinson's Multiagent System initialization...
2025-09-20 01:18:19,943 [INFO] agents.aiml_agent: [AUDIT] β
Model loaded successfully
2025-09-20 01:18:21,479 [INFO] parkinsons_system.main: System initialization completed successfully!
β "Model loading failed"
- Check TensorFlow installation:
pip install tensorflow - Verify model file exists:
models/parkinsons_model.keras - Check RAM: Minimum 4GB required
β "Groq API error"
- Verify API key in
.env:GROQ_API_KEY=your_key_here - Check internet connection
- Confirm API quota/limits
β "Database locked"
- Close other instances of the application
- Check file permissions on
data/parkinsons_system.db - Wait for automatic cleanup (5 minutes)
β "MRI processing failed"
- Verify image format (PNG/JPG/DICOM supported)
- Check file path validity
- Ensure sufficient disk space
Initialization Time: 15-30 seconds MRI Processing: 3-5 seconds per scan Prediction Time: 5-10 seconds Report Generation: 10-20 seconds Memory Usage: 2-4GB RAM during operation
- New Agent: Extend
BaseAgentclass inmodels/agent_interfaces.py - New Action Flag: Add to
ActionFlagTypeenum inmodels/data_models.py - New Data Model: Add to
models/data_models.pywith database schema - New Service: Implement service interface and integrate in
main.py
- Type Hints: All functions use proper type annotations
- Async/Await: All I/O operations are asynchronous
- Error Handling: Comprehensive try/catch with logging
- Documentation: Docstrings for all classes and methods
- Logging: Structured logging with appropriate levels
- No Auto-Diagnosis: System requires explicit user requests for analysis
- Clear Disclaimers: All outputs include medical disclaimers
- Data Privacy: Patient data handled according to privacy principles
- Professional Oversight: Designed to augment, not replace, medical professionals
- Check Health Status: Type
healthin interactive mode - Review Logs: Check
logs/system.logfor detailed information - Validate Setup: Ensure all dependencies are installed correctly
- Test Components: Use built-in health checks to isolate issues
- Fork the repository
- Create feature branch:
git checkout -b feature/new-feature - Make changes with comprehensive testing
- Update documentation as needed
- Submit pull request with detailed description
π― Key Reminder: This system implements explicit triggering only. No MRI processing, prediction, or report generation occurs automatically - all analysis must be explicitly requested by users through specific commands like "generate report on [MRI file]".
π¬ Research Focus: Designed for Parkinson's disease analysis research, with comprehensive data collection and analysis capabilities for medical AI development.
- Python 3.9+
- Groq API key (get from Groq Console)
-
Clone the repository
git clone <repository-url> cd ParkinsonsMultiagentSystem
-
Install dependencies
pip install -r requirements.txt
-
Configure environment
cp .env.example .env # Edit .env and add your GROQ_API_KEY -
Run tests
# Using the simple test runner python tests/run_tests.py # Or using pytest if installed pytest tests/test_explicit_triggering.py -v
-
Start the system
python main.py
> Hello, what can you help me with?
System: I'm here to help with Parkinson's disease analysis...
> What are the symptoms of Parkinson's disease?
System: Parkinson's disease symptoms include tremors, rigidity...
> Can you explain how MRI scans work?
System: MRI (Magnetic Resonance Imaging) uses magnetic fields...
β No action flags set - pure conversational mode
> Please analyze this MRI scan for Parkinson's: /path/to/scan.dcm
System: I'll analyze the MRI scan for Parkinson's disease indicators...
[System sets PREDICT_PARKINSONS flag]
[AI/ML Agent processes the scan]
[Analysis results stored in shared memory]
System: Analysis complete. Parkinson's probability: 75%
β PREDICT_PARKINSONS flag explicitly set and processed
> Please generate a comprehensive medical report
System: I'll generate a detailed medical report based on the analysis...
[System sets GENERATE_REPORT flag]
[RAG Agent generates report using knowledge base]
[Report stored in shared memory]
System: Medical report generated successfully.
β GENERATE_REPORT flag explicitly set and processed
> Hi, I need to analyze an MRI scan
System: Hello! I can help you analyze MRI scans for Parkinson's disease.
> Please analyze /data/patient_123.dcm for Parkinson's disease
System: Analyzing MRI scan... [PREDICT_PARKINSONS flag set]
System: Analysis complete. Results show 82% probability of Parkinson's.
> Now generate a detailed medical report please
System: Generating comprehensive report... [GENERATE_REPORT flag set]
System: Medical report generated with findings and recommendations.
> Thank you! What should the patient do next?
System: Based on the high probability result, I recommend...
# Required: Groq API Configuration
GROQ_API_KEY=your_api_key_here
GROQ_MODEL_CHAT=llama3-8b-8192
GROQ_MODEL_ANALYSIS=llama3-70b-8192
GROQ_MODEL_REPORT=llama3-70b-8192
# Optional: Database Configuration
DATABASE_URL=sqlite:///./data/parkinsons_system.db
DATABASE_ECHO=false
# Optional: Logging
LOG_LEVEL=INFO
DEBUG_MODE=falseKey configuration options in config.py:
- MRI Processing: Image dimensions, preprocessing pipeline, quality thresholds
- Agent Timeouts: Response timeouts, retry limits, confidence thresholds
- Embeddings: Model selection, cache settings, similarity thresholds
- Database: Connection pooling, cleanup intervals, session management
- User asks general questions
- Supervisor Agent responds via Groq
- No action flags set
- No other agents activated
- User explicitly requests MRI analysis
- Supervisor Agent sets
PREDICT_PARKINSONSflag - AI/ML Agent claims flag and processes:
- MRI preprocessing and feature extraction
- ML model prediction
- Results stored in shared memory
- Flag marked complete
- Supervisor responds with results
- User explicitly requests report generation
- Supervisor Agent sets
GENERATE_REPORTflag - RAG Agent claims flag and processes:
- Retrieves prediction data from shared memory
- Searches knowledge base for relevant information
- Generates comprehensive report via Groq
- Stores report in shared memory
- Flag marked complete
- Supervisor responds with report access
- Invalid MRI files: Graceful error messages, flag cleanup
- Missing predictions: Reports indicate missing data
- API failures: Retry logic with exponential backoff
- Agent timeouts: Automatic flag cleanup and user notification
- Explicit Triggering: Verifies no automatic processing occurs
- Chat-Only Mode: Confirms chat works without setting flags
- Flag-Based Communication: Tests agent isolation and shared memory communication
- Combined Workflows: Validates full analysis and report generation sequences
- Error Handling: Tests graceful failure handling
# Simple test runner (no dependencies)
python tests/run_tests.py
# Full pytest suite (requires pytest)
pytest tests/ -v
# Specific test categories
pytest tests/test_explicit_triggering.py::TestChatOnlyWorkflow -v
pytest tests/test_explicit_triggering.py::TestExplicitMRIPredictionWorkflow -v
pytest tests/test_explicit_triggering.py::TestExplicitReportGenerationWorkflow -vParkinsonsMultiagentSystem/
βββ agents/ # Agent implementations
β βββ __init__.py
β βββ supervisor_agent.py # Main orchestrator agent
β βββ aiml_agent.py # MRI processing and ML prediction
β βββ rag_agent.py # Report generation and knowledge retrieval
βββ core/ # Core system components
β βββ __init__.py
β βββ database.py # Database operations
β βββ shared_memory.py # Inter-agent communication
βββ knowledge_base/ # Knowledge management
β βββ __init__.py
β βββ embeddings_manager.py # Text embeddings and similarity search
βββ models/ # Data models and interfaces
β βββ __init__.py
β βββ agent_interfaces.py # Base agent classes
β βββ data_models.py # Core data structures
βββ services/ # External service integrations
β βββ __init__.py
β βββ groq_service.py # Groq API integration
β βββ mri_processor.py # MRI image processing
βββ tests/ # Test suite
β βββ __init__.py
β βββ run_tests.py # Simple test runner
β βββ test_explicit_triggering.py # Comprehensive tests
βββ utils/ # Utility modules
β βββ __init__.py
β βββ report_generator.py # Report formatting and generation
βββ config.py # Configuration management
βββ main.py # Application entry point
βββ requirements.txt # Python dependencies
βββ .env.example # Environment configuration template
βββ README.md # This file
# Programmatic health check
health_status = await system.health_check()
# Interactive health check
> health
Health Status: {
'system_status': 'healthy',
'components': {
'database': {'status': 'healthy', 'connections': 5},
'shared_memory': {'status': 'healthy', 'cache_size': 42},
'groq_service': {'status': 'healthy', 'api_responsive': True},
'supervisor_agent': {'status': 'healthy', 'active_sessions': 3}
}
}- Console Logging: INFO level for general operation
- File Logging: DEBUG level in
logs/system.log - Agent Logging: Individual agent operation tracking
- Flag Monitoring: Action flag lifecycle logging
- New Agent: Extend
BaseAgentclass - New Flag Type: Add to
ActionFlagenum and implement handling - New Data Model: Add to
data_models.pywith validation - New Service: Implement service interface and integrate
- All agent communication via shared memory action flags
- Explicit triggering only - no automatic processing
- Comprehensive error handling and logging
- Async/await for all I/O operations
- Type hints and docstrings for all functions
- Fork the repository
- Create a feature branch:
git checkout -b feature/new-feature - Make changes and add tests
- Run test suite:
python tests/run_tests.py - Commit changes:
git commit -am 'Add new feature' - Push to branch:
git push origin feature/new-feature - Submit a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions, issues, or contributions:
- Check the test suite:
python tests/run_tests.py - Review the logs:
logs/system.log - Check health status: Type
healthin interactive mode - Create an issue with system health output and relevant logs
Key Reminder: This system implements explicit triggering only. No MRI processing or report generation occurs automatically - all analysis must be explicitly requested by users. Chat functionality works independently without triggering any processing workflows.