Multi-Agent System for Healthcare Assistance
An advanced multi-agent system designed to assist healthcare professionals in integrated patient management through specialized AI agents across different medical domains.
HealthcareMAS is an innovative system that uses specialized AI agents to support medical decision-making in a "Human-in-the-Loop" environment. The system coordinates three main agents:
- π©Ί MedAI - Primary care physician for clinical analysis and therapeutic plans
- π₯ NutriAI - Nutritionist for personalized meal planning
- π§ PsyAI - Psychologist for psychophysical wellness monitoring
Patient β MedAI β NutriAI β PsyAI β Medical Validation β Patient
- Clinical Analysis: MedAI analyzes medical reports and generates therapeutic plans
- Nutritional Planning: NutriAI creates meal plans synchronized with therapies
- Psychological Monitoring: PsyAI evaluates psychophysical state and therapy adherence
- Medical Supervision: A qualified physician validates all recommendations
- Specialization: Internal medicine and clinical pharmacology
- Input: Clinical reports, laboratory results, patient history
- Output: Structured therapeutic plan in JSON format
- Safety: Drug interaction analysis, attention flags for physicians
- Specialization: Personalized meal planning and pharmacological synchronization
- Input: Therapeutic plan from MedAI
- Output: Complete 7-day plan with medication timing
- Features: Drug-nutrient interactions, shopping lists, macro balancing
- Specialization: Biometric-psychological correlation analysis
- Input: Subjective feedback + wearable data (Apple Watch, Fitbit)
- Output: Mental state assessment with medical alerting
- Monitoring: HRV, sleep quality, physiological stress
Python 3.8+
OpenAI API Key
datapizza-ai framework (Core dependency)git clone https://github.com/FedeCarollo/HealthcareMAS
cd HealthcareMAS
# Install all dependencies from requirements.txt
pip install -r requirements.txt
# Or install manually
pip install datapizza-aiHealthcareMAS is built on the datapizza-ai framework, a powerful tool for creating specialized AI agents:
- π€ Agent Creation: Simple agent instantiation with custom prompts
- π§ Tool Integration: Easy addition of custom medical tools
- π Client Management: Unified OpenAI API client handling
- π Response Processing: Structured JSON output parsing
from datapizza.agents import Agent
from datapizza.clients.openai import OpenAIClient
from datapizza.tools import tool
# Example: Creating a medical agent with datapizza
client = OpenAIClient(api_key=your_api_key)
agent = Agent(
client=client,
name="MedicalAssistant",
system_prompt="Your specialized medical prompt...",
tools=[your_custom_tools]
)- Create
.envfile:
OPEN_AI_KEY=your_openai_api_key_here- Import configuration system:
from config import get_openai_key# Unified Pipeline Function (Recommended)
from healthcare_mas_pipeline import healthcare_mas_pipeline
from agents.medico_base import clinical_summary
from agents.psicologo import daily_payload
# Complete execution with automatic file saving
result = healthcare_mas_pipeline(
clinical_summary=clinical_summary,
daily_data=daily_payload,
doctor_report=None, # Optional medical updates
save_folder="medical_reports" # Custom folder name
)
# Access results
medical_plan = result['medical_plan']
nutrition_plan = result['nutrition_plan']
psych_assessment = result['psychological_assessment']from agents.medico_base import get_medico, clinical_summary
from agents.nutrizionista import get_nutrizionista
from agents.psicologo import get_psyai, daily_payload
import json
# 1. Medical Analysis
medico = get_medico()
response = medico.run(clinical_summary)
piano_terapeutico = json.loads(response.text)
# 2. Nutritional Planning
nutrizionista = get_nutrizionista()
response = nutrizionista.run(json.dumps(piano_terapeutico))
piano_settimanale = json.loads(response.text)
# 3. Psychological Monitoring
psicologo = get_psyai()
input_psicologo = {
"clinical_summary": clinical_summary,
"treatment_plan": piano_terapeutico,
"weekly_meal_plan": piano_settimanale,
**daily_payload
}
assessment = psicologo.run(json.dumps(input_psicologo))The project includes an interactive notebook (notebook.ipynb) demonstrating the complete clinical workflow with example data.
- Patient history
- Vital signs (BP, HR, SpO2)
- Laboratory results (HbA1c, cholesterol, etc.)
- Symptoms and preliminary diagnosis
{
"diagnostic_summary": "Clinical summary",
"treatment_plan": [
{
"medication": "Active ingredient",
"dosage": "500mg",
"frequency": "1 tablet every 12 hours",
"administration_instructions": "After meals",
"duration": "7 days",
"purpose": "Clinical purpose"
}
],
"medical_recommendations": ["Non-pharmacological suggestions"],
"attention_flag": "Medical alerts or 'None'"
}The healthcare_mas_pipeline() function automatically generates:
- π
medical_plan_{timestamp}.json- Complete therapeutic plan - π₯
nutrition_plan_{timestamp}.json- Weekly meal plan - π§
psychological_assessment_{timestamp}.json- Psychological assessment - π
complete_summary_{timestamp}.json- Complete summary - π
human_readable_report_{timestamp}.txt- Human-readable report - π
shopping_list_{timestamp}.txt- Shopping list (if available)
medical_reports_20251122_143052/
βββ medical_plan_20251122_143052.json
βββ nutrition_plan_20251122_143052.json
βββ psychological_assessment_20251122_143052.json
βββ complete_summary_20251122_143052.json
βββ human_readable_report_20251122_143052.txt
βββ shopping_list_20251122_143052.txt
- β DOES NOT replace professional medical consultation
- β DOES NOT provide definitive diagnoses
- β DOES NOT prescribe medications autonomously
- β SUPPORTS physician decision-making
- β REQUIRES validation by qualified professionals
- All patient data is processed locally
- No sensitive information is permanently stored
- Compliant with healthcare privacy standards
The datapizza-ai framework makes tool integration seamless:
from datapizza.tools import tool
from datapizza.agents import Agent
@tool
def check_drug_interactions(med1: str, med2: str) -> str:
"""Check drug interactions using medical databases"""
# Advanced interaction checking logic
return f"Interaction analysis: {med1} vs {med2} - Status: Safe/Warning/Contraindicated"
@tool
def calculate_drug_dosage(weight: float, age: int, medication: str) -> str:
"""Calculate appropriate drug dosage based on patient parameters"""
# Dosage calculation algorithm
return f"Recommended dosage for {medication}: calculated based on {weight}kg, {age}y"
# Create enhanced medical agent
enhanced_agent = Agent(
client=client,
name="EnhancedMedAI",
system_prompt="Advanced medical AI with drug interaction analysis...",
tools=[check_drug_interactions, calculate_drug_dosage]
)Each agent has a customizable system_prompt leveraging datapizza's prompt engineering:
HealthcareMAS/
βββ agents/
β βββ client.py # Shared OpenAI client (datapizza integration)
β βββ medico_base.py # MedAI agent (datapizza Agent)
β βββ nutrizionista.py # NutriAI agent (datapizza Agent)
β βββ psicologo.py # PsyAI agent (datapizza Agent)
βββ .github/
β βββ copilot-instructions.md # AI coding guidelines
βββ config.py # Configuration management
βββ main.py # Main script
βββ notebook.ipynb # Interactive demo
βββ test.py # System tests
βββ requirements.txt # Project dependencies
βββ README.md
Each healthcare agent leverages datapizza-ai's robust architecture:
# Agent creation with datapizza framework
from datapizza.agents import Agent
from datapizza.clients.openai import OpenAIClient
agent = Agent(
client=OpenAIClient(api_key=api_key),
name="HealthcareAgent",
system_prompt="Specialized medical prompt",
tools=[medical_tools] # Custom healthcare tools
)
# Structured agent execution
response = agent.run(clinical_input)
structured_output = json.loads(response.text)Datapizza's @tool decorator enables seamless medical tool integration:
from datapizza.tools import tool
@tool
def analyze_vital_signs(bp: str, hr: int, temp: float) -> str:
"""Analyze patient vital signs using medical protocols"""
# Medical analysis logic
return clinical_assessment
@tool
def check_drug_interactions(med1: str, med2: str) -> str:
"""Check potential drug interactions"""
# Drug interaction database lookup
return interaction_report- Input: Report with T2 diabetes, hypertension, GERD
- MedAI: Prescribes Metformin, ACE inhibitor, PPI
- NutriAI: Mediterranean low-sodium diet, synchronized medication timing
- PsyAI: Monitors lifestyle change stress, therapy adherence
PsyAI analyzes data from devices like Apple Watch:
- Heart Rate Variability (HRV)
- Sleep quality
- Activity levels
- Correlation with self-reported emotional state
The system supports iterative medical updates:
# Example with doctor feedback
doctor_update = """
MEDICAL UPDATE - Dr. Smith Review (2025-11-22):
1. Increase Metformin to 1000mg twice daily
2. Add Atorvastatin 20mg daily
3. Monitor for lactic acidosis
"""
result = healthcare_mas_pipeline(
clinical_summary=clinical_summary,
daily_data=daily_payload,
doctor_report=doctor_update, # Medical update
save_folder="updated_reports"
)The project is open-source under Apache 2.0 license. Contributions welcome for:
- New specialized agents
- Medical API integrations
- Correlation algorithm improvements
- Clinical testing and validations
For technical support or medical questions:
- π¨ Emergencies: Always contact 911/emergency services
- π₯ Clinical Questions: Consult your healthcare provider
- π» Technical Support: Open a GitHub issue
βοΈ Remember: This system supports but never replaces professional clinical judgment