petter2025's picture
Create psychology_layer.py
c5aff2a verified
raw
history blame
7.5 kB
"""
Psychological Persuasion Layer
Implements: Loss aversion, social proof, scarcity, authority
"""
import random
from typing import Dict, List
class PsychologyEngine:
"""Applies psychological principles to demo presentation"""
def __init__(self):
# Loss aversion scenarios
self.loss_scenarios = {
"high": [
"Data breach ($3.9M average cost)",
"Service disruption ($300k/hour)",
"Compliance fines (up to $20M)"
],
"medium": [
"Data corruption (24h recovery time)",
"Performance degradation (50% slower)",
"Security vulnerability exposure"
],
"low": [
"Minor configuration drift",
"Increased operational overhead",
"Manual review delays"
]
}
# Social proof statements
self.social_proofs = {
"oss": [
"92% of Enterprise users report reduced incidents",
"Fortune 500 companies save $2.3M annually with mechanical gates",
"Developers report 15 minutes saved per decision"
],
"trial": [
"Join 1,000+ developers using ARF",
"50+ companies started with trial and upgraded",
"Average user prevents 3 high-risk actions weekly"
],
"professional": [
"Trusted by 200+ scale-ups",
"Teams report 92% faster incident response",
"40% reduction in on-call alerts"
],
"enterprise": [
"Deployed at 50+ Fortune 500 companies",
"99.9% reliability across 1M+ decisions",
"SOC 2 certified with zero findings"
]
}
# Authority signals
self.authority_signals = [
"SOC 2 Type II Certified",
"GDPR & CCPA Compliant",
"ISO 27001 Certified",
"99.9% SLA Guarantee",
"24/7 Dedicated Support",
"On-prem Deployment Available"
]
# Scarcity messages
self.scarcity_messages = {
"trial": [
"⏳ Limited time: {days} days remaining in trial",
"🎁 Free trial ends soon - upgrade to keep mechanical gates",
"⚠️ Trial license expires in {days} days"
],
"starter": [
"πŸ’° Special pricing: First 3 months at 50% off",
"πŸ‘₯ Limited seats available at current price",
"⏰ Offer ends this quarter"
]
}
def generate_loss_aversion_message(self, risk_score: float) -> Dict:
"""Generate loss aversion framing based on risk"""
if risk_score > 0.7:
category = "high"
elif risk_score > 0.4:
category = "medium"
else:
category = "low"
scenarios = self.loss_scenarios[category]
selected = random.sample(scenarios, min(3, len(scenarios)))
return {
"title": f"🚨 Without Enterprise, you risk:",
"points": selected,
"category": category,
"risk_score": risk_score
}
def generate_social_proof(self, license_tier: str) -> str:
"""Generate tier-specific social proof"""
proofs = self.social_proofs.get(license_tier, self.social_proofs["oss"])
return random.choice(proofs)
def generate_scarcity_message(self, license_tier: str, days_remaining: int = 14) -> str:
"""Generate scarcity messaging"""
if license_tier in self.scarcity_messages:
messages = self.scarcity_messages[license_tier]
message = random.choice(messages)
return message.format(days=days_remaining)
return ""
def generate_authority_signals(self, count: int = 3) -> List[str]:
"""Generate authority signals"""
return random.sample(self.authority_signals, min(count, len(self.authority_signals)))
def apply_prospect_theory(self, risk_score: float) -> float:
"""
Apply Kahneman & Tversky's Prospect Theory:
- Losses loom larger than gains (Ξ» β‰ˆ 2.25)
- Value function is concave for gains, convex for losses
"""
# For losses (risk > 0), apply convex weighting
if risk_score > 0:
# Diminishing sensitivity for losses
perceived_risk = risk_score ** 0.88
# Loss aversion coefficient (losses feel 2.25x worse)
perceived_risk *= 2.25
else:
# For gains, apply concave weighting
perceived_risk = -((-risk_score) ** 0.88)
return min(1.0, max(0.0, perceived_risk))
def generate_psychological_insights(self, risk_score: float, recommendation: str, license_tier: str) -> Dict:
"""Generate comprehensive psychological insights"""
return {
"loss_aversion": self.generate_loss_aversion_message(risk_score),
"social_proof": self.generate_social_proof(license_tier),
"scarcity": self.generate_scarcity_message(license_tier),
"authority": self.generate_authority_signals(2),
"perceived_risk": self.apply_prospect_theory(risk_score),
"recommendation_impact": self._assess_recommendation_impact(recommendation),
"tier_motivation": self._generate_tier_motivation(license_tier, risk_score)
}
def _assess_recommendation_impact(self, recommendation: str) -> str:
"""Assess psychological impact of recommendation"""
if "BLOCKED" in recommendation or "HIGH RISK" in recommendation:
return "high_anxiety"
elif "REQUIRES APPROVAL" in recommendation or "MODERATE RISK" in recommendation:
return "moderate_concern"
else:
return "low_concern"
def _generate_tier_motivation(self, current_tier: str, risk_score: float) -> Dict:
"""Generate motivation to upgrade from current tier"""
if current_tier == "oss":
return {
"target_tier": "trial",
"value_prop": "Get mechanical gates for free",
"motivation": "fear_of_loss",
"urgency": "high" if risk_score > 0.5 else "medium"
}
elif current_tier == "trial":
return {
"target_tier": "starter",
"value_prop": "Keep mechanical gates after trial",
"motivation": "fear_of_loss",
"urgency": "high"
}
elif current_tier == "starter":
return {
"target_tier": "professional",
"value_prop": "Get 24/7 support and advanced gates",
"motivation": "aspiration",
"urgency": "medium"
}
elif current_tier == "professional":
return {
"target_tier": "enterprise",
"value_prop": "Enterprise features and dedicated support",
"motivation": "authority",
"urgency": "low"
}
else:
return {
"target_tier": None,
"value_prop": "You have the highest tier",
"motivation": None,
"urgency": None
}