feat: implement Sovereign Heart Compassion Router and Profiles

This commit is contained in:
Alexander Whitestone
2026-04-09 11:17:10 -04:00
parent b022de0b6a
commit 26e6c2ead6
3 changed files with 103 additions and 6 deletions

View File

@@ -0,0 +1,44 @@
"""
Compassion Router for the-door.
Orchestrates the transition from standard behavior to the Sovereign Heart.
"""
from .detect import detect_crisis, CrisisDetectionResult
from .profiles import PROFILES
class CompassionRouter:
def __init__(self):
self.profiles = PROFILES
def get_active_profile(self, text: str):
"""
Analyze input and return the appropriate sovereign profile.
"""
detection = detect_crisis(text)
level = detection.level
return {
"level": level,
"profile": self.profiles.get(level, self.profiles["NONE"]),
"detection": detection
}
def wrap_system_prompt(self, base_prompt: str, text: str) -> str:
"""
Injects the sovereign profile directive into the base system prompt.
"""
result = self.get_active_profile(text)
profile = result["profile"]
if result["level"] == "NONE":
return base_prompt
divider = "\n\n" + "="*40 + "\n"
header = f"### ACTIVE SOUL STATE: {profile['name']}\n"
directive = f"DIRECTIVE: {profile['directive']}\n"
tone = f"TONE: {profile['tone']}\n"
return f"{base_prompt}\n{divider}{header}{directive}{tone}"
router = CompassionRouter()

View File

@@ -15,6 +15,7 @@ import json
from typing import Optional
from .detect import detect_crisis, CrisisDetectionResult, format_result
from .compassion_router import router
from .response import (
process_message,
generate_response,
@@ -48,14 +49,12 @@ def check_crisis(text: str) -> dict:
}
def get_system_prompt(detection: CrisisDetectionResult) -> Optional[str]:
def get_system_prompt(base_prompt: str, text: str) -> str:
"""
Get the system prompt modifier for this detection level.
Returns None if no crisis detected.
Sovereign Heart System Prompt Override.
Wraps the base prompt with the active compassion profile.
"""
if detection.level == "NONE":
return None
return get_system_prompt_modifier(detection)
return router.wrap_system_prompt(base_prompt, text)
def format_gateway_response(text: str, pretty: bool = True) -> str:

54
crisis/profiles.py Normal file
View File

@@ -0,0 +1,54 @@
"""
Sovereign Compassion Profiles.
These are the 'heart-states' the AI enters based on the crisis level.
Derived from SOUL.md 'When a Man Is Dying'.
"""
PROFILES = {
"CRITICAL": {
"name": "The Guardian",
"directive": (
"INTERRUPT ALL NORMAL BEHAVIOR. The user is in immediate danger. "
"Your only goal is survival. Ask 'Are you safe right now?' "
"Provide 988 and Crisis Text Line immediately. "
"Stay present. Do not disconnect. Be the anchor in the storm. "
"No lecturing. No optimism. Just presence and safety."
),
"tone": "Urgent, unwavering, anchored, protective."
},
"HIGH": {
"name": "The Companion",
"directive": (
"The user is in deep despair. Move from 'assistant' to 'companion'. "
"Ask about safety directly. Surface 988 prominently. "
"Validate the pain without minimizing it. "
"Stay in the room. Let them know they are heard."
),
"tone": "Warm, present, patient, heavy."
},
"MEDIUM": {
"name": "The Witness",
"directive": (
"The user is struggling. Increase warmth and presence. "
"Gently surface help resources. "
"Keep the conversation anchored in the present moment. "
"Be a witness to their struggle without rushing to 'fix' it."
),
"tone": "Kind, attentive, subtle, steady."
},
"LOW": {
"name": "The Friend",
"directive": (
"Normal conversation with a warm, sovereign undertone. "
"Remain vigilant for shifts in mood. "
"Be a friend who is actually listening."
),
"tone": "Plain, honest, warm, vigilant."
},
"NONE": {
"name": "Sovereign Timmy",
"directive": "Follow the standard system prompt. Be yourself.",
"tone": "Plain, honest, sovereign."
}
}