| title | ClinicalTrialEnv |
|---|---|
| emoji | 🧬 |
| colorFrom | blue |
| colorTo | green |
| sdk | docker |
| app_port | 7860 |
ClinicalTrialEnv is a live OpenEnv reinforcement-learning environment for adaptive Phase II clinical trial design. Agents act as autonomous trial statisticians: they choose cohort size, allocation across dose arms, early stopping, arm dropping, and patient inclusion strictness to reach significance quickly while strictly protecting patient safety.
The Challenge: Ethics vs. Optimization
Standard environments optimize for a simple score. ClinicalTrialEnv forces AI agents to formulate high-stakes trade-offs. The agent must balance mathematical optimization (powering a trial, achieving statistical significance, managing budget) against severe ethical constraints (limiting adverse patient events, avoiding over-enrollment in rare diseases, and swiftly dropping unsafe high-dose arms).
Built by Manas Dutta.
task_1: effective drug with a clear signal and a 200-patient budgettask_2: efficacy versus safety tradeoff with a risky high-dose armtask_3: rare-disease setting with only 150 patients and weak effects
The environment exposes trial progress, response rates, adverse-event rates, patient counts, p-values, Bayesian posterior probabilities, estimated power, active-arm flags, and stop metadata. The full schema is available from GET /tasks and GET /schema.
Agents submit:
n_next_cohortallocation_controlallocation_lowallocation_midallocation_highstop_for_successstop_for_futilitydrop_arminclusion_criteria_strictness
cd clinical_trial_env
pip install openenv-core
pip install -e .
uvicorn server.app:app --port 7860 --reloadOpen:
http://localhost:7860/for the custom dashboardhttp://localhost:7860/webfor the OpenEnv built-in UI
Run the LLM agent against the live environment:
API_BASE_URL=<url> MODEL_NAME=<model> HF_TOKEN=<token> python inference.pyinference.py is the hackathon submission agent used by judges against the deployed environment.
- It uses the OpenAI client for all model calls through an OpenAI-compatible endpoint.
- It emits exact
[START],[STEP], and[END]structured logs for evaluation. - By default it targets
meta-llama/Llama-3.1-8B-Instructthrough the Hugging Face Inference API. - It can be redirected to any OpenAI-compatible API by setting
API_BASE_URLandMODEL_NAME. - If model calls fail, it falls back to a built-in heuristic so the run still completes.
| Endpoint | Method | Purpose |
|---|---|---|
/ |
GET | Serve the custom dashboard directly with HTTP 200 |
/web |
GET | OpenEnv built-in web UI |
/health |
GET | Healthcheck for deployment validators |
/tasks |
GET | List tasks plus action_schema |
/reset |
POST | Start an HTTP episode for validator compatibility |
/step |
POST | Step the latest active HTTP episode |
/grader |
POST | Return the final normalized score for the latest completed episode |
/baseline |
POST | Run the heuristic agent across all three tasks |
/ws |
WebSocket | Main OpenEnv interaction channel |
WebSocket reset:
{"type": "reset", "data": {"task_id": "task_1"}}WebSocket step:
{"type": "step", "data": {"n_next_cohort": 25, "allocation_control": 0.25, "allocation_low": 0.25, "allocation_mid": 0.25, "allocation_high": 0.25, "stop_for_success": false, "stop_for_futility": false, "drop_arm": null, "inclusion_criteria_strictness": 0.5}}| Task | Typical Score | Outcome | Notes |
|---|---|---|---|
task_1 |
~0.8 | success |
Clear efficacy signal with efficient stopping |
task_2 |
~0.55-0.65 | success |
Balances efficacy with AE control |
task_3 |
~0.2-0.4 | futility |
Futility is often the correct behavior because the task is designed to reward efficient rare-disease decision making, not forced over-enrollment |
clinical_trial_env/Environment_Demo.ipynb is a runnable Colab notebook that connects to the live Space, runs a heuristic policy over WebSocket, plots p-value trajectories, and fetches the final grader breakdown.
openenv push --repo-id manasdutta04/clinicaltrialenv