Spaces:
Runtime error
Runtime error
Update robotics_diagnostician.py
Browse files- robotics_diagnostician.py +48 -10
robotics_diagnostician.py
CHANGED
|
@@ -1,32 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import logging
|
| 2 |
-
from typing import Dict, Any
|
| 3 |
from agentic_reliability_framework.runtime.agents.base import BaseAgent, AgentSpecialization
|
| 4 |
-
from
|
| 5 |
|
| 6 |
logger = logging.getLogger(__name__)
|
| 7 |
|
|
|
|
| 8 |
class RoboticsDiagnostician(BaseAgent):
|
| 9 |
-
"""
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
super().__init__(AgentSpecialization.DIAGNOSTICIAN)
|
| 12 |
-
|
| 13 |
-
self.thresholds = {
|
| 14 |
'temperature': 40.0,
|
| 15 |
'vibration': 0.3,
|
| 16 |
'motor_current': 3.5,
|
| 17 |
'position_error': 0.05
|
| 18 |
}
|
| 19 |
|
| 20 |
-
async def analyze(self, event:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
try:
|
| 22 |
-
# Extract metrics
|
| 23 |
temp = getattr(event, 'temperature', None)
|
| 24 |
vib = getattr(event, 'vibration', None)
|
| 25 |
curr = getattr(event, 'motor_current', None)
|
| 26 |
pos_err = getattr(event, 'position_error', None)
|
| 27 |
|
| 28 |
if temp is None:
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Detect which thresholds are exceeded
|
| 32 |
flags = []
|
|
@@ -65,4 +98,9 @@ class RoboticsDiagnostician(BaseAgent):
|
|
| 65 |
}
|
| 66 |
except Exception as e:
|
| 67 |
logger.error(f"RoboticsDiagnostician error: {e}", exc_info=True)
|
| 68 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Root cause analysis for robotic system failures.
|
| 3 |
+
Works with IoTEvent objects that contain temperature, vibration, motor_current, position_error.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
import logging
|
| 7 |
+
from typing import Dict, Any, Optional
|
| 8 |
from agentic_reliability_framework.runtime.agents.base import BaseAgent, AgentSpecialization
|
| 9 |
+
from iot_event import IoTEvent # Use the specific event type (though base ReliabilityEvent also works)
|
| 10 |
|
| 11 |
logger = logging.getLogger(__name__)
|
| 12 |
|
| 13 |
+
|
| 14 |
class RoboticsDiagnostician(BaseAgent):
|
| 15 |
+
"""
|
| 16 |
+
Diagnoses robotic system failures by comparing sensor readings against thresholds.
|
| 17 |
+
Intended to be used with IoTEvent instances.
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
def __init__(self, thresholds: Optional[Dict[str, float]] = None):
|
| 21 |
+
"""
|
| 22 |
+
Args:
|
| 23 |
+
thresholds: Optional dict overriding default sensor thresholds.
|
| 24 |
+
Keys: temperature, vibration, motor_current, position_error.
|
| 25 |
+
"""
|
| 26 |
super().__init__(AgentSpecialization.DIAGNOSTICIAN)
|
| 27 |
+
self.thresholds = thresholds or {
|
|
|
|
| 28 |
'temperature': 40.0,
|
| 29 |
'vibration': 0.3,
|
| 30 |
'motor_current': 3.5,
|
| 31 |
'position_error': 0.05
|
| 32 |
}
|
| 33 |
|
| 34 |
+
async def analyze(self, event: IoTEvent) -> Dict[str, Any]:
|
| 35 |
+
"""
|
| 36 |
+
Analyze sensor readings and return diagnosis.
|
| 37 |
+
|
| 38 |
+
Args:
|
| 39 |
+
event: An IoTEvent containing sensor fields.
|
| 40 |
+
|
| 41 |
+
Returns:
|
| 42 |
+
Dictionary with keys:
|
| 43 |
+
- specialization: 'robotics'
|
| 44 |
+
- confidence: float (0‑1)
|
| 45 |
+
- findings: dict with 'exceeded_thresholds' and 'likely_root_causes'
|
| 46 |
+
- recommendations: list of strings
|
| 47 |
+
"""
|
| 48 |
try:
|
| 49 |
+
# Extract metrics (safe even if event is base ReliabilityEvent without these fields)
|
| 50 |
temp = getattr(event, 'temperature', None)
|
| 51 |
vib = getattr(event, 'vibration', None)
|
| 52 |
curr = getattr(event, 'motor_current', None)
|
| 53 |
pos_err = getattr(event, 'position_error', None)
|
| 54 |
|
| 55 |
if temp is None:
|
| 56 |
+
# Event does not contain IoT fields – cannot diagnose
|
| 57 |
+
return {
|
| 58 |
+
'specialization': 'robotics',
|
| 59 |
+
'confidence': 0.0,
|
| 60 |
+
'findings': {},
|
| 61 |
+
'recommendations': []
|
| 62 |
+
}
|
| 63 |
|
| 64 |
# Detect which thresholds are exceeded
|
| 65 |
flags = []
|
|
|
|
| 98 |
}
|
| 99 |
except Exception as e:
|
| 100 |
logger.error(f"RoboticsDiagnostician error: {e}", exc_info=True)
|
| 101 |
+
return {
|
| 102 |
+
'specialization': 'robotics',
|
| 103 |
+
'confidence': 0.0,
|
| 104 |
+
'findings': {},
|
| 105 |
+
'recommendations': []
|
| 106 |
+
}
|