Ragna AI Companion & Learning Context
Relevant source files
The following files were used as context for generating this wiki page:
- artifacts/mobile/context/RagnaLearningContext.tsx
- artifacts/api-server/src/routes/anthropic/index.ts
- artifacts/api-server/src/intelligence/hospice/planner.ts
- replit.md
- attached_assets/Pasted-Refactor-the-Ragna-help-screen-into-smaller-reusable-co_1774839859780.txt
- attached_assets/Pasted-Build-the-next-major-intelligence-architecture-for-Hosp_1774852812580.txt
- attached_assets/Pasted-Make-a-focused-privacy-control-pass-on-the-mobile-app-s_1774838822268.txt
Ragna is a specialized hospice care AI companion designed to provide actionable guidance to caregivers, patients, and healthcare professionals navigating end-of-life care. Unlike general-purpose chatbots, Ragna operates as a role-aware expert system that utilizes a "Living Context" to maintain a continuous, human-centric understanding of a family's unique journey.
The system architecture bridges a high-fidelity mobile interface with a multi-layered hospice intelligence engine on the server. It captures real-time app activities—such as symptom tracking, journal entries, and goals of care—to synthesize a personalized "Patient Context" that grounds every AI interaction in the current reality of the user's situation.
Sources: replit.md, attached_assets/Pasted-Build-the-next-major-intelligence-architecture-for-Hosp_1774852812580.txt
Intelligence Architecture
Ragna's intelligence is not driven by a single static prompt but by a layered engine that processes user input against specialized clinical models. When a message is sent, the server executes a "Planner" to determine the appropriate response strategy.
The Response Planner
The planner.ts module analyzes the combined text of the user's message and the patient's context to detect critical factors such as urgency, journey stage, and care gaps. It determines which of the 13 knowledge domains (e.g., dying process, symptom management, or grief) are relevant to the query.
Sources: artifacts/api-server/src/intelligence/hospice/planner.ts:10-40, replit.md
The diagram above illustrates how the server-side planner assembles a response strategy before calling the LLM.
Response Plan Components
| Component | Description |
|---|---|
| Urgency Level | Ranges from routine to critical/911-emergency. |
| Knowledge Blocks | Deterministically retrieved clinical content (e.g., "final moments", "pain management"). |
| Communication Mode | Tailors tone (e.g., "Warm, steady, and practical") based on the detected role. |
| Required Sections | Hard-coded instructions for the AI to include specific advice (e.g., "What to watch for"). |
Sources: artifacts/api-server/src/intelligence/hospice/planner.ts:43-110, attached_assets/Pasted-Build-the-next-major-intelligence-architecture-for-Hosp_1774852812580.txt
Living Context & Learning System
The "Living Context" is a core feature of the mobile application that tracks meaningful user events to evolve Ragna's understanding of the patient and family.
RagnaLearningContext
The system observes specific actions in the app and stores them as a rolling list of observations. These observations are persisted locally via AsyncStorage at the @ragna_learning_v1 key.
Significant Observed Events:
- Symptom Check-ins: Tracking changes in physical comfort.
- Journal Entries: Capturing emotional state and caregiving challenges.
- Goals of Care (GoC) Saves: Identifying what matters most to the family.
- Profile Updates: Basic patient demographics and diagnosis.
Sources: replit.md, artifacts/mobile/context/RagnaLearningContext.tsx
Living Profile Synthesis
After at least three significant events and a 2-hour "cooldown," the LearningSync component triggers a synthesis process. The API server takes the raw observations and generates a 3-5 sentence "Living Knowledge" paragraph. This paragraph is written in the third person, describing patterns, unresolved concerns, and emotional trajectories.
Sources: replit.md, artifacts/api-server/src/routes/anthropic/index.ts:250-280
Data Flow: Message Processing
Every interaction between the mobile app and the Ragna AI involves a complex assembly of local data and server-side intelligence.
The sequence diagram shows the injection of intelligence-based context into the LLM request.
Patient Context Assembly
The buildPatientContext helper in the mobile app assembles the payload based on user-defined privacy settings. It includes:
- Base Context: User role and journey stage.
- Profile Details: Name, diagnosis, and notes.
- Medication/Equipment: Details of the home setup.
- Goals of Care: DNR status and care priorities.
- Recent Summaries: 7-day symptom trends and recent journal topics.
Sources: attached_assets/Pasted-Make-a-focused-privacy-control-pass-on-the-mobile-app-s_1774838822268.txt, artifacts/api-server/src/routes/anthropic/index.ts:150-180
Privacy & Security Controls
Conversations are scoped to a single mobile client using a persistent clientId (stored as ragna_client_id). This ID is sent via the x_client_id header to ensure a user can only access their own conversation history and memory.
Ragna Privacy Settings
Users have granular control over what information is sent to the server to personalize Ragna's responses:
| Setting | Default | Impact |
|---|---|---|
| Personalization Enabled | true | Master switch for all saved context. |
| Include Care Contacts | false | Includes hospice/pharmacy phone numbers. |
| Include Recent Symptoms | true | Sends the last 7 days of symptom data. |
| Include Conversation Memory | true | Allows Ragna to remember previous sessions. |
Sources: attached_assets/Pasted-Make-a-focused-privacy-control-pass-on-the-mobile-app-s_1774838822268.txt, artifacts/api-server/src/routes/anthropic/index.ts:15-30
Summary
The Ragna AI Companion is an expert system anchored by the RagnaLearningContext on the mobile device and a multi-stage planner on the server. By synthesizing real-time app activity into a "Living Context," the system ensures that AI-generated guidance is clinically grounded, role-specific, and aware of the family's emotional and practical journey. This architecture prioritizes safety through critical red-flag detection while maintaining a human-centric approach to end-of-life support.