python
import time
from collections import defaultdict, deque
class AgentLoopDetector:
def __init__(self, window_s=10, rate_threshold=5, diversity_threshold=0.2):
self.window_s = window_s
self.rate_threshold = rate_threshold
self.diversity_threshold = diversity_threshold
self.events = defaultdict(deque)
def is_looping(self, caller_id, payload_hash) -> bool:
now = time.monotonic()
q = self.events[caller_id]
q.append((now, payload_hash))
while q and q[0] < now – self.window_s:
q.popleft()
rate = len(q)
if rate < self.rate_threshold:
return False
unique = len({h for _, h in q})
diversity = unique / rate
return diversity < self.diversity_threshold
Örnek kullanım:
detector = AgentLoopDetector()
if detector.is_looping(caller_id=”agent-1″, payload_hash=”test1″):
quarantine(caller_id=”agent-1″)
Bu Gelişmeyi Toplulukta Değerlendirin
Haber hakkındaki düşüncelerinizi, donanım deneyimlerinizi ve teknik sorularınızı topluluk üyeleriyle anlık olarak tartışın.
Bir yanıt yazın