StackComponentProtocol — Cross-Cutting Concerns
Stack components are the stack’s equivalent of plugins. They extend what the stack can do by hooking into its lifecycle: memory saves, searches, loads, and periodic maintenance. Think of them as middleware for memory operations. When a memory is saved, every component gets notified. When search results come back, every component can re-rank them. When maintenance runs, every component does its background work.StackComponentProtocol Interface
Properties
| Property | Type | Purpose |
|---|---|---|
name | str | Unique identifier for registry lookup |
version | str | Semantic version string |
required | bool | If True, stack refuses to operate without it |
needs_inference | bool | If True, uses InferenceService when available |
Hook Dispatch
The stack calls component hooks at four points in its lifecycle:on_save
Called after a memory is saved. Can modify the memory by returning a modified version (returnNone to leave unchanged).
Used by:
- EmotionalTagging: Detects valence/arousal, adds emotional metadata
- MetaMemory: Initializes confidence tracking
- Embedding: Generates and stores vector representation
on_search
Called after search results are assembled. Returns the (possibly modified) results list. Components can re-rank, filter, or augment results. Used by:- Forgetting: Could filter out low-salience results
- EmotionalTagging: Could boost emotionally relevant results
on_load
Called duringload() working memory assembly. Components contribute to the context dict by mutating it directly.
Used by:
- Anxiety: Adds current anxiety levels and dimension scores
- Forgetting: Adds forgetting statistics
on_maintenance
Called during periodic maintenance. Each component does background work and returns a stats dict. The stack combines all stats keyed by component name. Used by:- Forgetting: Runs salience decay sweeps, soft-deletes low-salience memories
- Consolidation: Detects cross-domain patterns in episodes
- Suggestions: Scans raw entries for potential episodes/beliefs/notes
- MetaMemory: Applies confidence decay to stale memories
- Knowledge: Analyzes domain coverage and knowledge gaps
Error Isolation
Component failures never crash stack operations. If a component’s hook throws an exception, the stack logs the error and continues with the remaining components. This isolation means:- A buggy emotional tagger won’t prevent memory saves
- A failing embedding component won’t break search (results just won’t have embeddings)
- One component crashing during maintenance won’t prevent others from running
The 8 Default Components
SQLiteStack auto-loads all 8 built-in components on initialization. Passcomponents=[] for a bare stack, or an explicit list for custom configuration.
| Component | Name | Required | Needs Inference | Purpose |
|---|---|---|---|---|
| EmbeddingComponent | embedding-ngram | Yes | No | Vector embeddings for semantic search. Uses local hash embedder by default, delegates to InferenceService.embed() when available. |
| ForgettingComponent | forgetting | No | No | Salience-based memory decay. Calculates salience from confidence, access count, and age. Soft-deletes low-salience memories during maintenance. Protected memories are never forgotten. |
| ConsolidationComponent | consolidation | No | Yes | Cross-domain pattern detection across episodes. Identifies common lessons, finds structural similarities across domains. With inference, can synthesize episodes into beliefs. |
| EmotionalTaggingComponent | emotions | No | Yes | Automatic emotion detection from text. Tags memories with valence/arousal scores. Uses inference for emotional analysis; returns neutral defaults when no model is bound. |
| AnxietyComponent | anxiety | No | No | Memory health monitoring. Measures anxiety across dimensions: consolidation debt, raw aging, identity coherence, memory uncertainty, epoch staleness. Contributes anxiety levels to working memory. |
| SuggestionComponent | suggestions | No | Yes | Suggestion extraction from raw entries. Classifies raw captures into potential episodes, beliefs, and notes using inference. Returns empty results when no model is bound. Generates MemorySuggestion records for review. |
| MetaMemoryComponent | metamemory | No | No | Confidence tracking and time-based decay. Monitors confidence over time, applies decay to unverified memories, surfaces uncertain memories for review. |
| KnowledgeComponent | knowledge | No | Yes | Knowledge domain mapping. Analyzes beliefs, episodes, and notes to map competence boundaries and detect knowledge gaps. With inference, generates richer domain analysis. |
Component Configuration
Entry Point Registration
Stack components register in thekernle.stack_components entry point group:
Building a Custom Component
To create a custom stack component, implement theStackComponentProtocol: