petter2025 commited on
Commit
6a378f7
·
verified ·
1 Parent(s): 89d1ac0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -1
app.py CHANGED
@@ -1544,8 +1544,89 @@ class EnhancedReliabilityEngine:
1544
  logger.error(f"Failed to enhance with Claude: {e}")
1545
  # Continue without enhancement
1546
 
1547
- return result # ← Same return, but now with Claude enhancement
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1548
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1549
 
1550
  # === Initialize Engine (with dependency injection) ===
1551
  enhanced_engine = EnhancedReliabilityEngine()
 
1544
  logger.error(f"Failed to enhance with Claude: {e}")
1545
  # Continue without enhancement
1546
 
1547
+ return result
1548
+
1549
+ async def enhance_with_claude(
1550
+ self,
1551
+ event: ReliabilityEvent,
1552
+ agent_results: Dict[str, Any]
1553
+ ) -> Dict[str, Any]:
1554
+ """
1555
+ Enhance agent results with Claude AI reasoning
1556
+
1557
+ This is a NON-INVASIVE layer - all existing logic stays intact.
1558
+ If Claude fails, original results are returned unchanged.
1559
+ """
1560
+ try:
1561
+ # Build comprehensive context for Claude
1562
+ context_parts = []
1563
+
1564
+ # Add event summary
1565
+ context_parts.append("INCIDENT SUMMARY:")
1566
+ context_parts.append(f"Component: {event.component}")
1567
+ context_parts.append(f"Timestamp: {event.timestamp.isoformat()}")
1568
+ context_parts.append(f"Severity: {event.severity.value}")
1569
+ context_parts.append("")
1570
+
1571
+ # Add metrics
1572
+ context_parts.append("METRICS:")
1573
+ context_parts.append(f"• Latency P99: {event.latency_p99}ms")
1574
+ context_parts.append(f"• Error Rate: {event.error_rate:.1%}")
1575
+ context_parts.append(f"• Throughput: {event.throughput} req/s")
1576
+ if event.cpu_util:
1577
+ context_parts.append(f"• CPU: {event.cpu_util:.1%}")
1578
+ if event.memory_util:
1579
+ context_parts.append(f"• Memory: {event.memory_util:.1%}")
1580
+ context_parts.append("")
1581
+
1582
+ # Add agent findings
1583
+ if agent_results:
1584
+ context_parts.append("AGENT ANALYSIS:")
1585
+ if 'multi_agent_analysis' in agent_results:
1586
+ analysis = agent_results['multi_agent_analysis']
1587
+ context_parts.append(json.dumps(analysis, indent=2))
1588
+ elif 'incident_summary' in agent_results:
1589
+ context_parts.append(json.dumps(agent_results['incident_summary'], indent=2))
1590
+
1591
+ context = "\n".join(context_parts)
1592
+
1593
+ # Create prompt for Claude
1594
+ prompt = f"""{context}
1595
+
1596
+ TASK: Provide an executive summary synthesizing all agent analyses.
1597
+ Include:
1598
+ 1. Concise incident description
1599
+ 2. Most likely root cause
1600
+ 3. Single best recovery action
1601
+ 4. Estimated impact and recovery time
1602
+
1603
+ Be specific and actionable."""
1604
 
1605
+ system_prompt = """You are a senior Site Reliability Engineer synthesizing
1606
+ multiple AI agent analyses into clear, actionable guidance for incident response.
1607
+ Focus on clarity, accuracy, and decisive recommendations."""
1608
+
1609
+ # Get Claude's synthesis
1610
+ logger.info("Requesting Claude synthesis of agent results")
1611
+ claude_synthesis = claude_adapter.generate_completion(
1612
+ prompt=prompt,
1613
+ system_prompt=system_prompt
1614
+ )
1615
+
1616
+ # Add Claude's insights to results (non-destructive)
1617
+ agent_results['claude_synthesis'] = {
1618
+ 'summary': claude_synthesis,
1619
+ 'timestamp': datetime.datetime.now(datetime.timezone.utc).isoformat(),
1620
+ 'source': 'claude-opus-4'
1621
+ }
1622
+
1623
+ logger.info("✅ Claude synthesis added to results")
1624
+ return agent_results
1625
+
1626
+ except Exception as e:
1627
+ logger.error(f"Claude enhancement failed: {e}", exc_info=True)
1628
+ # Return original results unchanged - system still works!
1629
+ return agent_results
1630
 
1631
  # === Initialize Engine (with dependency injection) ===
1632
  enhanced_engine = EnhancedReliabilityEngine()