AgentSkillsCN

Esi Composition

Esi 构成

SKILL.md

ESI Composition Skill

Overview

Performs Phase 2 of the hybrid ESI classification pipeline: deterministic ESI-v4 assignment from structured facts using pure Python logic and configurable rules.

Unlike LLM-based classifiers, this skill never uses an LLM. It applies the official ESI-v4 decision tree through rule-based code, providing:

  • Audit trail: Exact rules that triggered classification
  • Reproducibility: Same input always produces same output
  • Performance: Fast (<5ms) with no API calls
  • Compliance: Aligns with validated ESI protocol

When to Use

  • Final ESI assignment after fact extraction
  • Part of hybrid pipelines (esi-extraction → esi-composition)
  • When reproducibility and audit trails are required
  • When cost/latency must be minimized

Input/Output

Input:

  • extracted_facts (object): From esi-extraction skill
  • OR manually provided: vital_signs, high_risk_keywords

Output:

  • esi_level (1-5): Final ESI classification
  • decision_path (string): Path through decision tree
  • triggers (array): Rules that fired
  • reasoning (string): Human-readable explanation

ESI-v4 Decision Algorithm

ESI-1: Immediate Life-Threatening

Exact Triggers:

  • Heart rate = 0 OR oxygen saturation < 60% (cardiac arrest/severe hypoxia)
  • Respiratory rate > 40 or < 8 (severe respiratory distress)
  • Systolic BP < 70 (severe shock)
  • High-risk keywords: "unresponsive", "unconscious", "cardiac arrest", "not breathing"

Code Path: rules/esi_rules.jsonesi_1_immediate_life_threat

ESI-2: Emergent (High-Risk)

Exact Triggers:

  • Systolic BP < 90 (hypotension/shock signs)
  • Heart rate > 120 (severe tachycardia)
  • Respiratory rate > 30 or < 8 (severe tachypnea/depression)
  • Oxygen saturation < 90% (hypoxia)
  • Pain level ≥ 7 (severe pain)
  • Fever > 38.5°C + altered mental status (sepsis pattern)
  • Trauma with systolic BP < 110
  • High-risk keywords: "chest pain", "SOB", "difficulty breathing", "stabbed", "gunshot"

Code Path: rules/esi_rules.jsonesi_2_high_risk

ESI-3: Urgent, Likely ≥2 Resources

Rules:

  • Requires exactly 2 or more resources
  • Valid resources: lab, imaging, specialist, observation, procedure, monitoring, medication, therapy
  • Acute injury (likely needs X-ray, CT)
  • Stable with concerning symptoms

Code Path: rules/esi_rules.json → Resource counting logic

ESI-4: Less Urgent, Likely 1 Resource

Rules:

  • Needs exactly 1 resource
  • Minor injury, minor illness
  • Stable, low-risk presentation

ESI-5: Non-Urgent

Rules:

  • No resources needed
  • Self-limiting condition
  • Advice/education only

Best Practices

Input Quality

  • Always provide complete vital_signs for accurate classification
  • Include high_risk_keywords list for pattern matching
  • Pass facts from esi-extraction skill for consistency

Audit Trail

  • Always review decision_path for clinical oversight
  • Share triggers list with clinicians for verification
  • Document reasoning for medical records

Resource Allowlisting

  • Skill validates resources against rules/resources.json
  • Allowed types: lab, imaging, specialist, observation, procedure, monitoring, medication, therapy
  • Unknown resource types are rejected (fail-safe)
  • Each resource type has examples and high-effort classification
  • Update rules/resources.json allowed_resources list when adding new types

Examples

Example 1: ESI-2 (Hypotension + Tachycardia)

json
Input:
{
  "vital_signs": {
    "systolic_bp": 85,       // < 90 → hypotension trigger
    "heart_rate": 125,       // > 120 → tachycardia trigger
    "respiratory_rate": 32,  // > 30 → tachypnea trigger
    "oxygen_saturation": 95
  },
  "symptoms": {},
  "risk_factors": {"high_risk_keywords": []}
}

Output:
{
  "esi_level": 2,
  "decision_path": "Rule: High-risk situation or severe symptom → ESI-2",
  "triggers": ["hypotension_systolic_lt90", "tachycardia_hr_gt120", "abnormal_respiratory_rate"],
  "reasoning": "ESI-2 assigned via Rule: High-risk situation or severe symptom → ESI-2"
}

Example 2: ESI-4 (1 Resource, Stable)

json
Input:
{
  "vital_signs": {
    "systolic_bp": 130,      // Normal
    "heart_rate": 82,        // Normal
    "respiratory_rate": 16   // Normal
  },
  "symptoms": {"pain_level": 3},
  "risk_factors": {"high_risk_keywords": []},
  "resources": {
    "lab": true,             // 1 resource
    "imaging": false,
    "specialist": false,
    "monitoring": false
  }
}

Output:
{
  "esi_level": 4,
  "decision_path": "No ESI-1 or ESI-2 triggers → Resource count = 1 → ESI-4",
  "triggers": [],
  "reasoning": "Stable vital signs, mild pain, needs 1 resource. ESI-4 classification."
}

Troubleshooting

Issue: ESI-5 when expecting ESI-3

  • Cause: Resource count <2 detected
  • Solution: Verify requires_imaging, requires_lab flags are set correctly

Issue: ESI-2 when expecting ESI-3

  • Cause: Vital danger detected (hypotension, extreme tachycardia, etc.)
  • Solution: Review vital_signs for abnormal readings; verify clinical assessment

Issue: "Invalid resource type" error

  • Cause: Unknown resource in resources field
  • Solution: Update rules/resources.json with new resource type, or remove invalid resource

See Also

  • esi-extraction: Upstream fact extraction skill
  • rules/esi_rules.json: ESI-1 and ESI-2 trigger definitions
  • rules/resources.json: Valid resource types and categories
  • compose_esi.py: Implementation logic