Spaces:
Runtime error
Runtime error
Delete robotics_diagnostician.py
Browse files- robotics_diagnostician.py +0 -106
robotics_diagnostician.py
DELETED
|
@@ -1,106 +0,0 @@
|
|
| 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 = []
|
| 66 |
-
if temp > self.thresholds['temperature']:
|
| 67 |
-
flags.append('overheat')
|
| 68 |
-
if vib > self.thresholds['vibration']:
|
| 69 |
-
flags.append('excess_vibration')
|
| 70 |
-
if curr > self.thresholds['motor_current']:
|
| 71 |
-
flags.append('overcurrent')
|
| 72 |
-
if pos_err > self.thresholds['position_error']:
|
| 73 |
-
flags.append('position_drift')
|
| 74 |
-
|
| 75 |
-
# Determine root cause based on combination
|
| 76 |
-
causes = []
|
| 77 |
-
if 'overheat' in flags and 'overcurrent' in flags:
|
| 78 |
-
causes.append('motor_stall')
|
| 79 |
-
elif 'overheat' in flags:
|
| 80 |
-
causes.append('cooling_failure')
|
| 81 |
-
elif 'excess_vibration' in flags:
|
| 82 |
-
causes.append('bearing_wear')
|
| 83 |
-
elif 'position_drift' in flags:
|
| 84 |
-
causes.append('encoder_misalignment')
|
| 85 |
-
else:
|
| 86 |
-
causes.append('normal_operation')
|
| 87 |
-
|
| 88 |
-
return {
|
| 89 |
-
'specialization': 'robotics',
|
| 90 |
-
'confidence': 0.8 if flags else 0.0,
|
| 91 |
-
'findings': {
|
| 92 |
-
'exceeded_thresholds': flags,
|
| 93 |
-
'likely_root_causes': causes,
|
| 94 |
-
},
|
| 95 |
-
'recommendations': [
|
| 96 |
-
f"Check {cause}" for cause in causes
|
| 97 |
-
] if flags else []
|
| 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 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|