evidence: inject hardware context

This commit is contained in:
Brad Stein 2026-02-03 15:01:23 -03:00
parent 1095503454
commit 2c7490288d

View File

@ -477,6 +477,10 @@ class AnswerEngine:
runbook_fix = _needs_runbook_fix(reply, runbook_paths) runbook_fix = _needs_runbook_fix(reply, runbook_paths)
runbook_needed = _needs_runbook_reference(normalized, runbook_paths, reply) runbook_needed = _needs_runbook_reference(normalized, runbook_paths, reply)
needs_evidence = _needs_evidence_fix(reply, classify) needs_evidence = _needs_evidence_fix(reply, classify)
hardware_terms = ("rpi", "raspberry", "jetson", "amd64", "arm64", "hardware")
hardware_line = _line_starting_with(summary_lines, "hardware_nodes:")
if any(term in lowered_question for term in hardware_terms) and hardware_line:
needs_evidence = True
if classify.get("question_type") in {"open_ended", "planning"} and metric_facts: if classify.get("question_type") in {"open_ended", "planning"} and metric_facts:
needs_evidence = True needs_evidence = True
resolved_runbook = None resolved_runbook = None
@ -507,6 +511,8 @@ class AnswerEngine:
extra_bits.append("ResolvedRunbook: " + resolved_runbook) extra_bits.append("ResolvedRunbook: " + resolved_runbook)
if metric_facts: if metric_facts:
extra_bits.append("MustUseFacts: " + "; ".join(metric_facts[:4])) extra_bits.append("MustUseFacts: " + "; ".join(metric_facts[:4]))
if hardware_line:
extra_bits.append("HardwareNodes: " + hardware_line)
if allowed_nodes: if allowed_nodes:
extra_bits.append("AllowedNodes: " + ", ".join(allowed_nodes)) extra_bits.append("AllowedNodes: " + ", ".join(allowed_nodes))
if allowed_namespaces: if allowed_namespaces:
@ -1623,6 +1629,16 @@ def _best_keyword_line(lines: list[str], keywords: list[str]) -> str | None:
return best if best_score > 0 else None return best if best_score > 0 else None
def _line_starting_with(lines: list[str], prefix: str) -> str | None:
if not lines or not prefix:
return None
lower_prefix = prefix.lower()
for line in lines:
if str(line).lower().startswith(lower_prefix):
return line
return None
def _lexicon_context(summary: dict[str, Any]) -> str: # noqa: C901 def _lexicon_context(summary: dict[str, Any]) -> str: # noqa: C901
if not isinstance(summary, dict): if not isinstance(summary, dict):
return "" return ""