Hospice Intelligence Engine Architecture
Relevant source files
The following files were used as context for generating this wiki page:
- artifacts/api-server/src/intelligence/hospice/catalog.ts
- artifacts/api-server/src/routes/anthropic/index.ts
- artifacts/api-server/src/routes/anthropic/systemPrompt.ts
- attached_assets/Pasted-Build-the-next-major-intelligence-architecture-for-Hosp_1774852812580.txt
- replit.md
- artifacts/api-server/src/intelligence/hospice/documentationCoach.ts
The Hospice Intelligence Engine is a layered, role-aware architecture designed to transform the Hospice Roadmap application from a simple chatbot into a comprehensive hospice intelligence platform. It provides actionable, grounded guidance for patients, caregivers, and clinicians across the entire end-of-life journey, including symptom management, communication coaching, and care gap recognition.
The engine operates by intercepting user messages and patient context on the server side to perform deterministic retrieval and response planning. This grounded context is then injected into the LLM prompt (Claude) to ensure responses are technically accurate, compassionately toned, and aligned with clinical governance standards.
Sources: replit.md:92-106, attached_assets/Pasted-Build-the-next-major-intelligence-architecture-for-Hosp_1774852812580.txt:3-15
Core Architectural Components
The engine is structured as a series of specialized modules that process data before it reaches the generative AI layer.
1. Response Planning and Retrieval
The planner.ts and retrieval.ts modules serve as the entry point for intelligence processing. They analyze the incoming user message and patient context (including symptoms, goals of care, and journey stage) to derive a ResponsePlan. This plan dictates the required sections, urgency level, and specific knowledge blocks that must be included in the final output.
Sources: replit.md:102-106, artifacts/api-server/src/routes/anthropic/index.ts:133-140
2. Knowledge Catalog
The system utilizes a structured HOSPICE_KNOWLEDGE_CATALOG containing over 35 knowledge blocks across 13 domains. Unlike free-form generation, these blocks provide the "source of truth" for clinical and operational guidance.
| Field | Description |
|---|---|
id | Unique identifier (e.g., SM001 for Symptom Management) |
domain | The functional area (e.g., dying_process, care_gap) |
urgency | Clinical priority level (critical, urgent, moderate, routine) |
whatToDoNow | Immediate actionable steps for the user |
hardStops | Critical safety warnings (e.g., "Call 911 if...") |
Sources: artifacts/api-server/src/intelligence/hospice/catalog.ts:5-15, attached_assets/Pasted-Build-the-next-major-intelligence-architecture-for-Hosp_1774852812580.txt:87-104
Data Flow and Integration
The intelligence engine integrates directly into the Anthropic API route. When a message is posted, the server synthesizes a comprehensive system prompt that combines the persona of "Ragna" with real-time patient data and retrieved clinical knowledge.
Request Processing Flow
The flow illustrates how deterministic clinical knowledge is prioritized over general AI knowledge to ensure safety and accuracy.
Sources: artifacts/api-server/src/routes/anthropic/index.ts:121-160, replit.md:92-106
Domain Models and Coaching
The architecture includes dedicated models for specific hospice scenarios, ensuring the AI remains broad yet specific.
Symptom and Disease Models
The engine defines structured behavior for symptoms such as pain, breathlessness (dyspnea), agitation, and terminal secretions. For example, the SM002 block for breathlessness provides non-pharmacological interventions like using a fan to activate trigeminal receptors.
Sources: artifacts/api-server/src/intelligence/hospice/catalog.ts:129-152, artifacts/api-server/src/routes/anthropic/systemPrompt.ts:312-329
Documentation Coaching
The documentationCoach.ts module provides specific guides for users to track symptoms, hospice calls, and care failures. This facilitates advocacy by giving caregivers structured templates to present to clinical staff.
// Example from documentationCoach.ts:25-30
{
situation: "Documenting hospice calls and responses",
whatToDocument: [
"Date and time of call",
"Name of person who answered",
"What you reported",
"What they said"
],
exampleEntry: "March 15 | 11:45pm | On-call nurse Linda | Reported severe pain..."
}
Sources: artifacts/api-server/src/intelligence/hospice/documentationCoach.ts:20-37
The Ragna Persona and Prompting Strategy
The AI is personified as "Ragna," a 58-year-old Norwegian hospice nurse. The system prompt is heavily structured to enforce emotional acknowledgment before providing clinical guidance.
Response Requirements
- Emotion First: Acknowledge distress or fear immediately.
- Warmth Before Information: Offer comfort before technical solutions.
- Structured Guidance: Follow the
ResponsePlanprovided by the intelligence package. - SBAR Format: When preparing a user to call hospice, the engine generates scripts in the Situation-Background-Assessment-Recommendation (SBAR) format.
Sources: artifacts/api-server/src/routes/anthropic/systemPrompt.ts:7-25, artifacts/api-server/src/routes/anthropic/systemPrompt.ts:607-635
Personalization via Learning Observations
The system maintains a "living profile" synthesized from recent conversation memory and symptom trends. This allows Ragna to reference previous concerns, such as "I remember we talked about the pain medication yesterday," creating a continuous support experience.
Sources: artifacts/api-server/src/routes/anthropic/index.ts:221-255, replit.md:60-65
Conclusion
The Hospice Intelligence Engine Architecture represents a shift toward "grounded AI" in healthcare. By combining a deterministic clinical catalog with a sophisticated response planner and a compassionate nurse persona, the system provides high-fidelity, safe, and emotionally intelligent guidance for the complex journey of hospice care.
Sources: attached_assets/Pasted-Build-the-next-major-intelligence-architecture-for-Hosp_1774852812580.txt:55-75, replit.md:92-106