Spaces:
Running
Running
| """Safety critic agent.""" | |
| from __future__ import annotations | |
| from app.common.enums import ActionType, DecisionMode, DoseBucket | |
| from app.common.types import PolyGuardAction, PolyGuardState | |
| from app.env.verifier import verify_action_legality | |
| class CriticAgent: | |
| name = "CriticAgent" | |
| def run(self, state: PolyGuardState, proposed: PolyGuardAction) -> dict: | |
| report = verify_action_legality(state, proposed) | |
| if report.legal: | |
| report_payload = report.model_dump(mode="json") | |
| return { | |
| "approved": True, | |
| "report": report_payload, | |
| "final_action": proposed, | |
| "legal": True, | |
| "violations": report_payload.get("violations", []), | |
| } | |
| fallback = PolyGuardAction( | |
| mode=DecisionMode.REVIEW, | |
| action_type=ActionType.REQUEST_SPECIALIST_REVIEW, | |
| target_drug=None, | |
| replacement_drug=None, | |
| dose_bucket=DoseBucket.NA, | |
| taper_days=None, | |
| monitoring_plan="critic_veto", | |
| candidate_id="cand_veto_fallback", | |
| confidence=0.62, | |
| rationale_brief=f"Critic veto: {', '.join(report.violations)}", | |
| ) | |
| report_payload = report.model_dump(mode="json") | |
| return { | |
| "approved": False, | |
| "report": report_payload, | |
| "final_action": fallback, | |
| "legal": False, | |
| "violations": report_payload.get("violations", []), | |
| } | |