From 19b52ac5e3efcf49d8933348b6877b3d80088da1 Mon Sep 17 00:00:00 2001 From: Brad Stein Date: Wed, 28 Jan 2026 03:29:21 -0300 Subject: [PATCH] atlasbot: add fact-pack fallback for fast --- services/comms/scripts/atlasbot/bot.py | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/services/comms/scripts/atlasbot/bot.py b/services/comms/scripts/atlasbot/bot.py index b73d3f3..4fa67d4 100644 --- a/services/comms/scripts/atlasbot/bot.py +++ b/services/comms/scripts/atlasbot/bot.py @@ -3823,6 +3823,37 @@ def _has_body_lines(answer: str) -> bool: return False +def _fallback_fact_answer(prompt: str, context: str) -> str: + facts: list[str] = [] + for line in (context or "").splitlines(): + trimmed = line.strip() + if not trimmed.startswith("F"): + continue + if ":" not in trimmed: + continue + fact = trimmed.split(":", 1)[1].strip() + if fact.startswith("-"): + fact = fact.lstrip("-").strip() + if fact: + facts.append(fact) + if not facts: + return "" + tokens = set(_tokens(prompt)) + best_fact = "" + best_score = -1 + for fact in facts: + score = len(tokens & set(_tokens(fact))) + if score > best_score: + best_score = score + best_fact = fact + if best_score <= 0: + return "" + sentence = f"Based on the snapshot, {best_fact}" + if not sentence.endswith((".", "!", "?")): + sentence += "." + return sentence + + def _open_ended_fast_single( prompt: str, *, @@ -3849,6 +3880,10 @@ def _open_ended_fast_single( system_override=_open_ended_system(), model=model, ) + if not _has_body_lines(reply): + fallback = _fallback_fact_answer(prompt, context) + if fallback: + reply = fallback if state: state.update("done", step=_open_ended_total_steps("fast")) return _ensure_scores(reply)