Add two-tier LLM analysis with triage/escalation

Triage model (LLM_MODEL) handles every message cheaply. If toxicity
>= 0.25, off_topic, or coherence < 0.6, the message is re-analyzed
with the heavy model (LLM_ESCALATION_MODEL). Chat, image analysis,
/bcs-test, and /bcs-scan always use the heavy model.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-21 18:33:36 -05:00
parent 64e9474c99
commit b9bac899f9
5 changed files with 45 additions and 9 deletions
+21 -1
View File
@@ -141,7 +141,7 @@ class SentimentCog(commands.Cog):
game_channels = config.get("game_channels", {})
channel_context = self._build_channel_context(message, game_channels)
# Analyze the combined message
# Analyze the combined message (triage with lightweight model)
context = self._get_context(message)
user_notes = self.bot.drama_tracker.get_user_notes(message.author.id)
result = await self.bot.llm.analyze_message(
@@ -152,6 +152,26 @@ class SentimentCog(commands.Cog):
if result is None:
return
# Escalation: re-analyze with heavy model if triage flags something
escalation_threshold = sentiment_config.get("escalation_threshold", 0.25)
needs_escalation = (
result["toxicity_score"] >= escalation_threshold
or result.get("off_topic", False)
or result.get("coherence_score", 1.0) < 0.6
)
if needs_escalation:
triage_score = result["toxicity_score"]
heavy_result = await self.bot.llm_heavy.analyze_message(
combined_content, context, user_notes=user_notes,
channel_context=channel_context,
)
if heavy_result is not None:
logger.info(
"Escalated to heavy model (triage_score=%.2f) for %s",
triage_score, message.author.display_name,
)
result = heavy_result
score = result["toxicity_score"]
categories = result["categories"]
reasoning = result["reasoning"]