petter2025 commited on
Commit
c6cea2c
·
verified ·
1 Parent(s): 0b88148

Update demo/orchestrator.py

Browse files
Files changed (1) hide show
  1. demo/orchestrator.py +65 -38
demo/orchestrator.py CHANGED
@@ -1,62 +1,89 @@
1
- # demo/orchestrator.py
2
  from __future__ import annotations
3
 
4
  import logging
5
- from typing import Any, Dict, Optional
 
 
6
 
7
  logger = logging.getLogger(__name__)
8
 
9
- # --- Optional Streamlit import (SAFE) ---
10
  try:
11
- import streamlit as st # type: ignore
12
- except Exception:
13
- st = None
14
- logger.info("Streamlit not available; running in non-Streamlit mode.")
 
 
 
 
 
 
15
 
16
 
17
  class DemoOrchestrator:
18
  """
19
- Orchestrates demo scenarios.
20
-
21
- Streamlit is OPTIONAL and never required at import time.
22
- This prevents Hugging Face Spaces from crashing.
23
  """
24
 
25
  def __init__(self, enable_streamlit: bool = False):
26
- self.enable_streamlit = enable_streamlit and st is not None
27
-
28
- if enable_streamlit and st is None:
29
- logger.warning(
30
- "Streamlit requested but not installed. "
31
- "Proceeding without Streamlit UI."
32
- )
33
-
34
- def render_streamlit(self) -> None:
35
  """
36
- Render Streamlit UI if available.
37
- Safe no-op otherwise.
38
  """
39
- if not self.enable_streamlit or st is None:
40
- logger.debug("Streamlit UI disabled or unavailable.")
41
- return
42
-
43
- st.title("Agentic Reliability Framework Demo")
44
- st.markdown("Interactive demo running inside Streamlit.")
45
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  def run_scenario(self, scenario: Dict[str, Any]) -> Dict[str, Any]:
47
  """
48
- Run a demo scenario without any UI dependency.
49
  """
50
  logger.info("Running scenario: %s", scenario.get("name", "unknown"))
51
 
52
- result = {
53
  "scenario": scenario.get("name"),
54
  "status": "completed",
55
  "output": scenario,
56
- }
57
-
58
- # Optional Streamlit visualization
59
- if self.enable_streamlit and st is not None:
60
- st.json(result)
61
-
62
- return result
 
1
+ # demo/orchestrator.py - FIXED VERSION
2
  from __future__ import annotations
3
 
4
  import logging
5
+ import asyncio
6
+ from typing import Any, Dict, Optional, List
7
+ import time
8
 
9
  logger = logging.getLogger(__name__)
10
 
11
+ # Import mock ARF functions
12
  try:
13
+ from demo.mock_arf import (
14
+ simulate_arf_analysis,
15
+ run_rag_similarity_search,
16
+ create_mock_healing_intent,
17
+ calculate_pattern_confidence
18
+ )
19
+ MOCK_ARF_AVAILABLE = True
20
+ except ImportError:
21
+ logger.warning("Mock ARF functions not available")
22
+ MOCK_ARF_AVAILABLE = False
23
 
24
 
25
  class DemoOrchestrator:
26
  """
27
+ Orchestrates demo scenarios with proper agent workflow.
 
 
 
28
  """
29
 
30
  def __init__(self, enable_streamlit: bool = False):
31
+ self.enable_streamlit = enable_streamlit
32
+
33
+ async def analyze_incident(self, scenario_name: str, scenario_data: Dict[str, Any]) -> Dict[str, Any]:
 
 
 
 
 
 
34
  """
35
+ Analyze an incident using the ARF agent workflow.
36
+ This is the method called by app.py
37
  """
38
+ logger.info(f"Analyzing incident: {scenario_name}")
39
+
40
+ if not MOCK_ARF_AVAILABLE:
41
+ return {
42
+ "status": "error",
43
+ "message": "Mock ARF functions not available",
44
+ "scenario": scenario_name
45
+ }
46
+
47
+ try:
48
+ # Step 1: Detection Agent
49
+ detection_result = simulate_arf_analysis(scenario_data)
50
+
51
+ # Step 2: Recall Agent
52
+ similar_incidents = run_rag_similarity_search(scenario_data)
53
+
54
+ # Step 3: Decision Agent
55
+ confidence = calculate_pattern_confidence(scenario_data, similar_incidents)
56
+ healing_intent = create_mock_healing_intent(scenario_data, similar_incidents, confidence)
57
+
58
+ # Simulate processing time
59
+ await asyncio.sleep(0.5)
60
+
61
+ return {
62
+ "status": "success",
63
+ "scenario": scenario_name,
64
+ "detection": detection_result,
65
+ "recall": similar_incidents,
66
+ "decision": healing_intent,
67
+ "confidence": confidence,
68
+ "processing_time_ms": 450
69
+ }
70
+
71
+ except Exception as e:
72
+ logger.error(f"Error analyzing incident: {e}")
73
+ return {
74
+ "status": "error",
75
+ "message": str(e),
76
+ "scenario": scenario_name
77
+ }
78
+
79
  def run_scenario(self, scenario: Dict[str, Any]) -> Dict[str, Any]:
80
  """
81
+ Run a demo scenario (legacy method).
82
  """
83
  logger.info("Running scenario: %s", scenario.get("name", "unknown"))
84
 
85
+ return {
86
  "scenario": scenario.get("name"),
87
  "status": "completed",
88
  "output": scenario,
89
+ }