From 67488a88981bfb707e12249aff06ad07a6ff5270 Mon Sep 17 00:00:00 2001 From: Brad Stein Date: Sun, 1 Feb 2026 17:47:39 -0300 Subject: [PATCH] atlasbot: use hardware usage facts for hardware questions --- atlasbot/engine/answerer.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/atlasbot/engine/answerer.py b/atlasbot/engine/answerer.py index 49f8ec0..6682660 100644 --- a/atlasbot/engine/answerer.py +++ b/atlasbot/engine/answerer.py @@ -267,11 +267,15 @@ class AnswerEngine: selected = _select_chunks(chunks, scored, plan, keyword_tokens) key_facts = _key_fact_lines(summary_lines, keyword_tokens) hottest_facts = _extract_hottest_facts(summary_lines, f"{question} {normalized}") + hardware_facts = _extract_hardware_usage_facts(summary_lines, f"{question} {normalized}") metric_facts = [line for line in key_facts if re.search(r"\d", line)] - if hottest_facts: + if hardware_facts: + metric_facts = hardware_facts + key_facts = _merge_fact_lines(metric_facts, key_facts) + if hottest_facts and not hardware_facts: metric_facts = hottest_facts key_facts = _merge_fact_lines(metric_facts, key_facts) - if classify.get("question_type") in {"metric", "diagnostic"} and not hottest_facts: + if classify.get("question_type") in {"metric", "diagnostic"} and not hottest_facts and not hardware_facts: metric_candidates = _metric_candidate_lines(summary_lines, keyword_tokens) selected_facts = await _select_metric_facts(call_llm, normalized, metric_candidates, plan) if selected_facts: @@ -1047,6 +1051,20 @@ def _extract_hottest_facts(lines: list[str], question: str) -> list[str]: return [fact for fact in facts if any(label in fact for label in wanted)] or facts +def _extract_hardware_usage_facts(lines: list[str], question: str) -> list[str]: + if not lines: + return [] + lowered = question.lower() + if "hardware" not in lowered: + return [] + if not any(term in lowered for term in ("average", "avg", "mean", "load", "cpu", "ram", "memory")): + return [] + for line in lines: + if line.startswith("hardware_usage_avg:"): + return [line] + return [] + + def _metric_candidate_lines(lines: list[str], keywords: list[str] | None, limit: int = 40) -> list[str]: if not lines: return []