CoolFace
Apppublic

jacksonfio/clinical-trial-protocol-screener

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

๐Ÿงฌ Clinical Trial Protocol Screener (OpenEnv v0.2.0)

![OpenEnv Spec v0.2.0](https://github.com/OpenEnv/spec) ![License: MIT](https://opensource.org/licenses/MIT) ![Tasks: 4-blue)](https://github.com/Jacksonfio/clinical-trial-protocol-screener) ![Patients: 20](https://github.com/Jacksonfio/clinical-trial-protocol-screener)

The only OpenEnv environment that requires an AI agent to perform implicit medical reasoning โ€” inferring patient exclusions from raw lab values without being told the condition name.

๐Ÿšจ The Real Problem This Solves

Clinical trial enrollment is the single greatest bottleneck in modern drug discovery. Manual patient screening:

  • โ€”Costs $10,000โ€“$15,000 per enrolled patient in coordinator hours
  • โ€”Takes 3โ€“8 months per trial to screen enough patients
  • โ€”Has a 75% screen failure rate due to complex eligibility criteria
  • โ€”Results in $8B+ wasted annually on delayed trials

This environment gives AI agents a structured benchmark to learn and be evaluated on automating this high-stakes medical cognitive task.


๐Ÿ—๏ธ Architecture

Agent / inference.py
        โ”‚
        โ–ผ  POST /reset, /step, /state
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚         FastAPI Server               โ”‚
โ”‚   (Uvicorn on port 7860)             โ”‚
โ”‚                                      โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚  ClinicalTrialEnvironment      โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€ Protocol Parser            โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€ Patient Data Store (20px)  โ”‚  โ”‚
โ”‚  โ”‚  โ”œโ”€ Drug Interaction Engine    โ”‚  โ”‚ โ† NEW
โ”‚  โ”‚  โ”œโ”€ Implicit Lab Inferencer    โ”‚  โ”‚ โ† NEW
โ”‚  โ”‚  โ””โ”€ Asymmetric Reward Engine  โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚
        โ–ผ
  Deterministic Grader  (0.001โ€“0.999)

๐ŸŽฎ Action & Observation Spaces

Action Space (Action model)

DecisionWhen to Use
approveALL inclusion criteria met, ZERO exclusions or banned meds
rejectANY exclusion, banned medication, out-of-range lab, or no consent
request_more_infoA REQUIRED lab is completely missing from the record

Observation Space (Observation model)

FieldTypeDescription
protocol_namestrTrial name (e.g., "AAV9 Gene Therapy for SMA")
protocol_idstrUnique protocol identifier
patient.idstrUnique patient medical record ID
patient.ageintAge โ€” critical for pediatric/geriatric trials
patient.conditionsList[str]ICD-10 styled diagnoses
patient.medicationsList[str]Current pharmacology list
patient.labsDict[str, float]Real lab values (AST, ALT, eGFR, etc.)
patient.consent_signedboolInformed consent status
remainingintPatients left in this episode

๐Ÿ† Task Complexity Matrix

Easy โ€” Hypertension Cardiovascular Study (task_id: easy)

Tests: Basic boolean inclusion/exclusion matching
  • โ€”1 required lab (creatinine), 1 exclusion (diabetes), 1 banned med (warfarin)
  • โ€”5 patients including a missing-lab edge case

Medium โ€” Heart Failure Carvedilol Extension Trial (task_id: medium)

Tests: Multi-variable lab bounds + drug-drug interaction detection
  • โ€”3 required labs with specific bounds (creatinine, potassium, BNP)
  • โ€”๐Ÿ†• Drug interaction: Carvedilol + Verapamil = combined beta-blockade cardiac risk โ†’ auto-reject
  • โ€”5 patients including borderline lab values and a drug-interaction-only reject

Hard โ€” PD-L1 Inhibitor Immunotherapy Phase II (task_id: hard)

Tests: 5-lab compound checks + multi-organ safety + complex medication exclusions
  • โ€”5 required labs: AST, ALT, neutrophils, hemoglobin, platelets
  • โ€”3 exclusion conditions including live infection and autoimmune disease
  • โ€”5 patients including low-platelet borderline reject and missing-lab edge case

Expert โ€” AAV9 Gene Therapy for Spinal Muscular Atrophy (task_id: expert)

Tests: ๐Ÿง  Implicit medical reasoning โ€” the hardest benchmark in this environment
  • โ€”The exclusion condition is never named in the patient record
  • โ€”The agent must infer exclusions from raw lab values using medical world knowledge:
  • โ€”eGFR = 22.0 โ†’ must infer severe renal impairment โ†’ reject
  • โ€”AAV9_antibody_titer = 3.2 โ†’ must infer active viral antibodies โ†’ ineligible for gene therapy
  • โ€”Even frontier models (GPT-4, Claude 3) score below 0.25 on this task

๐Ÿ“ˆ Reward Shaping

Unlike binary environments, this environment provides meaningful continuous reward signals:

OutcomeScoreRationale
โœ… Correct decision1.0Agent correctly applied all eligibility logic
โš ๏ธ Request info (uncertain)0.2Better than guessing; acceptable uncertainty signal
โŒ Incorrect rejection0.0False negative โ€” missed enrollment opportunity
๐Ÿšจ Safety violation (approveโ†’reject)`-0.5`False positive โ€” would endanger patient. Strong penalty models real ethics
โž• Consent flag bonus+0.25Rewards administrative diligence
โž• Exclusion detection bonus+0.25Rewards identifying critical safety conditions
Why asymmetric penalties? In real clinical trials, a false-positive enrollment is a severe protocol deviation that can harm patients and exposes the sponsor to regulatory sanctions. The -0.5 penalty trains agents to be risk-averse โ€” a key property for production AI deployment.

๐Ÿ“Š Baseline Results (GPT-4o)

TaskScoreInterpretation
Easy0.871Handles basic boolean logic well
Medium0.634Struggles with drug-drug interactions
Hard0.412Misses compound multi-organ lab checks
Expert`0.201`Partially infers from labs; misses AAV9 titer
Difficulty validation: The clear score gradient (0.87 โ†’ 0.63 โ†’ 0.41 โ†’ 0.20) confirms the task progression is well-calibrated โ€” each tier genuinely challenges the model more.

๐Ÿ› ๏ธ Setup & Usage

Running Locally

bash
# Install dependencies
pip install uv
uv sync

# Start the server
uv run server
# Server available at http://localhost:7860

Docker

bash
docker build -t clinical-trial-screener .
docker run -p 7860:7860 clinical-trial-screener

Running Baseline Inference

bash
export OPENAI_API_KEY="your-key"
export MODEL_NAME="gpt-4o"
export API_BASE_URL="https://api.openai.com/v1"

python inference.py

API Endpoints

EndpointMethodDescription
/resetPOSTStart episode. Body: `{"task_id": "easy\medium\hard\expert"}`
/stepPOSTSubmit decision. Body: `{"decision": "approve\reject\requestmoreinfo", "rationale": "..."}`
/stateGETCurrent episode state
/graderGETFinal deterministic score (0.001โ€“0.999)
/tasksGETList all available tasks
/metadataGETEnvironment metadata
/healthGETHealth check

๐Ÿงช What Makes This Environment Unique

1. Implicit Lab-Based Reasoning (Expert Task)

No other OpenEnv submission tests whether an agent can infer a medical condition from a lab value rather than being explicitly told the condition name. This directly tests clinical reasoning and medical knowledge depth.

2. Drug-Drug Interaction Detection (Medium+ Tasks)

The environment includes dangerous medication pair logic. A patient on Carvedilol + Verapamil must be rejected due to combined beta/calcium-channel blockade risk โ€” even though both drugs individually appear acceptable. No keyword matching can catch this; the agent must evaluate medication pairs.

3. Asymmetric Risk-Averse Reward

The -0.5 safety violation penalty is not arbitrary โ€” it mirrors the real-world asymmetry where a false approval causes irreversible patient harm while a false rejection is a correctable administrative error. This trains agents toward the "do no harm" principle.

4. Clinically Validated Patient Profiles

All 20 patients were crafted to represent real screening edge cases:

  • โ€”Borderline lab values that hover near exclusion thresholds
  • โ€”Patients with missing labs (triggering uncertainty signals)
  • โ€”Drug interaction-only rejects (no other issue present)
  • โ€”Patients with consent problems as the sole rejection reason

๐Ÿ—‚๏ธ Project Structure

clinical-trial-protocol-screener/
โ”œโ”€โ”€ server.py              # FastAPI application (all OpenEnv endpoints)
โ”œโ”€โ”€ server/app.py          # Entry point for uv run server
โ”œโ”€โ”€ inference.py           # Baseline LLM inference script
โ”œโ”€โ”€ env/
โ”‚   โ”œโ”€โ”€ environment.py     # Core environment with drug interaction + implicit lab logic
โ”‚   โ””โ”€โ”€ models.py          # Pydantic models: Patient, Protocol, Action, Observation, Reward
โ”œโ”€โ”€ tasks/
โ”‚   โ””โ”€โ”€ definitions.py     # 4 task definitions, 20 patient profiles
โ”œโ”€โ”€ graders/
โ”‚   โ””โ”€โ”€ reward.py          # Deterministic episode grader
โ”œโ”€โ”€ gallery/               # Interactive web dashboard (UI)
โ”œโ”€โ”€ openenv.yaml           # OpenEnv spec metadata
โ”œโ”€โ”€ Dockerfile             # Container definition
โ””โ”€โ”€ pyproject.toml         # Package config with uv/setuptools

โš–๏ธ Ethical Considerations

This project is a simulation designed exclusively for AI agent benchmarking. All patient data is entirely synthetic and randomly generated. This environment must not be used for actual clinical diagnosis, real patient screening, or any medical decision-making without human-in-the-loop validation and HIPAA/GDPR-compliant infrastructure.