atlasbot: steer metric focus with route hints

This commit is contained in:
Brad Stein 2026-02-02 11:00:00 -03:00
parent c0fd606f43
commit eaba83a033
2 changed files with 16 additions and 4 deletions

View File

@ -201,6 +201,8 @@ class AnswerEngine:
classify.setdefault("needs_snapshot", True) classify.setdefault("needs_snapshot", True)
classify.setdefault("answer_style", "direct") classify.setdefault("answer_style", "direct")
classify.setdefault("follow_up", False) classify.setdefault("follow_up", False)
classify.setdefault("focus_entity", "unknown")
classify.setdefault("focus_metric", "unknown")
_debug_log("route_parsed", {"classify": classify, "normalized": normalized}) _debug_log("route_parsed", {"classify": classify, "normalized": normalized})
cluster_terms = ( cluster_terms = (
"atlas", "atlas",
@ -270,6 +272,8 @@ class AnswerEngine:
sub_questions = _select_subquestions(parts, normalized, plan.max_subquestions) sub_questions = _select_subquestions(parts, normalized, plan.max_subquestions)
_debug_log("decompose_parsed", {"sub_questions": sub_questions}) _debug_log("decompose_parsed", {"sub_questions": sub_questions})
keyword_tokens = _extract_keywords(question, normalized, sub_questions=sub_questions, keywords=keywords) keyword_tokens = _extract_keywords(question, normalized, sub_questions=sub_questions, keywords=keywords)
focus_entity = str(classify.get("focus_entity") or "unknown").lower()
focus_metric = str(classify.get("focus_metric") or "unknown").lower()
snapshot_context = "" snapshot_context = ""
if classify.get("needs_snapshot"): if classify.get("needs_snapshot"):
@ -295,12 +299,15 @@ class AnswerEngine:
hardware_facts = [seg.strip() for seg in line.split(" | ") if seg.strip().startswith("hardware_usage_avg:")] hardware_facts = [seg.strip() for seg in line.split(" | ") if seg.strip().startswith("hardware_usage_avg:")]
break break
metric_facts = [line for line in key_facts if re.search(r"\d", line)] metric_facts = [line for line in key_facts if re.search(r"\d", line)]
if hardware_facts: if focus_entity == "node" and hottest_facts:
metric_facts = hottest_facts
key_facts = _merge_fact_lines(metric_facts, key_facts)
elif hardware_facts:
metric_facts = hardware_facts metric_facts = hardware_facts
key_facts = _merge_fact_lines(metric_facts, key_facts) key_facts = _merge_fact_lines(metric_facts, key_facts)
if classify.get("question_type") in {"metric", "diagnostic"}: if classify.get("question_type") in {"metric", "diagnostic"}:
lowered_q = f"{question} {normalized}".lower() lowered_q = f"{question} {normalized}".lower()
if any(tok in lowered_q for tok in ("hardware", "class", "type", "rpi", "jetson", "amd64", "arm64")) and any( if focus_entity != "node" and any(tok in lowered_q for tok in ("hardware", "class", "type", "rpi", "jetson", "amd64", "arm64")) and any(
tok in lowered_q for tok in ("average", "avg", "mean", "ram", "memory", "cpu", "load") tok in lowered_q for tok in ("average", "avg", "mean", "ram", "memory", "cpu", "load")
): ):
hw_top = None hw_top = None
@ -313,7 +320,7 @@ class AnswerEngine:
if hw_top: if hw_top:
metric_facts = [hw_top] metric_facts = [hw_top]
key_facts = _merge_fact_lines(metric_facts, key_facts) key_facts = _merge_fact_lines(metric_facts, key_facts)
if hottest_facts and not hardware_facts: if hottest_facts and not hardware_facts and focus_entity != "class":
metric_facts = hottest_facts metric_facts = hottest_facts
key_facts = _merge_fact_lines(metric_facts, key_facts) key_facts = _merge_fact_lines(metric_facts, key_facts)
if classify.get("question_type") in {"metric", "diagnostic"} and not hottest_facts and not hardware_facts: if classify.get("question_type") in {"metric", "diagnostic"} and not hottest_facts and not hardware_facts:
@ -1259,6 +1266,10 @@ def _metric_candidate_lines(lines: list[str], keywords: list[str] | None, limit:
"pod", "pod",
"pods", "pods",
"namespace", "namespace",
"anomaly",
"anomalies",
"pvc",
"storage",
} }
candidates: list[str] = [] candidates: list[str] = []
for line in lines: for line in lines:

View File

@ -30,7 +30,8 @@ ROUTE_SYSTEM = (
ROUTE_PROMPT = ( ROUTE_PROMPT = (
"Return JSON with fields: needs_snapshot (bool), needs_kb (bool), needs_tool (bool), " "Return JSON with fields: needs_snapshot (bool), needs_kb (bool), needs_tool (bool), "
"answer_style (direct|insightful), follow_up (bool), question_type (metric|diagnostic|planning|open_ended)." "answer_style (direct|insightful), follow_up (bool), question_type (metric|diagnostic|planning|open_ended), "
"focus_entity (node|class|namespace|service|cluster|unknown), focus_metric (cpu|ram|net|io|disk|load|pods|storage|unknown)."
) )
DECOMPOSE_SYSTEM = ( DECOMPOSE_SYSTEM = (