Skip to content

Cognitive (Camada 18)

The biological metaphor: hippocampal consolidation, mirror neurons, intuition, myelination.

MirrorLearner

Observe successful traces; infer reusable patterns once min_traces is reached (contextual per profile).

from src.cognitive import MirrorLearner, MirrorObservation

ml = MirrorLearner(min_traces=50)
for trace in finished_traces:
    ml.observe(MirrorObservation(
        trace_id=trace.id,
        intent_class=trace.intent,
        skill_chain=trace.skill_chain,
        success=trace.success,
        duration_ms=trace.duration_ms,
    ))

patterns = ml.infer_patterns(min_success_rate=0.85)
for p in patterns:
    print(f"{p.intent_class}: {p.skill_chain} (sr={p.success_rate}, n={p.occurrences})")

A pattern needs ≥3 occurrences (or min_traces // 10, whichever is higher) and a success rate above the threshold.

SleepConsolidator

When melatonin is high (>0.6) or during idle windows, run consolidate():

from src.cognitive import SleepConsolidator
from src.ai import EpisodicStore, SemanticStore

sc = SleepConsolidator(
    episodic=EpisodicStore(),
    semantic=SemanticStore(),
    min_occurrences=3,
)
report = sc.consolidate()
# Frequently-recurring episodic motifs are promoted to semantic store
# Tagged with `consolidated`. Skipped if already present in semantic.

IntuitionEngine

Fast pattern match BEFORE invoking the deliberative pipeline. If a high-confidence inferred pattern matches the intent, suggest its skill chain directly.

from src.cognitive import IntuitionEngine

ie = IntuitionEngine(min_confidence=0.85)
ie.update_patterns(patterns)
match = ie.suggest("build_feature")
if match:
    print(f"Shortcut available: {match.skill_chain} (conf={match.confidence})")

Confidence = success_rate × sample_weight where sample_weight = min(1.0, occurrences / 50). Below 0.85 → fall through to the full pipeline.

MyelinationCache

Tracks per-skill usage so the router can favor frequently-used paths. Strength follows a logistic curve:

strength(c) = 1 / (1 + exp(-(c - 20) / 15))   # saturates around 1.0 at ~100 uses
from src.cognitive import MyelinationCache

mc = MyelinationCache()
for _ in range(30):
    mc.record_use("code-writer")

ranked = mc.ranked(["code-writer", "git-worker", "unused"])
for r in ranked:
    print(f"{r.strength:.3f}  {r.skill_id}  (uses={r.usage_count})")

decay() is called nightly (by SleepConsolidator); multiplies all usage by (1 - decay_per_day) so unused paths shed strength over time.

Cross-camada feedback loop

trace → MirrorLearner ──┐
                        ├──→ IntuitionEngine (suggests skill_chain)
patterns ───────────────┘            │
            SkillRouter ◀── MyelinationCache (strength)
            ▼                        │
       SkillInvoker ────── trace ────┘
                          (loop closes)

Together these four make the system learn from its own work without retraining a model. The trade-off: patterns are heuristic — they don't replace the deliberative pipeline, they just give it a hint when one is clearly available.