feat: add metacognition, reflection, consolidation, narrative and notifications
Phase 10. Metacognition is a cognitive process with deterministic self-checks (insufficient evidence, single-source reliance, model output without evidence, repeated failed hypotheses, stale contradictions, calibration overconfidence); its warnings compete for attention and, when admitted, add counter-evidence or open an investigation goal. Reflection reviews the period since the last run (prediction errors, rejected beliefs, corrections, status changes, completed goals, contradictions, calibration), turns repeated failures into procedural lessons written once, and records a reflection event; a model may only word the prose within the mind's budget. Consolidation clusters unconsolidated episodes by shared stemmed terms, creates a belief whose confidence is computed from the episodes as evidence and a semantic memory linked to each episode by derived_from, and records jobs with inputs and outputs. Wording may come from the consolidate prompt within a per-run model budget; the job says which. Operators can run, pause and reject; originals are never touched. The narrative hook keeps a five-part first-person narrative built from state and stored with narrative_updated events. The notification hook applies explicit thresholded rules, aggregates repeats within a cooldown and records suppressions with reasons. A scheduled job runs consolidation and reflection per mind, switching the runtime mode while it works. API, Background tab, notifications page with unread badge, overview narrative and warnings, CLI commands, docs/cognition.md.
This commit is contained in:
@@ -19,6 +19,20 @@ type CognitiveConfig struct {
|
||||
WorkingMemoryDecay float64 `json:"working_memory_decay"` // activation multiplier per cycle
|
||||
LoopDetectWindow int `json:"loop_detect_window"`
|
||||
LoopDetectThreshold int `json:"loop_detect_threshold"`
|
||||
|
||||
// Background cognition (spec §9, §18, §39). Each subsystem has a switch,
|
||||
// a schedule and a model-call budget so idle minds cannot spend freely.
|
||||
ConsolidationEnabled bool `json:"consolidation_enabled"`
|
||||
ConsolidationInterval Duration `json:"consolidation_interval"`
|
||||
ConsolidationMinEpisodes int `json:"consolidation_min_episodes"`
|
||||
ConsolidationLLMCalls int `json:"consolidation_llm_calls"`
|
||||
ReflectionEnabled bool `json:"reflection_enabled"`
|
||||
ReflectionInterval Duration `json:"reflection_interval"`
|
||||
ReflectionLLMCalls int `json:"reflection_llm_calls"`
|
||||
NarrativeLLM bool `json:"narrative_llm"`
|
||||
NotifyMinConfidence float64 `json:"notify_min_confidence"`
|
||||
NotifyMinSalience float64 `json:"notify_min_salience"`
|
||||
NotifyCooldown Duration `json:"notify_cooldown"`
|
||||
}
|
||||
|
||||
// AttentionFeatures is the fixed set of scoring features (spec §6). Weights are
|
||||
@@ -31,7 +45,10 @@ func DefaultConfig() CognitiveConfig {
|
||||
"consequence": 0.9, "confidence": 0.4, "contradiction": 1.0, "operator_priority": 1.5, "context_relevance": 0.9}
|
||||
return CognitiveConfig{WorkspaceCapacity: 7, WorkingMemoryCapacity: 9, AttentionWeights: w,
|
||||
CycleMinInterval: Duration(500 * time.Millisecond), IdleCycleInterval: Duration(60 * time.Second), MaxCyclesPerMinute: 60,
|
||||
LLMCallsPerCycle: 3, DailyTokenBudget: 500_000, WorkingMemoryDecay: 0.85, LoopDetectWindow: 20, LoopDetectThreshold: 5}
|
||||
LLMCallsPerCycle: 3, DailyTokenBudget: 500_000, WorkingMemoryDecay: 0.85, LoopDetectWindow: 20, LoopDetectThreshold: 5,
|
||||
ConsolidationEnabled: true, ConsolidationInterval: Duration(6 * time.Hour), ConsolidationMinEpisodes: 3, ConsolidationLLMCalls: 5,
|
||||
ReflectionEnabled: true, ReflectionInterval: Duration(12 * time.Hour), ReflectionLLMCalls: 2, NarrativeLLM: false,
|
||||
NotifyMinConfidence: 0.85, NotifyMinSalience: 0.7, NotifyCooldown: Duration(time.Hour)}
|
||||
}
|
||||
|
||||
// Normalise fills gaps from defaults and clamps ranges.
|
||||
@@ -81,6 +98,30 @@ func (c *CognitiveConfig) Normalise() {
|
||||
if c.LoopDetectThreshold < 2 {
|
||||
c.LoopDetectThreshold = d.LoopDetectThreshold
|
||||
}
|
||||
if c.ConsolidationInterval < Duration(10*time.Minute) {
|
||||
c.ConsolidationInterval = d.ConsolidationInterval
|
||||
}
|
||||
if c.ConsolidationMinEpisodes < 2 {
|
||||
c.ConsolidationMinEpisodes = d.ConsolidationMinEpisodes
|
||||
}
|
||||
if c.ConsolidationLLMCalls < 0 || c.ConsolidationLLMCalls > 50 {
|
||||
c.ConsolidationLLMCalls = d.ConsolidationLLMCalls
|
||||
}
|
||||
if c.ReflectionInterval < Duration(10*time.Minute) {
|
||||
c.ReflectionInterval = d.ReflectionInterval
|
||||
}
|
||||
if c.ReflectionLLMCalls < 0 || c.ReflectionLLMCalls > 20 {
|
||||
c.ReflectionLLMCalls = d.ReflectionLLMCalls
|
||||
}
|
||||
if c.NotifyMinConfidence <= 0 || c.NotifyMinConfidence > 1 {
|
||||
c.NotifyMinConfidence = d.NotifyMinConfidence
|
||||
}
|
||||
if c.NotifyMinSalience <= 0 || c.NotifyMinSalience > 1 {
|
||||
c.NotifyMinSalience = d.NotifyMinSalience
|
||||
}
|
||||
if c.NotifyCooldown < Duration(time.Minute) {
|
||||
c.NotifyCooldown = d.NotifyCooldown
|
||||
}
|
||||
}
|
||||
|
||||
func contains(xs []string, x string) bool {
|
||||
|
||||
Reference in New Issue
Block a user