File size: 826 Bytes
d2a5f5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Error Learning Loop — Vitalis FSI
Tracks failures, extracts patterns, feeds corrections back into reasoning.
"""
import time


class ErrorLearningLoop:
    def __init__(self):
        self._errors  = []
        self._corrections = {}

    def record(self, task: str, error: str):
        self._errors.append({
            "task": task, "error": error, "t": time.time()})
        key = error[:40]
        self._corrections[key] = self._corrections.get(key, 0) + 1

    def most_common(self) -> list:
        return sorted(self._corrections.items(),
                      key=lambda x: x[1], reverse=True)[:5]

    def report(self) -> dict:
        return {
            "total_errors":   len(self._errors),
            "unique_patterns": len(self._corrections),
            "most_common":    self.most_common(),
        }