From e486245aaf0fb4f29128e1ebcf3a32d827e3145d Mon Sep 17 00:00:00 2001 From: Brad Stein Date: Tue, 27 Jan 2026 21:09:48 -0300 Subject: [PATCH] atlasbot: guard open-ended LLM calls --- services/comms/scripts/atlasbot/bot.py | 28 ++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/services/comms/scripts/atlasbot/bot.py b/services/comms/scripts/atlasbot/bot.py index aa7e614..47458ea 100644 --- a/services/comms/scripts/atlasbot/bot.py +++ b/services/comms/scripts/atlasbot/bot.py @@ -2530,6 +2530,26 @@ def _open_ended_system() -> str: ) +def _ollama_call_safe( + hist_key, + prompt: str, + *, + context: str, + fallback: str, + system_override: str | None = None, +) -> str: + try: + return _ollama_call( + hist_key, + prompt, + context=context, + use_history=False, + system_override=system_override, + ) + except Exception: + return fallback + + def _candidate_note(candidate: dict[str, Any]) -> str: claim = str(candidate.get("claim") or candidate.get("summary") or "") return claim[:160] + ("…" if len(claim) > 160 else "") @@ -2569,11 +2589,11 @@ def _open_ended_fast( f"Question: {prompt}" ) context = _append_history_context(fact_pack, history_lines) - reply = _ollama_call( + reply = _ollama_call_safe( ("fast", "open"), synthesis_prompt, context=context, - use_history=False, + fallback="I don't have enough data to answer that.", system_override=_open_ended_system(), ) return _ensure_scores(reply) @@ -2690,11 +2710,11 @@ def _open_ended_deep( f"Selected: {json.dumps(top, ensure_ascii=False)}" ) context = _append_history_context(fact_pack, history_lines) - reply = _ollama_call( + reply = _ollama_call_safe( ("deep", "open"), synth_prompt, context=context, - use_history=False, + fallback="I don't have enough data to answer that.", system_override=_open_ended_system(), ) state.update("done", step=6)