Procházet zdrojové kódy

Follow-Up: Timeout (60s) + Intent-Vorrang bei hoher Confidence

Probleme behoben:
- Follow-Up-Kontext blieb unbegrenzt aktiv (kein Timeout)
  "Musik spielen" wurde als Reminder-Antwort interpretiert
- Kein Check ob ein neuer Intent erkannt wurde

Fixes:
- Follow-Up-Timeout: 60 Sekunden, danach wird Kontext geloescht
- Intent-Vorrang: Wenn Classifier Intent mit conf >= 0.8 erkennt
  der NICHT zum Follow-Up gehoert, wird Follow-Up uebersprungen
- Zeitstempel (created_at) im Follow-Up-Kontext

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
patrick před 1 týdnem
rodič
revize
ffe963499f
1 změnil soubory, kde provedl 26 přidání a 0 odebrání
  1. 26 0
      trixy_core/nlp/intent_dispatcher.py

+ 26 - 0
trixy_core/nlp/intent_dispatcher.py

@@ -129,6 +129,30 @@ class IntentDispatcherService(IService):
 
         # Follow-Up-Validierung: Ist eine Rueckfrage aktiv?
         followup_ctx = self._active_followups.get(event_data.satellite_id)
+        if followup_ctx:
+            import time as _time
+
+            # Timeout: Follow-Up nach 60s ablaufen lassen
+            created_at = followup_ctx.get("created_at", 0)
+            if created_at and (_time.time() - created_at) > 60:
+                pdebug(f"[DISPATCHER] Follow-Up abgelaufen (>60s)")
+                del self._active_followups[event_data.satellite_id]
+                followup_ctx = None
+
+            # Wenn der Classifier einen klaren anderen Intent erkannt hat
+            # (nicht "unknown" und hohe Confidence), Follow-Up ignorieren
+            elif (event_data.intent != "unknown"
+                  and event_data.confidence >= 0.8
+                  and event_data.intent != followup_ctx.get("follow_up_intent")
+                  and event_data.intent != followup_ctx.get("original_intent")):
+                pinfo(
+                    f"[DISPATCHER] Follow-Up uebersprungen — "
+                    f"neuer Intent '{event_data.intent}' (conf={event_data.confidence:.2f}) "
+                    f"hat Vorrang vor Follow-Up '{followup_ctx.get('follow_up_intent')}'"
+                )
+                del self._active_followups[event_data.satellite_id]
+                followup_ctx = None
+
         if followup_ctx:
             validated = self._validate_followup_response(
                 event_data, followup_ctx,
@@ -257,12 +281,14 @@ class IntentDispatcherService(IService):
                         followup_prompt = result.follow_up_intent
 
                         # Follow-Up-Kontext mit Validierung speichern
+                        import time as _time
                         self._active_followups[event_data.satellite_id] = {
                             "follow_up_intent": result.follow_up_intent,
                             "valid_responses": result.follow_up_valid_responses,
                             "retry_text": result.follow_up_retry_text,
                             "data": result.data or {},
                             "original_intent": event_data.intent,
+                            "created_at": _time.time(),
                         }
 
             except Exception as e: