petter2025 commited on
Commit
ec78ba8
·
verified ·
1 Parent(s): 2e7d79d

Update demo/orchestrator.py

Browse files
Files changed (1) hide show
  1. demo/orchestrator.py +145 -160
demo/orchestrator.py CHANGED
@@ -1,178 +1,163 @@
1
  """
2
- Demo orchestration and presenter guidance
3
  """
4
 
5
- from typing import Dict, List, Optional
6
- from enum import Enum
7
- from core.data_models import DemoMode, DemoStep
 
 
 
 
 
8
 
9
  class DemoOrchestrator:
10
- """Guide presenter through optimal demo flow"""
11
 
12
- def __init__(self, mode: DemoMode = DemoMode.INVESTOR):
13
- self.mode = mode
14
- self.current_step = 0
15
- self.steps = self._get_steps_for_mode()
 
 
 
 
 
16
 
17
- def _get_steps_for_mode(self) -> List[DemoStep]:
18
- """Get demo steps based on mode"""
19
- if self.mode == DemoMode.QUICK:
20
- return [
21
- DemoStep(
22
- title="Show Crisis",
23
- scenario="Cache Miss Storm",
24
- action="metrics",
25
- message="Highlight the critical metrics - this is happening right now",
26
- icon="📊"
27
- ),
28
- DemoStep(
29
- title="OSS Analysis",
30
- scenario="Cache Miss Storm",
31
- action="oss",
32
- message="Perfect analysis but requires manual work",
33
- icon="🤖"
34
- ),
35
- DemoStep(
36
- title="Enterprise Magic",
37
- scenario="Cache Miss Storm",
38
- action="enterprise",
39
- message="Watch ARF fix it automatically in minutes",
40
- icon="⚡"
41
  )
42
- ]
43
- else: # INVESTOR mode
44
- return [
45
- DemoStep(
46
- title="Problem Statement",
47
- scenario="Cache Miss Storm",
48
- action="metrics",
49
- message="This critical incident costs $8,500/hour right now",
50
- icon="💰"
51
- ),
52
- DemoStep(
53
- title="Current Solution (OSS)",
54
- scenario="Cache Miss Storm",
55
- action="oss",
56
- message="Our free edition gives perfect analysis but manual work",
57
- icon="🆓"
58
- ),
59
- DemoStep(
60
- title="ARF Solution (Enterprise)",
61
- scenario="Cache Miss Storm",
62
- action="enterprise",
63
- message="Autonomous healing with enterprise safety controls",
64
- icon="🚀"
65
- ),
66
- DemoStep(
67
- title="Business Impact",
68
- scenario=None,
69
- action="dashboard",
70
- message="Show how ARF transforms cost centers to profit engines",
71
- icon="📈"
72
- ),
73
- DemoStep(
74
- title="Custom ROI Analysis",
75
- scenario=None,
76
- action="roi_calc",
77
- message="Calculate their specific potential savings",
78
- icon="🧮"
79
- )
80
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
- def get_next_guidance(self) -> Dict:
83
- """Get next guidance step"""
84
- if self.current_step >= len(self.steps):
85
- return self._create_completion_guidance()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
- step = self.steps[self.current_step]
88
- self.current_step += 1
 
 
89
 
90
  return {
91
- "title": step.title,
92
- "scenario": step.scenario,
93
- "action": step.action,
94
- "message": step.message,
95
- "icon": step.icon,
96
- "html": self._create_guidance_html(step)
97
  }
98
 
99
- def _create_guidance_html(self, step: DemoStep) -> str:
100
- """Create HTML guidance for presenter"""
101
- action_desc = self._get_action_description(step.action)
102
-
103
- return f"""
104
- <div style='
105
- padding: 20px;
106
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
107
- color: white;
108
- border-radius: 10px;
109
- margin: 15px 0;
110
- border-left: 5px solid #4ECDC4;
111
- box-shadow: 0 4px 6px rgba(0,0,0,0.1);
112
- '>
113
- <div style='display: flex; align-items: center; margin-bottom: 10px;'>
114
- <span style='font-size: 24px; margin-right: 10px;'>{step.icon}</span>
115
- <h3 style='margin: 0;'>Step {self.current_step}: {step.title}</h3>
116
- </div>
117
- <p style='margin: 0 0 10px 0; font-size: 16px;'><b>What to say:</b> "{step.message}"</p>
118
- <div style='
119
- background: rgba(255,255,255,0.1);
120
- padding: 10px;
121
- border-radius: 5px;
122
- margin-top: 10px;
123
- '>
124
- <span style='font-size: 14px; opacity: 0.9;'>👆 <b>Action:</b> {action_desc}</span>
125
- </div>
126
- </div>
127
- """
128
 
129
- def _create_completion_guidance(self) -> Dict:
130
- """Create completion guidance"""
131
  return {
132
- "title": "Demo Complete",
133
- "scenario": None,
134
- "action": "complete",
135
- "message": "Ready for investor Q&A",
136
- "icon": "🎉",
137
- "html": """
138
- <div style='
139
- padding: 25px;
140
- background: linear-gradient(135deg, #4ECDC4 0%, #44A08D 100%);
141
- color: white;
142
- border-radius: 10px;
143
- text-align: center;
144
- margin: 20px 0;
145
- box-shadow: 0 4px 6px rgba(0,0,0,0.1);
146
- '>
147
- <h2 style='margin: 0 0 15px 0;'>🎉 Demo Complete!</h2>
148
- <p style='margin: 0; font-size: 18px;'>Ready for investor Q&A</p>
149
- <div style='
150
- margin-top: 20px;
151
- padding: 15px;
152
- background: rgba(255,255,255,0.1);
153
- border-radius: 8px;
154
- text-align: left;
155
- '>
156
- <h4 style='margin: 0 0 10px 0;'>Key Metrics Demonstrated:</h4>
157
- <div style='display: grid; grid-template-columns: 1fr 1fr; gap: 10px;'>
158
- <div>• 85% faster incident resolution</div>
159
- <div>• 5.2× average ROI</div>
160
- <div>• 81.7% auto-heal rate</div>
161
- <div>• 2-3 month payback</div>
162
- </div>
163
- </div>
164
- </div>
165
- """
166
  }
167
 
168
- def _get_action_description(self, action: str) -> str:
169
- """Get description for action"""
170
- actions = {
171
- "metrics": "Show crisis metrics (already displayed)",
172
- "oss": "Click 'Run OSS Analysis' button",
173
- "enterprise": "Click 'Execute Enterprise Healing' (toggle approval)",
174
- "dashboard": "Switch to Business Impact tab",
175
- "roi_calc": "Adjust sliders and calculate custom ROI",
176
- "complete": "Proceed to Q&A"
177
- }
178
- return actions.get(action, "Continue with demo")
 
1
  """
2
+ Demo Orchestrator - Integrates with ARF OSS framework
3
  """
4
 
5
+ import asyncio
6
+ import json
7
+ import datetime
8
+ from typing import Dict, List, Any, Optional, Tuple
9
+ import logging
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
 
14
  class DemoOrchestrator:
15
+ """Orchestrates the demo workflow using ARF OSS"""
16
 
17
+ def __init__(self, arf_client=None):
18
+ self.arf_client = arf_client
19
+ self.incident_history = []
20
+ self.execution_history = []
21
+ self.learning_stats = {
22
+ "patterns_detected": 0,
23
+ "similar_incidents_found": 0,
24
+ "healing_intents_created": 0
25
+ }
26
 
27
+ async def analyze_incident(self, scenario_name: str, scenario_data: Dict) -> Dict:
28
+ """Analyze incident using ARF OSS"""
29
+ try:
30
+ if self.arf_client and hasattr(self.arf_client, 'analyze_and_recommend'):
31
+ # Use actual ARF OSS analysis
32
+ healing_intent = await self.arf_client.analyze_and_recommend(
33
+ tool_name="analyze",
34
+ component=scenario_data.get("component", "unknown"),
35
+ parameters=scenario_data.get("metrics", {}),
36
+ context={"scenario": scenario_name}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  )
38
+
39
+ self.learning_stats["healing_intents_created"] += 1
40
+
41
+ return {
42
+ "status": "success",
43
+ "healing_intent": healing_intent.to_enterprise_request(),
44
+ "analysis": {
45
+ "confidence": healing_intent.confidence,
46
+ "similar_incidents": healing_intent.similar_incidents,
47
+ "recommendation": healing_intent.justification
48
+ }
49
+ }
50
+
51
+ # Fallback to mock analysis
52
+ return {
53
+ "status": "success",
54
+ "analysis": {
55
+ "confidence": 0.85,
56
+ "similar_incidents": [
57
+ {"id": "inc_001", "similarity": 0.78, "component": "redis"},
58
+ {"id": "inc_045", "similarity": 0.65, "component": "database"}
59
+ ],
60
+ "recommendation": f"Based on 2 similar incidents, recommend action for {scenario_name}"
61
+ }
62
+ }
63
+
64
+ except Exception as e:
65
+ logger.error(f"Analysis failed: {e}")
66
+ return {
67
+ "status": "error",
68
+ "message": str(e)
69
+ }
70
+
71
+ def execute_healing(self, scenario_name: str, healing_intent: Dict,
72
+ mode: str = "autonomous") -> Dict:
73
+ """Execute healing action"""
74
+ execution_record = {
75
+ "id": f"exec_{len(self.execution_history):03d}",
76
+ "scenario": scenario_name,
77
+ "timestamp": datetime.datetime.now().isoformat(),
78
+ "mode": mode,
79
+ "healing_intent": healing_intent,
80
+ "status": "completed",
81
+ "results": {
82
+ "recovery_time_minutes": 12,
83
+ "cost_saved": 7200,
84
+ "users_impacted": "45,000 → 0"
85
+ }
86
+ }
87
+
88
+ self.execution_history.append(execution_record)
89
+
90
+ # Update learning stats
91
+ self.learning_stats["patterns_detected"] += 1
92
+
93
+ return execution_record
94
 
95
+ def get_similar_incidents(self, query: str, limit: int = 5) -> List[Dict]:
96
+ """Find similar incidents"""
97
+ # This would integrate with ARF's RAG memory
98
+ return [
99
+ {
100
+ "id": "inc_001",
101
+ "similarity": 0.92,
102
+ "scenario": "Cache Miss Storm",
103
+ "resolution": "Scaled Redis cluster + circuit breaker",
104
+ "recovery_time": "12 minutes"
105
+ },
106
+ {
107
+ "id": "inc_045",
108
+ "similarity": 0.78,
109
+ "scenario": "Database Connection Pool",
110
+ "resolution": "Increased pool size + monitoring",
111
+ "recovery_time": "18 minutes"
112
+ }
113
+ ][:limit]
114
+
115
+ def calculate_roi(self, company_data: Dict) -> Dict:
116
+ """Calculate ROI based on company data"""
117
+ monthly_incidents = company_data.get("monthly_incidents", 10)
118
+ avg_cost_per_incident = company_data.get("avg_cost_per_incident", 5000)
119
+ team_size = company_data.get("team_size", 3)
120
 
121
+ annual_impact = monthly_incidents * 12 * avg_cost_per_incident
122
+ team_cost = team_size * 150000 # $150k per engineer
123
+ savings = annual_impact * 0.82 # 82% savings with ARF
124
+ roi_multiplier = savings / team_cost if team_cost > 0 else 0
125
 
126
  return {
127
+ "annual_impact": annual_impact,
128
+ "team_cost": team_cost,
129
+ "potential_savings": savings,
130
+ "roi_multiplier": roi_multiplier,
131
+ "payback_months": (team_cost / (savings / 12)) if savings > 0 else 0,
132
+ "recommendation": self._get_roi_recommendation(roi_multiplier)
133
  }
134
 
135
+ def _get_roi_recommendation(self, roi_multiplier: float) -> str:
136
+ """Get recommendation based on ROI"""
137
+ if roi_multiplier >= 5.0:
138
+ return "🚀 Excellent fit for ARF Enterprise"
139
+ elif roi_multiplier >= 2.0:
140
+ return "✅ Good ROI with ARF Enterprise"
141
+ elif roi_multiplier >= 1.0:
142
+ return "⚠️ Consider ARF OSS edition first"
143
+ else:
144
+ return "🆓 Start with ARF OSS (free)"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
 
146
+ def get_audit_trail(self) -> Dict:
147
+ """Get complete audit trail"""
148
  return {
149
+ "incidents": self.incident_history,
150
+ "executions": self.execution_history,
151
+ "learning_stats": self.learning_stats,
152
+ "exported_at": datetime.datetime.now().isoformat()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  }
154
 
155
+ def reset_demo(self):
156
+ """Reset demo state"""
157
+ self.incident_history = []
158
+ self.execution_history = []
159
+ self.learning_stats = {
160
+ "patterns_detected": 0,
161
+ "similar_incidents_found": 0,
162
+ "healing_intents_created": 0
163
+ }