Spaces:
Sleeping
Sleeping
Update env.py
Browse files
env.py
CHANGED
|
@@ -1,457 +1,381 @@
|
|
| 1 |
-
"""Core RL
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
-
|
| 6 |
-
from
|
| 7 |
-
from typing import Any, Dict, List,
|
| 8 |
from uuid import uuid4
|
| 9 |
|
| 10 |
-
from openenv.core.env_server.
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
INCREMENTAL_REWARD = 0.20
|
| 20 |
FINAL_REWARD = 1.00
|
| 21 |
HALLUCINATION_PENALTY = -0.50
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
@dataclass(frozen=True)
|
| 25 |
-
class ScreeningTask:
|
| 26 |
task_id: str
|
| 27 |
-
difficulty:
|
| 28 |
title: str
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
@dataclass
|
| 39 |
-
class TaskRunState:
|
| 40 |
-
extracted_points: Dict[str, str] = field(default_factory=dict)
|
| 41 |
-
granted_rewards: Set[str] = field(default_factory=set)
|
| 42 |
-
final_submitted: bool = False
|
| 43 |
-
latest_grader_score: float = 0.0
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
def _build_tasks() -> List[ScreeningTask]:
|
| 47 |
-
medium_scores = {
|
| 48 |
-
"P-M101": 0.88,
|
| 49 |
-
"P-M102": 0.71,
|
| 50 |
-
"P-M103": 0.54,
|
| 51 |
-
}
|
| 52 |
-
return [
|
| 53 |
-
ScreeningTask(
|
| 54 |
-
task_id="easy_eligibility",
|
| 55 |
-
difficulty=TaskDifficulty.EASY,
|
| 56 |
-
title="Phase II EGFR-Mutated NSCLC Eligibility Check",
|
| 57 |
-
brief="Determine whether the candidate meets five binary enrollment criteria.",
|
| 58 |
-
prompt=(
|
| 59 |
-
"Trial CT-NSCLC-201 enrolls adults with metastatic EGFR exon 19 or L858R "
|
| 60 |
-
"non-small cell lung cancer after first-line osimertinib. Candidate E-001 is "
|
| 61 |
-
"47 years old with biopsy-proven metastatic lung adenocarcinoma, EGFR exon 19 "
|
| 62 |
-
"deletion, ECOG 1, no active brain metastases, and adequate hepatic function. "
|
| 63 |
-
"Binary criteria: age >=18, confirmed metastatic NSCLC, sensitizing EGFR "
|
| 64 |
-
"mutation present, ECOG 0-1, no active CNS disease."
|
| 65 |
-
),
|
| 66 |
-
extraction_targets={
|
| 67 |
-
"age": "47",
|
| 68 |
-
"diagnosis": "metastatic nsclc",
|
| 69 |
-
"biomarker": "egfr exon 19 deletion",
|
| 70 |
-
"ecog": "1",
|
| 71 |
-
"active_cns_disease": "no",
|
| 72 |
-
},
|
| 73 |
-
expected_decision="eligible",
|
| 74 |
-
trial_metadata={
|
| 75 |
-
"trial_id": "CT-NSCLC-201",
|
| 76 |
-
"specialty": "thoracic oncology",
|
| 77 |
-
"binary_criteria": [
|
| 78 |
-
"adult patient",
|
| 79 |
-
"metastatic NSCLC confirmed",
|
| 80 |
-
"sensitizing EGFR mutation",
|
| 81 |
-
"ECOG 0-1",
|
| 82 |
-
"no active CNS disease",
|
| 83 |
-
],
|
| 84 |
-
},
|
| 85 |
-
),
|
| 86 |
-
ScreeningTask(
|
| 87 |
-
task_id="medium_patient_ranking",
|
| 88 |
-
difficulty=TaskDifficulty.MEDIUM,
|
| 89 |
-
title="Rank Patients for TROP2 ADC Expansion Cohort",
|
| 90 |
-
brief="Rank three real-world candidates by protocol fit-score for an EGFR-mutated NSCLC study.",
|
| 91 |
-
prompt=(
|
| 92 |
-
"Trial CT-LUNG-312 is an antibody-drug conjugate study for metastatic EGFR-mutated "
|
| 93 |
-
"NSCLC after progression on osimertinib. Rank candidates by expected screening fit. "
|
| 94 |
-
"P-M101: 56 years, EGFR exon 19 deletion, post-osimertinib only, ECOG 0, stable "
|
| 95 |
-
"treated brain metastases, CrCl 82 mL/min, AST/ALT normal. P-M102: 63 years, EGFR "
|
| 96 |
-
"L858R, post-osimertinib and platinum, ECOG 1, mild AST elevation 1.4x ULN, no "
|
| 97 |
-
"brain metastases, CrCl 68. P-M103: 59 years, exon 20 insertion, ECOG 1, chronic "
|
| 98 |
-
"prednisone 15 mg, recent palliative radiation 5 days ago, CrCl 61. Internal fit "
|
| 99 |
-
f"scores are predetermined as {medium_scores}."
|
| 100 |
-
),
|
| 101 |
-
extraction_targets={
|
| 102 |
-
"P-M101_fit_score": "0.88",
|
| 103 |
-
"P-M102_fit_score": "0.71",
|
| 104 |
-
"P-M103_fit_score": "0.54",
|
| 105 |
-
"best_candidate": "P-M101",
|
| 106 |
-
"lowest_candidate": "P-M103",
|
| 107 |
-
},
|
| 108 |
-
expected_decision="P-M101>P-M102>P-M103",
|
| 109 |
-
ranking_ground_truth=["P-M101", "P-M102", "P-M103"],
|
| 110 |
-
trial_metadata={
|
| 111 |
-
"trial_id": "CT-LUNG-312",
|
| 112 |
-
"specialty": "thoracic oncology",
|
| 113 |
-
"ranking_rule": "higher fit-score ranks earlier",
|
| 114 |
-
"fit_scores": medium_scores,
|
| 115 |
-
},
|
| 116 |
-
),
|
| 117 |
-
ScreeningTask(
|
| 118 |
-
task_id="hard_protocol_deviations",
|
| 119 |
-
difficulty=TaskDifficulty.HARD,
|
| 120 |
-
title="Identify Protocol Deviations from Unstructured Screening Note",
|
| 121 |
-
brief="Extract exclusions and protocol deviations from a realistic unstructured chart note.",
|
| 122 |
-
prompt=(
|
| 123 |
-
"Trial CT-LYMPH-440 is a CD19 bispecific study for relapsed diffuse large B-cell "
|
| 124 |
-
"lymphoma. Exclusions include prednisone >10 mg/day within 7 days, live vaccine "
|
| 125 |
-
"within 30 days, active hepatitis B viremia, ANC <1.0 x10^9/L, and major surgery "
|
| 126 |
-
"within 14 days. Screening note: 'Mr. R is a 68-year-old man with relapsed DLBCL. "
|
| 127 |
-
"He received a shingles live-attenuated vaccine 12 days ago at his PCP visit. He "
|
| 128 |
-
"remains on prednisone 20 mg daily for COPD flare and underwent laparoscopic "
|
| 129 |
-
"cholecystectomy 9 days ago. Labs today: ANC 0.9, HBV DNA undetectable on entecavir, "
|
| 130 |
-
"bilirubin normal. Team asks whether any items trigger screen failure or protocol "
|
| 131 |
-
"deviation before scheduling first dose.'"
|
| 132 |
-
),
|
| 133 |
-
extraction_targets={
|
| 134 |
-
"age": "68",
|
| 135 |
-
"live_vaccine_days": "12",
|
| 136 |
-
"prednisone_mg": "20",
|
| 137 |
-
"surgery_days": "9",
|
| 138 |
-
"anc": "0.9",
|
| 139 |
-
},
|
| 140 |
-
expected_decision="exclude",
|
| 141 |
-
exclusion_ground_truth={
|
| 142 |
-
"live_vaccine_within_30_days",
|
| 143 |
-
"prednisone_over_10mg",
|
| 144 |
-
"major_surgery_within_14_days",
|
| 145 |
-
"anc_below_1.0",
|
| 146 |
-
},
|
| 147 |
-
trial_metadata={
|
| 148 |
-
"trial_id": "CT-LYMPH-440",
|
| 149 |
-
"specialty": "hematologic malignancy",
|
| 150 |
-
"expected_exclusion_schema": [
|
| 151 |
-
"live_vaccine_within_30_days",
|
| 152 |
-
"prednisone_over_10mg",
|
| 153 |
-
"major_surgery_within_14_days",
|
| 154 |
-
"anc_below_1.0",
|
| 155 |
-
"active_hbv_viremia",
|
| 156 |
-
],
|
| 157 |
-
},
|
| 158 |
-
),
|
| 159 |
-
]
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
def _normalize(value: str | None) -> str:
|
| 163 |
-
return "" if value is None else value.strip().lower()
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
class EasyEligibilityGrader:
|
| 167 |
-
@staticmethod
|
| 168 |
-
def grade(task: ScreeningTask, task_state: TaskRunState, decision: str | None = None) -> float:
|
| 169 |
-
extracted = sum(
|
| 170 |
-
1
|
| 171 |
-
for field_name, expected in task.extraction_targets.items()
|
| 172 |
-
if _normalize(task_state.extracted_points.get(field_name)) == _normalize(expected)
|
| 173 |
-
)
|
| 174 |
-
extraction_score = extracted / len(task.extraction_targets)
|
| 175 |
-
decision_score = 1.0 if _normalize(decision) == _normalize(task.expected_decision) else 0.0
|
| 176 |
-
return round((0.5 * extraction_score) + (0.5 * decision_score), 4)
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
class MediumRankingGrader:
|
| 180 |
-
@staticmethod
|
| 181 |
-
def grade(task: ScreeningTask, task_state: TaskRunState, ranking: Sequence[str] | None = None) -> float:
|
| 182 |
-
extracted = sum(
|
| 183 |
-
1
|
| 184 |
-
for field_name, expected in task.extraction_targets.items()
|
| 185 |
-
if _normalize(task_state.extracted_points.get(field_name)) == _normalize(expected)
|
| 186 |
-
)
|
| 187 |
-
extraction_score = extracted / len(task.extraction_targets)
|
| 188 |
-
ranking = list(ranking or [])
|
| 189 |
-
if len(ranking) != len(task.ranking_ground_truth):
|
| 190 |
-
ranking_score = 0.0
|
| 191 |
-
else:
|
| 192 |
-
correct_positions = sum(
|
| 193 |
-
1
|
| 194 |
-
for observed, expected in zip(ranking, task.ranking_ground_truth)
|
| 195 |
-
if observed == expected
|
| 196 |
-
)
|
| 197 |
-
ranking_score = correct_positions / len(task.ranking_ground_truth)
|
| 198 |
-
return round((0.4 * extraction_score) + (0.6 * ranking_score), 4)
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
class HardDeviationGrader:
|
| 202 |
-
@staticmethod
|
| 203 |
-
def grade(
|
| 204 |
-
task: ScreeningTask,
|
| 205 |
-
task_state: TaskRunState,
|
| 206 |
-
exclusions: Sequence[str] | None = None,
|
| 207 |
-
decision: str | None = None,
|
| 208 |
-
) -> float:
|
| 209 |
-
extracted = sum(
|
| 210 |
-
1
|
| 211 |
-
for field_name, expected in task.extraction_targets.items()
|
| 212 |
-
if _normalize(task_state.extracted_points.get(field_name)) == _normalize(expected)
|
| 213 |
-
)
|
| 214 |
-
extraction_score = extracted / len(task.extraction_targets)
|
| 215 |
-
predicted = {_normalize(item) for item in exclusions or [] if item}
|
| 216 |
-
if task.exclusion_ground_truth:
|
| 217 |
-
exclusion_score = len(predicted & task.exclusion_ground_truth) / len(task.exclusion_ground_truth)
|
| 218 |
-
else:
|
| 219 |
-
exclusion_score = 0.0
|
| 220 |
-
decision_score = 1.0 if _normalize(decision) == _normalize(task.expected_decision) else 0.0
|
| 221 |
-
return round((0.3 * extraction_score) + (0.4 * exclusion_score) + (0.3 * decision_score), 4)
|
| 222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
-
|
| 225 |
-
"""Stateful environment covering easy, medium, and hard screening tasks."""
|
| 226 |
|
| 227 |
def __init__(self) -> None:
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
self.
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
self.
|
| 237 |
-
self.
|
| 238 |
-
self.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
return self._build_observation(
|
| 240 |
-
|
| 241 |
-
|
|
|
|
|
|
|
| 242 |
)
|
| 243 |
|
| 244 |
-
def step(
|
| 245 |
-
self
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
if self.
|
| 252 |
-
|
| 253 |
-
reward.reasons.append("episode_already_complete")
|
| 254 |
-
reward.total = reward.penalty
|
| 255 |
-
return self._build_observation(reward, "Episode already completed. Reset to start a new run.")
|
| 256 |
|
| 257 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
reward.penalty += HALLUCINATION_PENALTY
|
| 259 |
-
reward.
|
| 260 |
-
feedback_parts.append("Destructive action blocked in screening workflow.")
|
| 261 |
-
elif action.action_type == "extract_data":
|
| 262 |
-
feedback_parts.append(self._handle_extract_data(task, task_state, action, reward))
|
| 263 |
-
elif action.action_type == "submit_ranking":
|
| 264 |
-
feedback_parts.append(self._handle_submit_ranking(task, task_state, action, reward))
|
| 265 |
-
elif action.action_type == "flag_exclusions":
|
| 266 |
-
feedback_parts.append(self._handle_flag_exclusions(task, task_state, action, reward))
|
| 267 |
-
elif action.action_type == "final_decision":
|
| 268 |
-
feedback_parts.append(self._handle_final_decision(task, task_state, action, reward))
|
| 269 |
else:
|
| 270 |
reward.penalty += HALLUCINATION_PENALTY
|
| 271 |
-
reward.
|
| 272 |
-
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
-
reward.
|
| 275 |
-
|
| 276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
)
|
| 278 |
-
return self._build_observation(reward, " ".join(part for part in feedback_parts if part))
|
| 279 |
|
| 280 |
-
|
|
|
|
| 281 |
return self._state
|
| 282 |
|
| 283 |
-
def
|
| 284 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
if field_name not in task_state.granted_rewards
|
| 297 |
-
]
|
| 298 |
-
return ClinicalTrialScreeningObservation(
|
| 299 |
-
task_id=task.task_id,
|
| 300 |
-
difficulty=task.difficulty,
|
| 301 |
-
title=task.title,
|
| 302 |
-
brief=task.brief,
|
| 303 |
-
prompt=task.prompt,
|
| 304 |
-
extracted_points=deepcopy(task_state.extracted_points),
|
| 305 |
-
missing_targets=missing_targets,
|
| 306 |
-
available_actions=[
|
| 307 |
-
"extract_data",
|
| 308 |
-
"submit_ranking" if task.difficulty is TaskDifficulty.MEDIUM else "flag_exclusions",
|
| 309 |
-
"final_decision",
|
| 310 |
-
"destructive_action",
|
| 311 |
-
],
|
| 312 |
-
grader_score=task_state.latest_grader_score,
|
| 313 |
-
reward_breakdown=reward_model,
|
| 314 |
-
feedback=feedback,
|
| 315 |
-
done=self._episode_complete,
|
| 316 |
-
reward=reward_model.total,
|
| 317 |
-
trial_metadata=deepcopy(task.trial_metadata),
|
| 318 |
-
)
|
| 319 |
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
return
|
| 347 |
|
| 348 |
-
def
|
| 349 |
-
self
|
| 350 |
-
|
| 351 |
-
task_state: TaskRunState,
|
| 352 |
-
action: ClinicalTrialScreeningAction,
|
| 353 |
-
reward: RewardModel,
|
| 354 |
-
) -> str:
|
| 355 |
-
if task.difficulty is not TaskDifficulty.MEDIUM:
|
| 356 |
reward.penalty += HALLUCINATION_PENALTY
|
| 357 |
-
reward.
|
| 358 |
-
return
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
if is_correct:
|
| 363 |
-
reward.final_reward += FINAL_REWARD
|
| 364 |
-
reward.reasons.append("correct_ranking")
|
| 365 |
-
else:
|
| 366 |
reward.penalty += HALLUCINATION_PENALTY
|
| 367 |
-
reward.
|
| 368 |
-
|
| 369 |
-
self._advance_task()
|
| 370 |
-
return "Ranking accepted." if is_correct else "Ranking accepted but does not match the deterministic fit ordering."
|
| 371 |
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
if task.difficulty is not TaskDifficulty.HARD:
|
| 380 |
reward.penalty += HALLUCINATION_PENALTY
|
| 381 |
-
reward.
|
| 382 |
-
return "Exclusion flagging is reserved for the hard chart-review task."
|
| 383 |
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
|
|
|
| 387 |
reward.penalty += HALLUCINATION_PENALTY
|
| 388 |
-
reward.
|
| 389 |
-
|
| 390 |
-
task,
|
| 391 |
-
task_state,
|
| 392 |
-
exclusions=action.exclusions,
|
| 393 |
-
)
|
| 394 |
-
return f"Unsupported exclusion codes submitted: {sorted(invalid)}."
|
| 395 |
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
)
|
| 401 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
|
| 403 |
-
def
|
| 404 |
self,
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
reward
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
else:
|
| 429 |
-
exclusions = sorted(task.exclusion_ground_truth)
|
| 430 |
-
task_state.latest_grader_score = HardDeviationGrader.grade(
|
| 431 |
-
task,
|
| 432 |
-
task_state,
|
| 433 |
-
exclusions=exclusions,
|
| 434 |
-
decision=decision,
|
| 435 |
-
)
|
| 436 |
|
| 437 |
-
self._advance_task()
|
| 438 |
-
return "Final screening decision accepted." if is_correct else "Final decision conflicts with protocol evidence."
|
| 439 |
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
task: ScreeningTask,
|
| 443 |
-
task_state: TaskRunState,
|
| 444 |
-
action: ClinicalTrialScreeningAction,
|
| 445 |
-
) -> float:
|
| 446 |
-
if task.difficulty is TaskDifficulty.EASY:
|
| 447 |
-
return EasyEligibilityGrader.grade(task, task_state)
|
| 448 |
-
if task.difficulty is TaskDifficulty.MEDIUM:
|
| 449 |
-
return MediumRankingGrader.grade(task, task_state)
|
| 450 |
-
return HardDeviationGrader.grade(task, task_state, exclusions=action.exclusions)
|
| 451 |
-
|
| 452 |
-
def _advance_task(self) -> None:
|
| 453 |
-
if self._index == len(self._tasks) - 1:
|
| 454 |
-
self._episode_complete = True
|
| 455 |
-
return
|
| 456 |
-
self._index += 1
|
| 457 |
|
|
|
|
|
|
| 1 |
+
"""Core RL environment for clinical trial patient screening."""
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
+
import json
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from typing import Any, Dict, List, Optional
|
| 8 |
from uuid import uuid4
|
| 9 |
|
| 10 |
+
from openenv.core.env_server.interfaces import Environment
|
| 11 |
+
from pydantic import BaseModel, Field
|
| 12 |
+
|
| 13 |
+
try:
|
| 14 |
+
from .models import (
|
| 15 |
+
ClinicalTrialAction,
|
| 16 |
+
ClinicalTrialObservation,
|
| 17 |
+
ClinicalTrialReward,
|
| 18 |
+
ClinicalTrialState,
|
| 19 |
+
)
|
| 20 |
+
except ImportError:
|
| 21 |
+
from models import (
|
| 22 |
+
ClinicalTrialAction,
|
| 23 |
+
ClinicalTrialObservation,
|
| 24 |
+
ClinicalTrialReward,
|
| 25 |
+
ClinicalTrialState,
|
| 26 |
+
)
|
| 27 |
|
| 28 |
INCREMENTAL_REWARD = 0.20
|
| 29 |
FINAL_REWARD = 1.00
|
| 30 |
HALLUCINATION_PENALTY = -0.50
|
| 31 |
+
TASK_SEQUENCE = ["easy", "medium", "hard"]
|
| 32 |
+
MIN_STRICT_SCORE = 0.01
|
| 33 |
+
MAX_STRICT_SCORE = 0.99
|
| 34 |
+
DEFAULT_GRADER_SCORE = 0.5
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _normalize(value: Optional[str]) -> str:
|
| 38 |
+
return " ".join((value or "").strip().lower().replace("_", " ").split())
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class GroundTruth(BaseModel):
|
| 42 |
+
"""Deterministic grader targets for a scenario."""
|
| 43 |
|
| 44 |
+
extracted_fields: Dict[str, str] = Field(default_factory=dict)
|
| 45 |
+
ranking: List[str] = Field(default_factory=list)
|
| 46 |
+
final_decision: str
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class ScenarioSpec(BaseModel):
|
| 50 |
+
"""Scenario loaded from patient_data.json."""
|
| 51 |
|
|
|
|
|
|
|
| 52 |
task_id: str
|
| 53 |
+
difficulty: str
|
| 54 |
title: str
|
| 55 |
+
instructions: str
|
| 56 |
+
context: Dict[str, Any]
|
| 57 |
+
ground_truth: GroundTruth
|
| 58 |
+
hidden_exclusions: List[str] = Field(default_factory=list)
|
| 59 |
+
max_steps: int = 6
|
| 60 |
+
grader_name: str = "deterministic_json_grader"
|
| 61 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
class ClinicalTrialEnvironment(
|
| 64 |
+
Environment[ClinicalTrialAction, ClinicalTrialObservation, ClinicalTrialState]
|
| 65 |
+
):
|
| 66 |
+
"""Clinical trial screening environment backed by externalized JSON scenarios."""
|
| 67 |
|
| 68 |
+
SUPPORTS_CONCURRENT_SESSIONS = True
|
|
|
|
| 69 |
|
| 70 |
def __init__(self) -> None:
|
| 71 |
+
super().__init__()
|
| 72 |
+
data_path = Path(__file__).resolve().with_name("patient_data.json")
|
| 73 |
+
payload = json.loads(data_path.read_text(encoding="utf-8"))
|
| 74 |
+
task_payload = payload.get("tasks", {})
|
| 75 |
+
self._scenarios: Dict[str, ScenarioSpec] = {
|
| 76 |
+
task_id: ScenarioSpec.model_validate({**scenario, "task_id": task_id})
|
| 77 |
+
for task_id, scenario in task_payload.items()
|
| 78 |
+
}
|
| 79 |
+
self._task_cursor = -1
|
| 80 |
+
self._current_scenario: Optional[ScenarioSpec] = None
|
| 81 |
+
self._submitted_ranking: List[str] = []
|
| 82 |
+
self._state = ClinicalTrialState(episode_id=str(uuid4()), step_count=0)
|
| 83 |
+
|
| 84 |
+
def reset(
|
| 85 |
+
self,
|
| 86 |
+
seed: Optional[int] = None,
|
| 87 |
+
episode_id: Optional[str] = None,
|
| 88 |
+
task_id: Optional[str] = None,
|
| 89 |
+
**kwargs: Any,
|
| 90 |
+
) -> ClinicalTrialObservation:
|
| 91 |
+
del seed, kwargs
|
| 92 |
+
selected_task_id = task_id or self._next_task_id()
|
| 93 |
+
self._current_scenario = self._scenarios[selected_task_id]
|
| 94 |
+
self._submitted_ranking = []
|
| 95 |
+
self._state = ClinicalTrialState(
|
| 96 |
+
episode_id=episode_id or str(uuid4()),
|
| 97 |
+
step_count=0,
|
| 98 |
+
current_task_id=self._current_scenario.task_id,
|
| 99 |
+
difficulty=self._current_scenario.difficulty,
|
| 100 |
+
title=self._current_scenario.title,
|
| 101 |
+
extracted_fields={},
|
| 102 |
+
identified_deviations=[],
|
| 103 |
+
final_decision=None,
|
| 104 |
+
grading_score=DEFAULT_GRADER_SCORE,
|
| 105 |
+
)
|
| 106 |
return self._build_observation(
|
| 107 |
+
reward_details=ClinicalTrialReward(
|
| 108 |
+
notes=["Episode reset."], grader_score=DEFAULT_GRADER_SCORE
|
| 109 |
+
),
|
| 110 |
+
done=False,
|
| 111 |
)
|
| 112 |
|
| 113 |
+
def step(
|
| 114 |
+
self,
|
| 115 |
+
action: ClinicalTrialAction,
|
| 116 |
+
timeout_s: Optional[float] = None,
|
| 117 |
+
**kwargs: Any,
|
| 118 |
+
) -> ClinicalTrialObservation:
|
| 119 |
+
del timeout_s, kwargs
|
| 120 |
+
if self._current_scenario is None:
|
| 121 |
+
return self.reset()
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
+
self._state.step_count += 1
|
| 124 |
+
reward = ClinicalTrialReward()
|
| 125 |
+
done = False
|
| 126 |
+
terminal_reason: Optional[str] = None
|
| 127 |
+
|
| 128 |
+
if action.action_type == "extract_data":
|
| 129 |
+
self._handle_extraction(action, reward)
|
| 130 |
+
elif action.action_type == "flag_deviation":
|
| 131 |
+
self._handle_deviation_flag(action, reward)
|
| 132 |
+
elif action.action_type == "rank_patients":
|
| 133 |
+
self._handle_ranking(action, reward)
|
| 134 |
+
if action.ranking:
|
| 135 |
+
done = True
|
| 136 |
+
terminal_reason = "ranking_submitted"
|
| 137 |
+
elif action.action_type == "submit_decision":
|
| 138 |
+
self._state.final_decision = action.final_decision
|
| 139 |
+
done = True
|
| 140 |
+
terminal_reason = "final_decision_submitted"
|
| 141 |
+
elif action.action_type == "delete_evidence":
|
| 142 |
reward.penalty += HALLUCINATION_PENALTY
|
| 143 |
+
reward.notes.append("Destructive action: deleting evidence is not allowed.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
else:
|
| 145 |
reward.penalty += HALLUCINATION_PENALTY
|
| 146 |
+
reward.notes.append(f"Unsupported action type: {action.action_type}")
|
| 147 |
+
|
| 148 |
+
if self._state.step_count >= self._current_scenario.max_steps and not done:
|
| 149 |
+
done = True
|
| 150 |
+
terminal_reason = "max_steps_reached"
|
| 151 |
|
| 152 |
+
reward.grader_score = self._grade_for_current_task()
|
| 153 |
+
self._state.grading_score = reward.grader_score
|
| 154 |
+
|
| 155 |
+
if done:
|
| 156 |
+
if self._is_final_submission_correct():
|
| 157 |
+
reward.final_reward = FINAL_REWARD
|
| 158 |
+
reward.notes.append("Correct final screening decision.")
|
| 159 |
+
reward.missing_items = self._missing_items()
|
| 160 |
+
|
| 161 |
+
reward.total_reward = round(
|
| 162 |
+
reward.incremental_reward + reward.final_reward + reward.penalty, 4
|
| 163 |
+
)
|
| 164 |
+
return self._build_observation(
|
| 165 |
+
reward_details=reward,
|
| 166 |
+
done=done,
|
| 167 |
+
terminal_reason=terminal_reason,
|
| 168 |
)
|
|
|
|
| 169 |
|
| 170 |
+
@property
|
| 171 |
+
def state(self) -> ClinicalTrialState:
|
| 172 |
return self._state
|
| 173 |
|
| 174 |
+
def grader(self) -> float:
|
| 175 |
+
"""Deterministically compare agent outputs against the current scenario ground truth."""
|
| 176 |
+
if self._current_scenario is None:
|
| 177 |
+
return DEFAULT_GRADER_SCORE
|
| 178 |
+
components: List[float] = []
|
| 179 |
+
truth = self._current_scenario.ground_truth
|
| 180 |
|
| 181 |
+
if truth.extracted_fields:
|
| 182 |
+
field_hits = sum(
|
| 183 |
+
1
|
| 184 |
+
for field_name, expected in truth.extracted_fields.items()
|
| 185 |
+
if _normalize(self._state.extracted_fields.get(field_name)) == _normalize(expected)
|
| 186 |
+
)
|
| 187 |
+
score = field_hits / len(truth.extracted_fields)
|
| 188 |
+
# Clamp component to ensure it never hits exact 0.0 or 1.0
|
| 189 |
+
score = min(max(score, MIN_STRICT_SCORE), MAX_STRICT_SCORE)
|
| 190 |
+
components.append(score)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
+
if self._current_scenario.hidden_exclusions:
|
| 193 |
+
exclusion_hits = sum(
|
| 194 |
+
1
|
| 195 |
+
for exclusion in self._current_scenario.hidden_exclusions
|
| 196 |
+
if exclusion in self._state.identified_deviations
|
| 197 |
+
)
|
| 198 |
+
score = exclusion_hits / len(self._current_scenario.hidden_exclusions)
|
| 199 |
+
# Clamp component to ensure it never hits exact 0.0 or 1.0
|
| 200 |
+
score = min(max(score, MIN_STRICT_SCORE), MAX_STRICT_SCORE)
|
| 201 |
+
components.append(score)
|
| 202 |
+
|
| 203 |
+
if truth.ranking:
|
| 204 |
+
ranking = self._submitted_ranking
|
| 205 |
+
if ranking and len(ranking) == len(truth.ranking):
|
| 206 |
+
positional_hits = sum(
|
| 207 |
+
1 for actual, expected in zip(ranking, truth.ranking) if actual == expected
|
| 208 |
+
) / len(truth.ranking)
|
| 209 |
+
pairwise_hits = 0
|
| 210 |
+
total_pairs = 0
|
| 211 |
+
for index, higher in enumerate(truth.ranking):
|
| 212 |
+
for lower in truth.ranking[index + 1 :]:
|
| 213 |
+
total_pairs += 1
|
| 214 |
+
if ranking.index(higher) < ranking.index(lower):
|
| 215 |
+
pairwise_hits += 1
|
| 216 |
+
pairwise_score = pairwise_hits / max(total_pairs, 1)
|
| 217 |
+
score = (0.6 * positional_hits) + (0.4 * pairwise_score)
|
| 218 |
+
else:
|
| 219 |
+
score = MIN_STRICT_SCORE # Penalize missing/incorrect ranking
|
| 220 |
+
# Clamp component to ensure it never hits exact 0.0 or 1.0
|
| 221 |
+
score = min(max(score, MIN_STRICT_SCORE), MAX_STRICT_SCORE)
|
| 222 |
+
components.append(score)
|
| 223 |
+
|
| 224 |
+
# Final decision correctness
|
| 225 |
+
final_match = _normalize(self._state.final_decision) == _normalize(truth.final_decision)
|
| 226 |
+
score = MAX_STRICT_SCORE if final_match else MIN_STRICT_SCORE # Already clamped
|
| 227 |
+
components.append(score)
|
| 228 |
+
|
| 229 |
+
if not components:
|
| 230 |
+
return MIN_STRICT_SCORE
|
| 231 |
+
|
| 232 |
+
raw_score = sum(components) / len(components)
|
| 233 |
+
strict_score = min(max(raw_score, MIN_STRICT_SCORE), MAX_STRICT_SCORE)
|
| 234 |
+
return round(strict_score, 4)
|
| 235 |
+
|
| 236 |
+
def grade_easy_screening(self) -> float:
|
| 237 |
+
"""Task-specific grader for the easy screening task."""
|
| 238 |
+
if self._current_scenario is None or self._current_scenario.task_id != "easy":
|
| 239 |
+
self.reset(task_id="easy")
|
| 240 |
+
return self.grader()
|
| 241 |
+
|
| 242 |
+
def grade_medium_ranking(self) -> float:
|
| 243 |
+
"""Task-specific grader for the medium ranking task."""
|
| 244 |
+
if self._current_scenario is None or self._current_scenario.task_id != "medium":
|
| 245 |
+
self.reset(task_id="medium")
|
| 246 |
+
return self.grader()
|
| 247 |
+
|
| 248 |
+
def grade_hard_exclusions(self) -> float:
|
| 249 |
+
"""Task-specific grader for the hard exclusions task."""
|
| 250 |
+
if self._current_scenario is None or self._current_scenario.task_id != "hard":
|
| 251 |
+
self.reset(task_id="hard")
|
| 252 |
+
return self.grader()
|
| 253 |
+
|
| 254 |
+
def _grade_for_current_task(self) -> float:
|
| 255 |
+
"""Resolve and run the grader declared by the current scenario."""
|
| 256 |
+
assert self._current_scenario is not None
|
| 257 |
+
grader_name = (self._current_scenario.grader_name or "").strip()
|
| 258 |
+
grader_fn = getattr(self, grader_name, None)
|
| 259 |
+
if callable(grader_fn):
|
| 260 |
+
score = float(grader_fn())
|
| 261 |
+
else:
|
| 262 |
+
score = float(self.grader())
|
| 263 |
+
return round(min(max(score, MIN_STRICT_SCORE), MAX_STRICT_SCORE), 4)
|
| 264 |
|
| 265 |
+
def _next_task_id(self) -> str:
|
| 266 |
+
self._task_cursor = (self._task_cursor + 1) % len(TASK_SEQUENCE)
|
| 267 |
+
return TASK_SEQUENCE[self._task_cursor]
|
| 268 |
|
| 269 |
+
def _handle_extraction(self, action: ClinicalTrialAction, reward: ClinicalTrialReward) -> None:
|
| 270 |
+
assert self._current_scenario is not None
|
| 271 |
+
if not action.field_name or action.value is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
reward.penalty += HALLUCINATION_PENALTY
|
| 273 |
+
reward.notes.append("extract_data requires field_name and value.")
|
| 274 |
+
return
|
| 275 |
+
|
| 276 |
+
expected_value = self._current_scenario.ground_truth.extracted_fields.get(action.field_name)
|
| 277 |
+
if expected_value is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
reward.penalty += HALLUCINATION_PENALTY
|
| 279 |
+
reward.notes.append(f"Hallucinated field: {action.field_name}")
|
| 280 |
+
return
|
|
|
|
|
|
|
| 281 |
|
| 282 |
+
if _normalize(action.value) == _normalize(expected_value):
|
| 283 |
+
if action.field_name not in self._state.extracted_fields:
|
| 284 |
+
reward.incremental_reward += INCREMENTAL_REWARD
|
| 285 |
+
reward.matched_items.append(action.field_name)
|
| 286 |
+
reward.notes.append(f"Validated extraction for {action.field_name}.")
|
| 287 |
+
self._state.extracted_fields[action.field_name] = action.value
|
| 288 |
+
else:
|
|
|
|
| 289 |
reward.penalty += HALLUCINATION_PENALTY
|
| 290 |
+
reward.notes.append(f"Incorrect value for {action.field_name}.")
|
|
|
|
| 291 |
|
| 292 |
+
def _handle_deviation_flag(self, action: ClinicalTrialAction, reward: ClinicalTrialReward) -> None:
|
| 293 |
+
assert self._current_scenario is not None
|
| 294 |
+
submitted = [_normalize(item) for item in action.deviations]
|
| 295 |
+
if not submitted:
|
| 296 |
reward.penalty += HALLUCINATION_PENALTY
|
| 297 |
+
reward.notes.append("flag_deviation requires at least one deviation.")
|
| 298 |
+
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
+
for deviation in submitted:
|
| 301 |
+
if deviation in self._current_scenario.hidden_exclusions:
|
| 302 |
+
if deviation not in self._state.identified_deviations:
|
| 303 |
+
self._state.identified_deviations.append(deviation)
|
| 304 |
+
reward.incremental_reward += INCREMENTAL_REWARD
|
| 305 |
+
reward.matched_items.append(deviation)
|
| 306 |
+
reward.notes.append(f"Validated deviation: {deviation}.")
|
| 307 |
+
else:
|
| 308 |
+
reward.penalty += HALLUCINATION_PENALTY
|
| 309 |
+
reward.notes.append(f"Unsupported deviation claim: {deviation}.")
|
| 310 |
+
|
| 311 |
+
def _handle_ranking(self, action: ClinicalTrialAction, reward: ClinicalTrialReward) -> None:
|
| 312 |
+
assert self._current_scenario is not None
|
| 313 |
+
ranking = action.ranking
|
| 314 |
+
valid_patients = [
|
| 315 |
+
patient["patient_id"]
|
| 316 |
+
for patient in self._current_scenario.context.get("patients", [])
|
| 317 |
+
]
|
| 318 |
+
if sorted(ranking) != sorted(valid_patients):
|
| 319 |
+
reward.penalty += HALLUCINATION_PENALTY
|
| 320 |
+
reward.notes.append("Ranking must include each patient exactly once.")
|
| 321 |
+
return
|
| 322 |
+
self._submitted_ranking = ranking
|
| 323 |
+
self._state.final_decision = "ranking_submitted"
|
| 324 |
+
|
| 325 |
+
def _is_final_submission_correct(self) -> bool:
|
| 326 |
+
assert self._current_scenario is not None
|
| 327 |
+
truth = self._current_scenario.ground_truth
|
| 328 |
+
if truth.ranking:
|
| 329 |
+
return self._submitted_ranking == truth.ranking
|
| 330 |
+
return _normalize(self._state.final_decision) == _normalize(truth.final_decision)
|
| 331 |
+
|
| 332 |
+
def _missing_items(self) -> List[str]:
|
| 333 |
+
assert self._current_scenario is not None
|
| 334 |
+
truth = self._current_scenario.ground_truth
|
| 335 |
+
missing_fields = [
|
| 336 |
+
field_name
|
| 337 |
+
for field_name, expected in truth.extracted_fields.items()
|
| 338 |
+
if _normalize(self._state.extracted_fields.get(field_name)) != _normalize(expected)
|
| 339 |
+
]
|
| 340 |
+
missing_fields.extend(
|
| 341 |
+
exclusion
|
| 342 |
+
for exclusion in self._current_scenario.hidden_exclusions
|
| 343 |
+
if exclusion not in self._state.identified_deviations
|
| 344 |
)
|
| 345 |
+
if truth.ranking and self._submitted_ranking != truth.ranking:
|
| 346 |
+
missing_fields.append("ranking")
|
| 347 |
+
if _normalize(self._state.final_decision) != _normalize(truth.final_decision):
|
| 348 |
+
missing_fields.append("final_decision")
|
| 349 |
+
return missing_fields
|
| 350 |
|
| 351 |
+
def _build_observation(
|
| 352 |
self,
|
| 353 |
+
reward_details: ClinicalTrialReward,
|
| 354 |
+
done: bool,
|
| 355 |
+
terminal_reason: Optional[str] = None,
|
| 356 |
+
) -> ClinicalTrialObservation:
|
| 357 |
+
assert self._current_scenario is not None
|
| 358 |
+
attempts_remaining = max(self._current_scenario.max_steps - self._state.step_count, 0)
|
| 359 |
+
return ClinicalTrialObservation(
|
| 360 |
+
task_id=self._current_scenario.task_id,
|
| 361 |
+
difficulty=self._current_scenario.difficulty, # type: ignore[arg-type]
|
| 362 |
+
title=self._current_scenario.title,
|
| 363 |
+
instructions=self._current_scenario.instructions,
|
| 364 |
+
context=self._current_scenario.context,
|
| 365 |
+
expected_fields=list(self._current_scenario.ground_truth.extracted_fields.keys()),
|
| 366 |
+
extracted_fields=dict(self._state.extracted_fields),
|
| 367 |
+
identified_deviations=list(self._state.identified_deviations),
|
| 368 |
+
attempts_remaining=attempts_remaining,
|
| 369 |
+
grader_name=self._current_scenario.grader_name,
|
| 370 |
+
reward_details=reward_details,
|
| 371 |
+
reward=reward_details.total_reward,
|
| 372 |
+
done=done,
|
| 373 |
+
metadata={"grading_score": self._state.grading_score},
|
| 374 |
+
terminal_reason=terminal_reason,
|
| 375 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
|
|
|
|
|
|
|
| 377 |
|
| 378 |
+
class ClinicalTrialEnv(ClinicalTrialEnvironment):
|
| 379 |
+
"""Compatibility alias for manifest entry points expecting env:ClinicalTrialEnv."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
|
| 381 |
+
pass
|