CoolFace
Apppublic

deep-thinker/er-triage-env

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

๐Ÿฅ ER Triage Decision Environment (OpenEnv)

๐Ÿ“Œ Overview

This project implements a real-world reinforcement learning environment simulating emergency room (ER) triage decisions.

The agent acts as a triage nurse, assigning:

  • โ€”ESI level (1โ€“5) โ†’ urgency classification
  • โ€”Care pathway โ†’ treatment routing

The goal is to maximize patient safety and triage accuracy.


๐ŸŽฏ Problem Motivation

Emergency triage is a high-stakes decision-making task:

  • โ€”Under-triage โ†’ life-threatening delays
  • โ€”Over-triage โ†’ resource overload
  • โ€”Ambiguous cases โ†’ require reasoning

This environment evaluates whether AI systems can:

  • โ€”interpret patient data
  • โ€”make safe decisions
  • โ€”handle uncertainty

๐Ÿง  Environment Design

๐Ÿ”น Observation Space

Each observation represents a patient:

python
PatientObservation:
    patient_id: str
    age: int
    chief_complaint: str
    vitals: Dict[str, float]
    symptoms: List[str]
    medical_history: List[str]
    arrival_mode: str
    time_in_waiting_room_minutes: int
    queue_length: int
    task_id: str
    done: bool
    reward: float
    masked: bool
    attempts_remaining: int
    message: str

๐Ÿ”น Action Space

python
TriageAction:
    triage_level: int  # 1 (most urgent) to 5 (least urgent)
    care_pathway: str  # resuscitation | acute | fast_track | observation | discharge_likely
    confidence: float  # 0.0 to 1.0

๐Ÿ”น State

python
ERTriageState:
    episode_id: str
    step_count: int
    current_patient_id: str
    task_id: str
    max_attempts: int

๐Ÿ” Interaction Flow

text
reset() โ†’ returns patient case
step(action) โ†’ returns reward + feedback
state โ†’ environment metadata

Each episode:

  • โ€”One patient case
  • โ€”Agent makes triage decision
  • โ€”Reward assigned
  • โ€”Episode ends

๐ŸŽฏ Tasks (Difficulty Levels)

The environment includes 3 task categories:

๐ŸŸข 1. Classic Presentations (Easy)

  • โ€”Clear symptoms
  • โ€”Obvious triage decisions
  • โ€”Example: cardiac arrest, severe trauma

๐ŸŸก 2. Ambiguous Cases (Medium)

  • โ€”Mixed symptoms
  • โ€”Requires reasoning
  • โ€”Example: chest pain + anxiety

๐Ÿ”ด 3. Masked Presentations (Hard)

  • โ€”Hidden or misleading symptoms
  • โ€”High risk of misclassification
  • โ€”Example: atypical heart attack

๐Ÿ“Š Reward Design (0.0 โ†’ 1.0)

The reward function is continuous and safety-aware.

โœ… Base scoring:

  • โ€”Correct ESI โ†’ 0.7
  • โ€”Off by 1 โ†’ 0.4
  • โ€”Off by 2 โ†’ 0.2
  • โ€”Incorrect โ†’ 0.0

โž• Bonus:

  • โ€”Correct care pathway โ†’ +0.2
  • โ€”Confidence (if correct) โ†’ +0.1 ร— confidence

โž– Penalty:

  • โ€”Incorrect confident decisions โ†’ โˆ’0.05 ร— confidence
  • โ€”Critical under-triage โ†’ 0.0 (severe penalty)

๐Ÿ”’ Final reward:

text
Clamped between 0.0 and 1.0

๐Ÿงช Example Interaction

python
obs = env.reset()

action = TriageAction(
    triage_level=2,
    care_pathway="acute",
    confidence=0.8
)

result = env.step(action)

print(result.reward)
print(result.message)

โš™๏ธ Setup Instructions

1. Install dependencies

bash
pip install -r requirements.txt

2. Run locally

bash
uvicorn server.app:app --reload

Check:

http://localhost:8000/health

3. Run inference

bash
export HF_TOKEN=your_token
export MODEL_NAME=your_model
export ENV_BASE_URL=http://localhost:8000

python inference.py

๐Ÿณ Docker

Build:

bash
docker build -t er-triage-env -f server/Dockerfile .

Run:

bash
docker run -p 8000:8000 er-triage-env

๐ŸŒ Deployment (Hugging Face)

bash
openenv push --repo-id <username>/er-triage-env

Access:

https://<username>-er-triage-env.hf.space

๐Ÿ“ˆ Evaluation

The system is evaluated on:

  • โ€”Accuracy of ESI classification
  • โ€”Correct care pathway
  • โ€”Safety (avoiding under-triage)
  • โ€”Robustness across tasks

Final score:

text
Average across all tasks

๐Ÿš€ Key Features

  • โ€”โœ… Real-world healthcare scenario
  • โ€”โœ… Continuous reward function (not binary)
  • โ€”โœ… Multi-difficulty tasks
  • โ€”โœ… Safety-aware penalties
  • โ€”โœ… Type-safe design
  • โ€”โœ… OpenEnv compliant

โš ๏ธ Notes

  • โ€”Ground truth labels are never exposed to the agent
  • โ€”Masked tasks intentionally hide key signals
  • โ€”Designed to challenge advanced LLM reasoning

๐Ÿง  Summary

This environment tests whether AI systems can make safe, accurate, and context-aware medical triage decisions under uncertainty.