petter2025 commited on
Commit
eb22bd8
·
verified ·
1 Parent(s): cce889a

Update memory_drift_diagnostician.py

Browse files
Files changed (1) hide show
  1. memory_drift_diagnostician.py +13 -3
memory_drift_diagnostician.py CHANGED
@@ -1,6 +1,6 @@
1
  import logging
2
  import numpy as np
3
- from typing import Dict, Any, List
4
  from agentic_reliability_framework.runtime.agents.base import BaseAgent, AgentSpecialization
5
  from ai_event import AIEvent
6
 
@@ -19,7 +19,15 @@ class MemoryDriftDiagnosticianAgent(BaseAgent):
19
  self.zscore_threshold = zscore_threshold
20
  self._retrieval_scores_history: List[float] = []
21
 
22
- async def analyze(self, event: AIEvent) -> Dict[str, Any]:
 
 
 
 
 
 
 
 
23
  try:
24
  if not event.retrieval_scores:
25
  return {
@@ -32,7 +40,9 @@ class MemoryDriftDiagnosticianAgent(BaseAgent):
32
  current_avg = float(np.mean(event.retrieval_scores))
33
  self._retrieval_scores_history.append(current_avg)
34
 
35
- if len(self._retrieval_scores_history) > self.history_window:
 
 
36
  self._retrieval_scores_history.pop(0)
37
 
38
  if len(self._retrieval_scores_history) < 10:
 
1
  import logging
2
  import numpy as np
3
+ from typing import Dict, Any, List, Optional
4
  from agentic_reliability_framework.runtime.agents.base import BaseAgent, AgentSpecialization
5
  from ai_event import AIEvent
6
 
 
19
  self.zscore_threshold = zscore_threshold
20
  self._retrieval_scores_history: List[float] = []
21
 
22
+ async def analyze(self, event: AIEvent, context_window: Optional[int] = None) -> Dict[str, Any]:
23
+ """
24
+ Analyze drift using retrieval scores.
25
+ Args:
26
+ event: AIEvent containing retrieval_scores.
27
+ context_window: Optional override of history window size.
28
+ Returns:
29
+ Dictionary with drift detection findings.
30
+ """
31
  try:
32
  if not event.retrieval_scores:
33
  return {
 
40
  current_avg = float(np.mean(event.retrieval_scores))
41
  self._retrieval_scores_history.append(current_avg)
42
 
43
+ # Use provided context_window if given, else default
44
+ window = context_window if context_window is not None else self.history_window
45
+ if len(self._retrieval_scores_history) > window:
46
  self._retrieval_scores_history.pop(0)
47
 
48
  if len(self._retrieval_scores_history) < 10: