DSPy extension for STCC medical triage with specialized nurses
Project description
STCC Triage Agent - DSPy Extension (v2.0.0)
Professional medical triage system powered by DSPy and DeepSeek, with 10 specialized nurse agents.
โ ๏ธ IMPORTANT: Educational and research use only. NOT approved for clinical use.
Demo
Interactive triage system with 10 specialized nurse agents. Watch full video
What's New in v2.0.0
This is now a professional DSPy extension that users can install locally:
- ๐ฆ PyPI package:
pip install dspy-stcc-homecare - ๐ CLI commands:
stcc-ui,stcc-optimize,stcc-api - ๐๏ธ Clean structure: All code in
stcc_triage/package - ๐ Bundled data: 225 STCC protocols pre-parsed and included
- ๐พ Zero setup: Just install and run - no manual configuration
- ๐ Breaking changes: Clean v2.0.0 release (no backward compatibility)
Installation
Quick Start (PyPI)
# Install the package
pip install dspy-stcc-homecare
# Configure API key
export DEEPSEEK_API_KEY="your-key-here"
# Launch UI
stcc-ui
Development Setup
# Clone repository
git clone https://github.com/chenhaodev/dspy-stcc-homecare.git
cd dspy-stcc-homecare
# Install in editable mode
pip install -e .
# Or use uv (faster)
uv pip install -e .
# Install with API support
pip install -e ".[api]"
Configure API Key
# Option 1: Environment variable
export DEEPSEEK_API_KEY="your-key-here"
# Option 2: .env file (for development)
cp .env.example .env
# Edit .env and add: DEEPSEEK_API_KEY=your_key_here
Quick Start
Launch Web UI
stcc-ui
# Opens at http://localhost:8501
Features:
- ๐ฅ Select from 10 specialized nurses
- ๐ฌ Interactive chat interface
- ๐จ Color-coded triage levels
- ๐ View reasoning steps
- ๐ง Check optimization status
Python API
from stcc_triage import STCCTriageAgent
from stcc_triage.nurses import WoundCareNurse
# Use baseline agent
agent = STCCTriageAgent()
result = agent.triage("55-year-old with severe chest pain and shortness of breath")
print(f"Triage Level: {result.triage_level}")
print(f"Justification: {result.clinical_justification}")
# Use specialized nurse (requires compilation first)
nurse = WoundCareNurse()
result = nurse.triage("deep laceration with bleeding")
Specialized Nurses
Instead of one generic agent, this system provides 10 specialized nurses, each optimized for their domain:
| Nurse | Specialization | Protocol Count | Example Cases |
|---|---|---|---|
| Wound Care | Trauma, burns, bleeding | 24 | Deep laceration, severe burn |
| OB/Maternal | Pregnancy, labor | 13 | Contractions at 32 weeks, bleeding |
| Pediatric | Children/infants | 12 | Infant fever, child vomiting |
| Neuro | Stroke, seizure | 7 | Sudden weakness, worst headache |
| GI | Abdominal, digestive | 6 | Severe abdominal pain, GI bleeding |
| Respiratory | Breathing, asthma | 6 | COPD exacerbation, wheezing |
| Mental Health | Behavioral crises | 5 | Suicide risk, panic attack |
| CHF | Heart failure | 4 | Dyspnea, edema, chest pain |
| ED | Emergency/acute | All | Multi-trauma, critical |
| PreOp | Pre-surgical | 2 | Surgical clearance |
Each nurse is optimized with domain-specific training data using DSPy's BootstrapFewShot.
Optimize Nurses
Optimize a Specific Nurse
stcc-optimize --role wound_care_nurse
# Other roles: ob_nurse, pediatric_nurse, neuro_nurse, gi_nurse,
# respiratory_nurse, mental_health_nurse, chf_nurse, ed_nurse, preop_nurse
Output:
Compiling Specialized Agent: Wound Care Nurse
Training set: 16 specialized cases
Distribution:
emergency: 4 cases
home_care: 4 cases
moderate: 4 cases
urgent: 4 cases
Optimizing for Wound Care Nurse...
This may take 5-10 minutes...
โ Compiled Wound Care Nurse agent saved to:
user_data/compiled/compiled_wound_care_nurse_agent.json
Optimize All Nurses
stcc-optimize
This compiles all 10 specialized nurses (takes ~1 hour).
Launch API Server
# Launch FastAPI server
stcc-api
# With auto-reload for development
stcc-api --reload
# Custom host/port
stcc-api --host 127.0.0.1 --port 8080
Visit http://localhost:8000/docs for interactive API documentation.
Example API Usage:
# Basic triage
curl -X POST "http://localhost:8000/triage" \
-H "Content-Type: application/json" \
-d '{"symptoms": "severe chest pain for 30 minutes"}'
# Specialized nurse triage
curl -X POST "http://localhost:8000/triage/specialized" \
-H "Content-Type: application/json" \
-d '{"symptoms": "deep laceration with active bleeding", "nurse_role": "wound_care_nurse"}'
Architecture
Package Structure
dspy-stcc-homecare/
โโโ stcc_triage/ # Main package
โ โโโ core/ # Core triage logic
โ โ โโโ agent.py # STCCTriageAgent
โ โ โโโ signatures.py # DSPy signatures
โ โ โโโ settings.py # DeepSeek config
โ โ โโโ paths.py # Path management
โ โ
โ โโโ nurses/ # Specialized nurses
โ โ โโโ roles.py # NurseRole enum
โ โ โโโ specialized.py # WoundCareNurse, OBNurse, etc.
โ โ
โ โโโ datasets/ # Dataset generation
โ โ โโโ schema.py # PatientCase schema
โ โ โโโ generator.py # Dataset generator
โ โ โโโ cases/ # Case definitions
โ โ
โ โโโ optimizers/ # Optimization logic
โ โ โโโ metric.py # Safety metrics
โ โ โโโ optimizer.py # BootstrapFewShot config
โ โ โโโ compiler.py # Compilation logic
โ โ
โ โโโ protocols/ # Protocol handling
โ โ โโโ parser.py # Protocol parser
โ โ โโโ context.py # Context enrichment
โ โ
โ โโโ ui/ # Streamlit UI
โ โ โโโ app.py # Main app
โ โ โโโ components/ # UI components
โ โ
โ โโโ api/ # FastAPI deployment
โ โ โโโ app.py # FastAPI app
โ โ โโโ models.py # API models
โ โ
โ โโโ cli/ # CLI commands
โ โ โโโ ui.py # stcc-ui
โ โ โโโ optimize.py # stcc-optimize
โ โ โโโ api.py # stcc-api
โ โ โโโ parse.py # stcc-parse-protocols
โ โ
โ โโโ data/ # Bundled data
โ โโโ protocols/ # STCC protocols (~2MB)
โ
โโโ user_data/ # User-generated (gitignored)
โ โโโ compiled/ # Compiled nurses
โ โโโ datasets/ # Generated datasets
โ
โโโ protocols/ # Generated protocols.json
How It Works
- Protocol Context: Enriches patient symptoms with relevant STCC protocol guidelines
- DSPy ChainOfThought: Structured reasoning with transparent decision-making
- DeepSeek R1: Advanced reasoning engine with medical knowledge
- BootstrapFewShot: Automatic optimization with domain-specific examples
- Safety Metrics: Prevents under-triage (missing emergencies = score 0.0)
CLI Reference
# Launch Web UI
stcc-ui
# Optimize nurses
stcc-optimize # All nurses
stcc-optimize --role wound_care_nurse # Specific nurse
stcc-optimize --regenerate-data # Force regenerate training data
# Launch API server
stcc-api # Default: 0.0.0.0:8000
stcc-api --host 127.0.0.1 --port 8080 # Custom host/port
stcc-api --reload # Auto-reload for dev
# Parse protocols
stcc-parse-protocols # (Optional) Re-parse STCC markdown files
Python API Reference
# Core imports
from stcc_triage import STCCTriageAgent, TriageSignature, FollowUpSignature
# Specialized nurses
from stcc_triage.nurses import (
WoundCareNurse,
OBNurse,
PediatricNurse,
NeuroNurse,
GINurse,
RespiratoryNurse,
MentalHealthNurse,
CHFNurse,
EDNurse,
PreOpNurse,
GeneralNurse,
NurseRole,
)
# Optimization
from stcc_triage.optimizers import optimize_nurse, load_compiled_nurse
# Dataset generation
from stcc_triage.datasets import generate_all_specialized_datasets
# Protocol parsing
from stcc_triage.protocols import parse_all_protocols
Development
Run Tests
pytest tests/
Code Quality
# Format code
ruff format .
# Lint code
ruff check .
# Type checking
mypy stcc_triage/
Troubleshooting
"protocols.json not found"
This should only happen in development. The protocols are pre-bundled when installing from PyPI.
# For development only - regenerate protocols
stcc-parse-protocols
"Compiled agent not found"
stcc-optimize --role wound_care_nurse
Import errors after installation
pip install -e . # Reinstall in editable mode
License
MIT License - See LICENSE
Contributing
Contributions welcome! This is an educational project demonstrating DSPy optimization for domain-specific agents.
Citation
If you use this project in research:
@software{stcc_triage_agent,
title = {STCC Triage Agent: DSPy Extension for Medical Triage},
author = {STCC Triage Agent Contributors},
year = {2025},
url = {https://github.com/chenhaodev/dspy-stcc-homecare}
}
Acknowledgments
- STCC Protocols: Schmitt-Thompson Clinical Content (225 protocols)
- DSPy: Stanford NLP's programming framework for LMs
- DeepSeek: Advanced reasoning engine with medical knowledge
Built with DSPy โข Optimized for Safety โข Educational Use Only
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dspy_stcc_homecare-2.0.1.tar.gz.
File metadata
- Download URL: dspy_stcc_homecare-2.0.1.tar.gz
- Upload date:
- Size: 7.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c375555a30642c64edb8d36480d1fd1cf5a52676b623010189669fa6ce5e05e1
|
|
| MD5 |
14616fe7d477427dc7605b12fa71dbc7
|
|
| BLAKE2b-256 |
aca42bcb13e36a67c832cd72fdce03b48ca4b4ed12e8ac3b51f5c1e9d7889ae5
|
File details
Details for the file dspy_stcc_homecare-2.0.1-py3-none-any.whl.
File metadata
- Download URL: dspy_stcc_homecare-2.0.1-py3-none-any.whl
- Upload date:
- Size: 491.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9efe679378306376eb27a5e95bff870253427c68ccd053884dec84e6bf33612
|
|
| MD5 |
d5958ae93cab9a368c8b5b150ff8052a
|
|
| BLAKE2b-256 |
88e8331b1fdff18fdf50e711f6a4261e34f7e13fbb92427e001681207fd81bcd
|