From 0a10a2d861a1114642785b45f8ac2fcc9b58b932 Mon Sep 17 00:00:00 2001 From: Brad Stein Date: Tue, 27 Jan 2026 18:17:29 -0300 Subject: [PATCH] atlasbot: add narrative insights --- services/comms/scripts/atlasbot/bot.py | 50 ++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/services/comms/scripts/atlasbot/bot.py b/services/comms/scripts/atlasbot/bot.py index 0dcfc60..ada8dd7 100644 --- a/services/comms/scripts/atlasbot/bot.py +++ b/services/comms/scripts/atlasbot/bot.py @@ -1616,7 +1616,7 @@ def _insight_candidates( def _select_insight( prompt: str, candidates: list[tuple[str, str, str]], -) -> tuple[str, str] | None: +) -> tuple[str, str, str] | None: if not candidates: return None q = normalize_query(prompt) @@ -1624,13 +1624,43 @@ def _select_insight( if any(word in q for word in ("unconventional", "weird", "odd", "unique", "surprising")): prefer_keys.extend(["hardware", "availability"]) if any(word in q for word in ("another", "else", "different", "other")) and len(candidates) > 1: - return candidates[1][1], candidates[1][2] + return candidates[1] if prefer_keys: for key, text, conf in candidates: if key in prefer_keys: - return text, conf - key, text, conf = candidates[0] - return text, conf + return key, text, conf + return candidates[0] + + +def _format_insight_text(key: str, text: str) -> str: + cleaned = text.strip().rstrip(".") + if not cleaned: + return "" + if key == "hardware": + counts = cleaned.replace("Hardware mix includes ", "") + return f"Atlas mixes Raspberry Pi, Jetson, and AMD64 nodes ({counts})." + if key == "postgres": + detail = cleaned.replace("Postgres is at ", "") + return f"Postgres looks healthy at {detail}." + if key == "pods": + detail = cleaned.replace("There are ", "") + return f"Pods look stable with {detail}." + if key == "availability": + return cleaned + "." + if key in ("cpu", "ram"): + return cleaned + "." + return cleaned + "." + + +def _insight_prefix(prompt: str) -> str: + q = normalize_query(prompt) + if any(word in q for word in ("another", "else", "different", "other")): + return "Another interesting detail: " + if any(word in q for word in ("unconventional", "weird", "odd", "unique", "surprising")): + return "What stands out is that " + if any(word in q for word in ("interesting", "notable", "fun", "cool")): + return "One notable detail: " + return "" def cluster_overview_answer( @@ -1714,8 +1744,14 @@ def cluster_answer( candidates = _insight_candidates(inventory, snapshot) selected = _select_insight(prompt, candidates) if selected: - text, confidence = selected - return _format_confidence(text, confidence) + key, raw_text, confidence = selected + formatted = _format_insight_text(key, raw_text) + if not formatted: + formatted = raw_text + prefix = _insight_prefix(prompt) + if prefix: + formatted = prefix + formatted + return _format_confidence(formatted, confidence) structured = structured_answer( prompt, inventory=inventory,