Spaces:
Running
Running
Update SuperAgent/app/services/router.py
Browse files
SuperAgent/app/services/router.py
CHANGED
|
@@ -636,7 +636,40 @@ class RouterService:
|
|
| 636 |
"orchestration": orch
|
| 637 |
}
|
| 638 |
|
| 639 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 640 |
# Check if asset specification is required but missing/invalid
|
| 641 |
if intent not in ("report", "executive") and not is_all_query and not asset_name:
|
| 642 |
user_specs = [
|
|
|
|
| 636 |
"orchestration": orch
|
| 637 |
}
|
| 638 |
|
| 639 |
+
# Check if user requested a specific metric (e.g., oil level, pressure) that the selected asset does NOT possess
|
| 640 |
+
lowered_msg = state["message"].lower()
|
| 641 |
+
requested_metric = None
|
| 642 |
+
for m_kw in ["oil_level", "oil level", "level", "pressure", "voltage", "current", "vibration"]:
|
| 643 |
+
if m_kw in lowered_msg:
|
| 644 |
+
requested_metric = m_kw
|
| 645 |
+
break
|
| 646 |
+
|
| 647 |
+
if requested_metric and asset_id:
|
| 648 |
+
user_allowed = asset_registry.list_all_assets(state["user_id"])
|
| 649 |
+
matched_asset_obj = next((a for a in user_allowed if str(a["id"]) == str(asset_id)), None)
|
| 650 |
+
if matched_asset_obj:
|
| 651 |
+
asset_attr_keys = [str(k).lower() for k in (matched_asset_obj.get("attribute_keys") or matched_asset_obj.get("attributes") or [])]
|
| 652 |
+
clean_kw = requested_metric.replace(" ", "_")
|
| 653 |
+
has_metric = any(clean_kw in k or requested_metric in k for k in asset_attr_keys)
|
| 654 |
+
|
| 655 |
+
if not has_metric:
|
| 656 |
+
matching_assets = [
|
| 657 |
+
a["name"] for a in user_allowed
|
| 658 |
+
if any(clean_kw in str(k).lower() or requested_metric in str(k).lower() for k in (a.get("attribute_keys") or a.get("attributes") or []))
|
| 659 |
+
]
|
| 660 |
+
sample_names = ", ".join(matching_assets[:4]) if matching_assets else "Tank 1, Physical 01"
|
| 661 |
+
avail_metrics = ", ".join([str(k).replace("_", " ").title() for k in asset_attr_keys if str(k).lower() not in {'notes', 'location'}]) or "Temperature, Humidity"
|
| 662 |
+
|
| 663 |
+
answer = (
|
| 664 |
+
f"**{asset_name}** (active in this chat) does not have an **{requested_metric.replace('_', ' ').title()}** sensor (available metrics: **{avail_metrics}**).\n\n"
|
| 665 |
+
f"Which asset's **{requested_metric.replace('_', ' ').title()}** would you like to check? (e.g., {sample_names})"
|
| 666 |
+
)
|
| 667 |
+
orch.append(f"Gateway: Metric '{requested_metric}' absent on '{asset_name}'. Prompting counter-question.")
|
| 668 |
+
return {
|
| 669 |
+
"intent": "counter_question",
|
| 670 |
+
"answer": answer,
|
| 671 |
+
"orchestration": orch
|
| 672 |
+
}
|
| 673 |
# Check if asset specification is required but missing/invalid
|
| 674 |
if intent not in ("report", "executive") and not is_all_query and not asset_name:
|
| 675 |
user_specs = [
|