diff --git a/atlasbot/engine/answerer.py b/atlasbot/engine/answerer.py index 72e5944..94699fd 100644 --- a/atlasbot/engine/answerer.py +++ b/atlasbot/engine/answerer.py @@ -166,6 +166,7 @@ class AnswerEngine: allowed_nodes = _allowed_nodes(summary) allowed_namespaces = _allowed_namespaces(summary) summary_lines = _summary_lines(snapshot_used) + global_facts = _global_facts(summary_lines) kb_summary = self._kb.summary() runbooks = self._kb.runbook_titles(limit=6) runbook_paths = self._kb.runbook_paths(limit=10) @@ -386,8 +387,11 @@ class AnswerEngine: ) facts_used = list(dict.fromkeys(key_facts)) if key_facts else list(dict.fromkeys(metric_facts)) snapshot_context = "ClusterSnapshot:\n" + "\n".join([chunk["text"] for chunk in selected]) - if key_facts: - snapshot_context = "KeyFacts:\n" + "\n".join(key_facts) + "\n\n" + snapshot_context + combined_facts = key_facts + if global_facts: + combined_facts = _merge_fact_lines(global_facts, key_facts) + if combined_facts: + snapshot_context = "KeyFacts:\n" + "\n".join(combined_facts) + "\n\n" + snapshot_context context = _join_context( [kb_summary, _format_runbooks(runbooks), snapshot_context, history_ctx if classify.get("follow_up") else ""] @@ -1445,6 +1449,18 @@ def _filter_lines_by_keywords(lines: list[str], keywords: list[str], max_lines: return (filtered or lines)[:max_lines] +def _global_facts(lines: list[str]) -> list[str]: + if not lines: + return [] + wanted = ("nodes_total", "nodes_ready", "cluster_name", "cluster", "nodes_not_ready") + facts: list[str] = [] + for line in lines: + lower = line.lower() + if any(key in lower for key in wanted): + facts.append(line) + return _dedupe_lines(facts, limit=6) + + def _lexicon_context(summary: dict[str, Any]) -> str: # noqa: C901 if not isinstance(summary, dict): return ""