Agents
polars_ts.healthcare_agents.agents
Specialized clinical agents for EHR vital-sign monitoring.
The agents operate on a single vital-sign observation (one row of
ClinicalEnv) in :data:~polars_ts.healthcare_agents.env.VITAL_CHANNELS
order: (heart_rate, systolic_bp, respiratory_rate, temperature, spo2).
Scoring heuristics are grounded in widely used bedside instruments — qSOFA and SIRS for sepsis risk and a NEWS-style aggregate for escalation — kept dependency-free and deterministic so they are testable and auditable.
SepsisWarningAgent
Early sepsis-risk scoring from vital signs (qSOFA + SIRS heuristics).
qSOFA awards a point each for respiratory rate >= 22, systolic BP <= 100,
and (unavailable here) altered mentation. SIRS awards points for
temperature, heart rate and respiratory-rate derangement. The agent flags
sepsis risk when the combined score meets threshold.
Parameters
threshold Combined qSOFA+SIRS score at or above which sepsis risk is flagged.
score(vitals)
Return (risk_score, is_at_risk) for one vital-sign row.
VitalMonitorAgent
Per-channel physiological range monitor.
Flags any vital sign outside its normal reference band and reports how many channels are deranged.
Parameters
bounds
Optional mapping channel_index -> (low, high) overriding the
default adult reference ranges.
score(vitals)
Return (n_deranged, any_deranged) for one vital-sign row.
EscalationAgent
Map a clinical picture to a discrete escalation tier (NEWS-style).
Aggregates a NEWS-like severity score from the vital-sign row and combines
it with upstream sepsis and monitoring signals to pick an escalation tier
in [0, n_tiers):
0routine monitoring1increased observation frequency2urgent clinical review3rapid-response / ICU transfer
news_score(vitals)
Compute a simplified National Early Warning Score (0-3 per channel).
decide(vitals, sepsis_risk, n_deranged)
Choose an escalation tier from NEWS score and upstream signals.
TreatmentAgent
Contextual-bandit treatment recommender over escalation tiers.
Learns a per-tier preference for a small action set via a simple reward-averaging (bandit) update, letting the recommended intervention adapt to observed outcomes without any heavyweight RL dependency.
Parameters
actions
Ordered intervention labels; the index is the action id.
seed
Seed for the exploration RNG (numpy.random.default_rng).
recommend(tier, explore=0.0)
Return an action id for tier; explore is the epsilon-greedy rate.
update(tier, action, reward)
Incremental sample-average update of the tier/action value estimate.
federated_average(values, weights=None)
Privacy-preserving FedAvg of per-site agent parameters.
Combines locally trained parameter arrays (e.g. TreatmentAgent value
tables) from multiple sites into a single global array by weighted mean,
without any site sharing its raw patient data.
Parameters
values Per-site parameter arrays, all of identical shape. weights Optional per-site weights (e.g. local sample counts). Defaults to equal weighting.
Returns
numpy.ndarray The aggregated global parameter array.