feat(self): add bounded improvement learning loop

This commit is contained in:
m
2026-08-30 22:26:09 +03:00
parent 4559e0439c
commit 82b89a37d3
10 changed files with 597 additions and 22 deletions
+12
View File
@@ -1,6 +1,18 @@
package self
type BenchmarkCaseRef string
type BenchmarkCase struct {
ID string
PrincipalID string
TaskClass string
EvidenceRefs []SemanticReference
RecordedAt int64
}
func (c BenchmarkCase) Valid() bool {
return c.ID != "" && c.PrincipalID != "" && c.TaskClass != "" && len(c.EvidenceRefs) > 0 && c.RecordedAt > 0
}
type PersonalBenchmark struct {
ID string
PrincipalID string
+161 -9
View File
@@ -6,6 +6,58 @@ type AssessmentID string
type LearningLedgerEntryID string
type AssessmentState string
type LearningSignalKind string
type DiagnosisClass string
type EpistemicStatus string
type InterventionClass string
type DecisionRegretKind string
type CandidateState string
const (
SignalVerifiedFailure LearningSignalKind = "VERIFIED_FAILURE"
SignalUserCorrection LearningSignalKind = "USER_CORRECTION"
SignalRepeatedMistake LearningSignalKind = "REPEATED_KNOWN_MISTAKE"
SignalReflexDivergence LearningSignalKind = "REFLEX_DIVERGENCE"
SignalSkillFallback LearningSignalKind = "SKILL_FALLBACK"
SignalUnexpectedEscalation LearningSignalKind = "UNEXPECTED_ESCALATION"
SignalOutcomeMismatch LearningSignalKind = "OUTCOME_MISMATCH"
SignalRetryFallback LearningSignalKind = "RETRY_FALLBACK"
SignalStaleDependency LearningSignalKind = "STALE_DEPENDENCY"
SignalDecisionRegret LearningSignalKind = "DECISION_REGRET"
SignalBetterSolution LearningSignalKind = "BETTER_SOLUTION"
DiagnosisMemoryMissing DiagnosisClass = "MEMORY_MISSING"
DiagnosisMemoryNotRetrieved DiagnosisClass = "MEMORY_NOT_RETRIEVED"
DiagnosisWrongScope DiagnosisClass = "WRONG_SCOPE"
DiagnosisStaleKnowledge DiagnosisClass = "STALE_KNOWLEDGE"
DiagnosisContextSelection DiagnosisClass = "CONTEXT_SELECTION"
DiagnosisReasoningFailure DiagnosisClass = "REASONING_FAILURE"
DiagnosisSkillFailure DiagnosisClass = "SKILL_FAILURE"
DiagnosisReflexFailure DiagnosisClass = "REFLEX_FAILURE"
DiagnosisToolFailure DiagnosisClass = "TOOL_FAILURE"
DiagnosisProviderFailure DiagnosisClass = "PROVIDER_FAILURE"
DiagnosisOutcomeVerificationFailure DiagnosisClass = "OUTCOME_VERIFICATION_FAILURE"
DiagnosisRoutingInefficiency DiagnosisClass = "ROUTING_INEFFICIENCY"
DiagnosisUnknown DiagnosisClass = "UNKNOWN_CAUSE"
EpistemicKnown EpistemicStatus = "KNOWN"
EpistemicSupported EpistemicStatus = "SUPPORTED"
EpistemicHypothesis EpistemicStatus = "HYPOTHESIS"
EpistemicUnknown EpistemicStatus = "UNKNOWN"
InterventionConfiguration InterventionClass = "CONFIGURATION"
InterventionSkillReview InterventionClass = "SKILL_REVIEW"
InterventionReflexReview InterventionClass = "REFLEX_REVIEW"
InterventionRoutingReview InterventionClass = "ROUTING_REVIEW"
InterventionProviderReview InterventionClass = "PROVIDER_REVIEW"
InterventionContextReview InterventionClass = "CONTEXT_REVIEW"
RegretUnavailableThen DecisionRegretKind = "INFORMATION_UNAVAILABLE_THEN"
RegretAvailableUnused DecisionRegretKind = "INFORMATION_AVAILABLE_UNUSED"
RegretIgnoredInContext DecisionRegretKind = "EVIDENCE_IGNORED_IN_CONTEXT"
CandidateProposed CandidateState = "PROPOSED"
CandidateEvaluating CandidateState = "EVALUATING"
CandidateKept CandidateState = "KEPT"
CandidateRejected CandidateState = "REJECTED"
CandidateRolledBack CandidateState = "ROLLED_BACK"
)
const (
AssessmentCandidate AssessmentState = "CANDIDATE"
AssessmentConfirmed AssessmentState = "CONFIRMED"
@@ -37,6 +89,17 @@ type WeaknessPattern struct {
DetectionEvidenceRefs []SemanticReference
State AssessmentState
RecordedAt int64
TaskPattern string
ScopeKey string
EnvironmentVersion string
DependencyRefs []SemanticReference
Frequency int
LastObservedAt int64
Severity int
AffectedComponent string
AffectedStrategy string
ConfidenceMillis int64
EpistemicStatus EpistemicStatus
}
type DependencyAssessment struct {
ID AssessmentID
@@ -48,15 +111,83 @@ type DependencyAssessment struct {
AssessedAt int64
}
type ImprovementNeed struct {
ID AssessmentID
PrincipalID string
SubjectRef SemanticReference
ProblemSummary string
EvidenceRefs []SemanticReference
ExpectedBenefit string
Priority int
State string
CreatedAt int64
ID AssessmentID
PrincipalID string
SubjectRef SemanticReference
ProblemSummary string
EvidenceRefs []SemanticReference
ExpectedBenefit string
Priority int
State string
CreatedAt int64
Diagnosis DiagnosisClass
DiagnosisStatus EpistemicStatus
AffectedComponent string
ScopeKey string
Risk string
Intervention InterventionClass
Hypothesis string
EvaluationPlan string
MustNotWorsen string
RollbackPlan string
ResourceCost string
}
type LearningSignal struct {
ID string
PrincipalID string
Kind LearningSignalKind
TaskPattern string
ScopeKey string
SubjectRef SemanticReference
EvidenceRefs []SemanticReference
ExpectedOutcome string
ActualOutcome string
DependencyRefs []SemanticReference
EnvironmentVersion string
ObservedAt int64
Severity int
UserImpact int
CorrectionCount int
DecisionRegret DecisionRegretKind
}
type Diagnosis struct {
Class DiagnosisClass
Status EpistemicStatus
Rationale string
EvidenceRefs []SemanticReference
ConfidenceMillis int64
}
type ImprovementCandidate struct {
ID string
PrincipalID string
NeedRef SemanticReference
Hypothesis string
ExpectedEffect string
EvaluationPlan string
MustNotWorsen []string
RollbackPlan string
ResourceCost string
Creator string
IndependentEvaluator string
State CandidateState
EvidenceRefs []SemanticReference
CreatedAt int64
}
type ImprovementEvaluation struct {
CandidateRef SemanticReference
Evaluator string
EvidenceRefs []SemanticReference
ExpectedQuality int64
ActualQuality int64
ExpectedLatency int64
ActualLatency int64
MustNotWorsenPass bool
Decision CandidateState
EvaluatedAt int64
}
type LearningLedgerEntry struct {
ID LearningLedgerEntryID
@@ -90,3 +221,24 @@ func (l LearningLedgerEntry) Validate() error {
}
return nil
}
func (s LearningSignal) Validate() error {
if s.ID == "" || s.PrincipalID == "" || s.Kind == "" || s.TaskPattern == "" || s.ScopeKey == "" || !s.SubjectRef.Valid() || len(s.EvidenceRefs) == 0 || s.ObservedAt < 1 {
return fmt.Errorf("learning signal is incomplete")
}
return nil
}
func (d Diagnosis) Validate() error {
if d.Class == "" || d.Status == "" || len(d.EvidenceRefs) == 0 || d.ConfidenceMillis < 0 || d.ConfidenceMillis > 1000 {
return fmt.Errorf("diagnosis requires bounded evidence")
}
return nil
}
func (c ImprovementCandidate) Validate() error {
if c.ID == "" || c.PrincipalID == "" || !c.NeedRef.Valid() || c.Hypothesis == "" || c.ExpectedEffect == "" || c.EvaluationPlan == "" || c.MustNotWorsen == nil || c.RollbackPlan == "" || c.Creator == "" || c.IndependentEvaluator == "" || c.Creator == c.IndependentEvaluator || len(c.EvidenceRefs) == 0 || c.CreatedAt < 1 {
return fmt.Errorf("candidate lacks independent bounded evaluation")
}
return nil
}