diff --git a/services/comms/scripts/atlasbot/bot.py b/services/comms/scripts/atlasbot/bot.py index 6f18b9e..96765b1 100644 --- a/services/comms/scripts/atlasbot/bot.py +++ b/services/comms/scripts/atlasbot/bot.py @@ -1037,6 +1037,11 @@ def facts_context( nodes_list = by_hardware.get(key) or [] if nodes_list: lines.append(f"- {key}: {', '.join(nodes_list)}") + if by_hardware: + counts = {key: len(nodes_list) for key, nodes_list in by_hardware.items() if nodes_list} + if counts: + parts = [f"{key}={count}" for key, count in sorted(counts.items())] + lines.append(f"- nodes_by_hardware_count: {', '.join(parts)}") non_rpi = sorted(set(by_hardware.get("jetson", [])) | set(by_hardware.get("amd64", []))) if non_rpi: lines.append(f"- non_raspberry_pi: {', '.join(non_rpi)}") @@ -1096,6 +1101,25 @@ def facts_context( value = metrics.get(key) if value is not None: lines.append(f"- {key}: {value}") + if workloads: + ns_counts: dict[str, int] = collections.defaultdict(int) + for entry in workloads: + if not isinstance(entry, dict): + continue + ns = entry.get("namespace") or "" + pods = entry.get("pods_running") + if pods is None: + pods = entry.get("pods_total") + try: + pods_val = int(pods) + except (TypeError, ValueError): + pods_val = 0 + if ns: + ns_counts[ns] += pods_val + if ns_counts: + top_ns = sorted(ns_counts.items(), key=lambda item: item[1], reverse=True)[:5] + parts = [f"{ns}={count}" for ns, count in top_ns] + lines.append(f"- pods_by_namespace: {', '.join(parts)}") top_restarts = metrics.get("top_restarts_1h") if isinstance(metrics.get("top_restarts_1h"), list) else [] if top_restarts: @@ -2725,6 +2749,8 @@ def _fact_line_tags(line: str) -> set[str]: tags.add("database") if "pods_" in text or "pod phases" in text or "restarts" in text: tags.add("pods") + if "namespace" in text: + tags.add("workloads") if "workloads" in text or "primary_node" in text or "workload_" in text: tags.add("workloads") if "node_details" in text: @@ -2900,6 +2926,8 @@ def _open_ended_system() -> str: "If the question asks for a list, embed the list inline in a sentence (comma-separated). " "If the question is ambiguous, pick a reasonable interpretation and state it briefly. " "Avoid repeating the exact same observation as the last response if possible; vary across metrics, workload, or hardware details. " + "When the fact pack includes hottest_cpu/ram/net/io lines, use them to answer hottest/busiest node questions. " + "When the fact pack includes postgres_hottest_db, use it for questions about the busiest database. " "Do not invent numbers or facts. " "End with lines: Confidence, Relevance (0-100), Satisfaction (0-100), HallucinationRisk (low|medium|high)." )