From 8316e5dd15f23b8c99a18969364aff2034291072 Mon Sep 17 00:00:00 2001 From: Brad Stein Date: Wed, 28 Jan 2026 03:20:28 -0300 Subject: [PATCH] atlasbot: fix tag detection for workload queries --- services/comms/scripts/atlasbot/bot.py | 29 ++++++++++++++------------ 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/services/comms/scripts/atlasbot/bot.py b/services/comms/scripts/atlasbot/bot.py index 7d47423..b73d3f3 100644 --- a/services/comms/scripts/atlasbot/bot.py +++ b/services/comms/scripts/atlasbot/bot.py @@ -3154,35 +3154,37 @@ def _open_ended_interpret( def _preferred_tags_for_prompt(prompt: str) -> set[str]: q = normalize_query(prompt) + tokens = set(_tokens(prompt)) tags: set[str] = set() - if any(word in q for word in ("cpu", "ram", "memory", "net", "network", "io", "disk", "hottest", "busy", "usage", "utilization", "load")): + if tokens & {"cpu", "ram", "memory", "net", "network", "io", "disk", "hottest", "busy", "usage", "utilization", "load"}: tags.add("utilization") - if any(word in q for word in ("postgres", "database", "db", "connections")): + if tokens & {"postgres", "database", "db", "connections"}: tags.add("database") - if any(word in q for word in ("pod", "pods", "deployment", "job", "cronjob")): + if tokens & {"pod", "pods", "deployment", "job", "cronjob"}: tags.add("pods") - if any(word in q for word in ("workload", "service", "namespace")): + if tokens & {"workload", "service", "namespace"}: tags.add("workloads") - if any(word in q for word in ("ready", "not ready", "down", "unreachable", "availability")): + if tokens & {"ready", "down", "unreachable", "availability"} or "not ready" in q: tags.add("availability") - if any(word in q for word in ("node", "nodes", "hardware", "arch", "architecture", "rpi", "jetson", "amd64", "arm64", "worker", "control-plane")): + if tokens & {"node", "nodes", "hardware", "arch", "architecture", "rpi", "jetson", "amd64", "arm64", "worker", "control-plane"}: tags.update({"hardware", "inventory", "architecture"}) return tags & _ALLOWED_INSIGHT_TAGS def _primary_tags_for_prompt(prompt: str) -> set[str]: q = normalize_query(prompt) - if any(word in q for word in ("cpu", "ram", "memory", "net", "network", "io", "disk", "hottest", "busy", "usage", "utilization", "load")): + tokens = set(_tokens(prompt)) + if tokens & {"cpu", "ram", "memory", "net", "network", "io", "disk", "hottest", "busy", "usage", "utilization", "load"}: return {"utilization"} - if any(word in q for word in ("postgres", "database", "db", "connections")): + if tokens & {"postgres", "database", "db", "connections"}: return {"database"} - if any(word in q for word in ("pod", "pods", "deployment", "job", "cronjob")): + if tokens & {"pod", "pods", "deployment", "job", "cronjob"}: return {"pods"} - if any(word in q for word in ("workload", "service", "namespace")): + if tokens & {"workload", "service", "namespace"}: return {"workloads"} - if any(word in q for word in ("ready", "not ready", "down", "unreachable", "availability")): + if tokens & {"ready", "down", "unreachable", "availability"} or "not ready" in q: return {"availability"} - if any(word in q for word in ("node", "nodes", "hardware", "arch", "architecture", "rpi", "jetson", "amd64", "arm64", "worker", "control-plane")): + if tokens & {"node", "nodes", "hardware", "arch", "architecture", "rpi", "jetson", "amd64", "arm64", "worker", "control-plane"}: return {"hardware", "inventory", "architecture"} return set() @@ -3202,9 +3204,10 @@ def _tags_from_text(text: str) -> set[str]: q = normalize_query(text) if not q: return set() + tokens = set(_tokens(text)) tags: set[str] = set() for tag, keywords in _TAG_KEYWORDS.items(): - if any(word in q for word in keywords): + if any(word in tokens for word in keywords): tags.add(tag) return tags & _ALLOWED_INSIGHT_TAGS