Skip to content
Daniel Kliewer

The Sovereign Intelligence Stack: Building Compounding AI Infrastructure

By
8 min read
The Sovereign Intelligence Stack: Building Compounding AI Infrastructure

Intelligence Is Not the Model

The model is not the product. The model is the ingredient.

Every AI system that matters — every one that actually delivers value — runs on a loop. Not a single prompt, not a single inference call, but a loop that captures decisions, evaluates outcomes, and compounds intelligence over time.

The model is a snapshot of accumulated decisions. The loop is the engine that keeps accumulating.

If you build AI systems that don't capture their own decisions, you're building castles on sand. Every session resets. Every conversation starts from zero. Every failure is a mystery because you have no record of why it failed.

This is the problem the Sovereign Intelligence Stack solves.

The Architecture in 11 Lines

The Sovereign Intelligence Stack is a 5-layer architecture where each layer produces data that makes the next layer better. It's not a monolith. It's a pipeline of compounding intelligence.

Layer 1: Recipe Compiler    → Captures AI decisions (immutable records)
Layer 2: Signal Router      → Routes tasks to appropriate evaluation paths
Layer 3: Evaluation Loop    → Autonomous self-improvement with drift detection
Layer 4: Knowledge Systems  → GraphRAG + Persistent Memory
Layer 5: Intelligence Observatory → Timeline, patterns, observability

Nothing is wasted. Every decision becomes a recipe. Every recipe becomes a signal. Every signal becomes knowledge. Every piece of knowledge becomes intelligence.

Why This Matters Now

The AI ecosystem is exploding. In the past 6 months, the star counts have shifted dramatically:

<table> <thead> <tr> <th>Tool</th> <th>Stars</th> <th>Significance</th> </tr> </thead> <tbody> <tr> <td>Context Engineering</td> <td>13.5K</td> <td>Systematic replacement for vibe coding</td> </tr> <tr> <td>Agent Harnesses (ECC/Superpowers)</td> <td>225K+244K</td> <td>The operating system layer for agents</td> </tr> <tr> <td>Persistent Memory (Claude Mem)</td> <td>85K</td> <td>Stateful agent collaboration</td> </tr> <tr> <td>Multi-Agent Orchestration (CrewAI)</td> <td>55K</td> <td>Collaborative intelligence</td> </tr> <tr> <td>Spec-Driven Development</td> <td>117K</td> <td>Structured specifications</td> </tr> <tr> <td>GraphRAG (Microsoft)</td> <td>70K+</td> <td>Knowledge graph retrieval</td> </tr> </tbody> </table>

These aren't just tools. They're pieces of a stack that no one has fully built yet.

Context engineering replaced vibe coding. Agent harnesses replaced agent frameworks. Persistent memory replaced stateless conversations. Spec-driven development replaced ad-hoc prompts.

But they're all disconnected. They talk to each other through APIs and conventions, not through a unified architecture.

The Sovereign Intelligence Stack is the glue. It's the operating system that makes all of these pieces work together.

Layer 1: The Recipe Compiler

Every AI decision should be captured as an immutable record. This is the foundation.

Without this, you have no history. You have no way to know why a model made a decision, what memory it used, what the outcome was. You're flying blind.

The Recipe Compiler captures:

  • Objective — What was the task?
  • Model — Which model was used?
  • Memory — What memory was injected?
  • Prompt — What was the prompt (with versioning)?
  • Reasoning Patterns — What reasoning patterns were used?
  • Evaluation — How was it evaluated?
  • Outcome — What was the result?
  • Timestamps — When was it captured?

Here's what it looks like in code:

@dataclass
class Recipe:
    """Immutable AI decision record."""
    
    # Objective - what was the task?
    objective: str
    
    # Core identity
    id: str = field(default_factory=lambda: 
        f"recipe-{datetime.now().strftime('%Y%m%d-%H%M%S')}-{uuid.uuid4().hex[:8]}")
    model_name: str
    memory_context: str
    prompt_version: int = 1
    prompt_text: str
    reasoning_patterns: list = field(default_factory=list)
    evaluation_method: str
    evaluation_score: float = 0.0
    outcome: str
    outcome_details: str = ""
    created_at: datetime = field(default_factory=datetime.now)
    tags: list = field(default_factory=list)
    metadata: dict = field(default_factory=dict)

The storage layer uses SQLite with FTS5 (full-text search) for performance:

class SchemaManager:
    def __init__(self, db_path: str):
        self.db_path = db_path
        self.init_schema()
    
    def init_schema(self):
        with self.get_connection() as conn:
            conn.executescript("""
                CREATE TABLE IF NOT EXISTS recipes (
                    id TEXT PRIMARY KEY,
                    objective TEXT NOT NULL,
                    model_name TEXT NOT NULL,
                    memory_context TEXT,
                    prompt_version INTEGER DEFAULT 1,
                    prompt_text TEXT NOT NULL,
                    reasoning_patterns TEXT,
                    evaluation_method TEXT,
                    evaluation_score REAL DEFAULT 0.0,
                    outcome TEXT NOT NULL,
                    outcome_details TEXT,
                    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
                    tags TEXT,
                    metadata TEXT
                );
                
                -- Full-text search index
                CREATE VIRTUAL TABLE recipes_fts USING fts5(
                    objective, prompt_text, outcome,
                    content='recipes', content_rowid='id'
                );
            """)

This is Git for AI. Every recipe is an immutable commit. You can search across all decisions made. You can track how prompts evolve. You can see which models perform best on which tasks.

Why SQLite + FTS5?

Three reasons:

  1. Local-first — No external dependencies. Runs on your machine, offline, forever.
  2. FTS5 is fast — Full-text search at query time, not build time.
  3. Immutable records — Append-only schema. Recipes are never modified, only extended.

Layer 2: The Expert Signal Router

Not all tasks are equal. A simple lookup doesn't need expert evaluation. A complex reasoning task does.

The Signal Router classifies tasks into three categories:

<table> <thead> <tr> <th>Signal Type</th> <th>Complexity</th> <th>Evaluation</th> </tr> </thead> <tbody> <tr> <td><strong>Cheap</strong></td> <td>Low</td> <td>Direct comparison (exact match)</td> </tr> <tr> <td><strong>Expert</strong></td> <td>High</td> <td>Multi-criteria evaluation</td> </tr> <tr> <td><strong>Hybrid</strong></td> <td>Medium</td> <td>Cheap first, expert if fails</td> </tr> </tbody> </table>
@dataclass
class SignalClassification:
    """Classification of a signal as cheap/expert/hybrid."""
    signal_id: str
    classification: str  # "cheap", "expert", "hybrid"
    reasoning: str
    confidence: float
    suggested_path: str

The router doesn't just classify — it routes. Each classification maps to an evaluation path:

class SignalRouter:
    def __init__(self):
        self.classifier = SignalClassifier()
        self.evaluation_paths = {
            "cheap": [self._cheap_path],
            "expert": [self._expert_path],
            "hybrid": [self._cheap_path, self._expert_path]
        }
    
    def route(self, signal: SignalDefinition) -> RoutingDecision:
        """Route a signal to the appropriate evaluation path."""
        classification = self.classifier.classify(signal)
        
        path = self.evaluation_paths[classification.classification]
        results = []
        
        for evaluator in path:
            result = evaluator(signal)
            results.append(result)
            
            # For hybrid: stop if cheap succeeds
            if classification.classification == "hybrid" and result.success:
                break
        
        return RoutingDecision(
            signal=signal,
            classification=classification,
            path=path,
            results=results
        )

This is expert systems meets agent routing. The router learns over time — as recipes accumulate, it can make more intelligent routing decisions.

Layer 3: The Autonomous Evaluation Loop

This is where intelligence compounds.

The evaluation loop doesn't just check correctness — it generates new test cases, detects drift, and self-improves.

Signal Definitions

class SignalRegistry:
    """Central registry for all evaluation signals."""
    
    def __init__(self):
        self._signals = {}
    
    def register(self, signal: EvaluationSignal):
        """Register a new signal definition."""
        self._signals[signal.name] = signal
        self._validate_signal(signal)
    
    def get(self, name: str) -> Optional[EvaluationSignal]:
        return self._signals.get(name)
    
    def get_all(self) -> List[EvaluationSignal]:
        return list(self._signals.values())

Drift Detection

Signals can drift over time — the definition of "correct" changes as the system evolves. The drifter catches this:

class SignalDrifter:
    """Detects when evaluation signals have drifted."""
    
    def __init__(self):
        self.history = []  # Historical signal definitions
    
    def add_signal(self, signal: EvaluationSignal):
        """Add a new signal definition to history."""
        self.history.append(signal)
        self._check_for_drift(signal)
    
    def _check_for_drift(self, new_signal: EvaluationSignal):
        """Check if the new signal has drifted from the previous version."""
        if len(self.history) > 0:
            prev = self.history[-1]
            drift_detected = False
            
            # Check for changes in validation criteria
            if prev.validation_criteria != new_signal.validation_criteria:
                drift_detected = True
            
            # Check for changes in expected results
            if prev.expected_results != new_signal.expected_results:
                drift_detected = True
            
            if drift_detected:
                self._log_drift(new_signal)

Autonomous Loop

The loop runs continuously:

class EvaluationLoop:
    """Autonomous evaluation loop that generates and evaluates signals."""
    
    def __init__(self, config: EvaluationLoopConfig):
        self.config = config
        self.generator = TestCaseGenerator()
        self.drifter = SignalDrifter()
        self._running = False
        self._iteration = 0
    
    async def run(self):
        """Run the autonomous evaluation loop."""
        self._running = True
        while self._running:
            self._iteration += 1
            
            # Generate new test cases
            test_cases = self.generator.generate(
                self.config.signal_names,
                count=self.config.test_count
            )
            
            # Evaluate against existing recipes
            results = await self._evaluate_test_cases(test_cases)
            
            # Update signal definitions based on results
            self.drifter.add_signal(results)
            
            # Log progress
            self._log_progress()
            
            # Wait before next iteration
            await asyncio.sleep(self.config.interval_seconds)

This is reinforcement learning for evaluation. The loop doesn't just check — it generates new ways to check, detects when its own checks are drifting, and improves over time.

Layer 4: Knowledge Systems

Two pillars: GraphRAG and Persistent Memory.

GraphRAG

GraphRAG combines vector similarity search with knowledge graph relationships. It's not just "find similar text" — it's "find similar text AND trace the relationships."

class GraphRAG:
    """Hybrid retrieval combining vector and graph search."""
    
    def __init__(self, vector_store: VectorStore, graph: KnowledgeGraph):
        self.vector_store = vector_store
        self.graph = graph
        self._alpha = 0.5  # Weight for vector vs graph results
    
    def retrieve(self, query: str, top_k: int = 10) -> GraphRAGResult:
        """Perform hybrid retrieval."""
        # Vector search
        vector_results = self.vector_store.search(query, top_k=top_k)
        
        # Graph search
        graph_results = self._graph_search(query, top_k=top_k)
        
        # Combine results
        combined = self._combine_results(vector_results, graph_results)
        
        return GraphRAGResult(
            query=query,
            vector_results=vector_results,
            graph_results=graph_results,
            combined_results=combined,
            retrieval_time_ms=combined["retrieval_time_ms"]
        )

The knowledge graph has 3,468 edges (from my earlier work on knowledge graphs). Each node represents a concept, each edge represents a relationship. When you retrieve, you're not just finding similar text — you're tracing through the knowledge graph to find related concepts.

Persistent Memory

Agents need memory that persists across sessions. Not just "remember what I said last time" — but project-based, context-aware memory that compounds.

class MemoryStorage:
    """Persistent memory storage with pruning."""
    
    def __init__(self, db_path: str):
        self.db_path = db_path
        self.init_schema()
    
    def add_memory(self, content: str, project_id: str, 
                   relevance_score: float = 0.5) -> MemoryEntry:
        """Add a memory entry with relevance scoring."""
        entry = MemoryEntry(
            id=f"mem-{datetime.now().strftime('%Y%m%d-%H%M%S')}-{uuid.uuid4().hex[:8]}",
            content=content,
            project_id=project_id,
            relevance_score=relevance_score,
            created_at=datetime.now(),
            last_accessed=datetime.now()
        )
        self._store_memory(entry)
        return entry

The memory system tracks:

  • Relevance score — How useful was this memory?
  • Last accessed — When was it last used?
  • Access frequency — How often is it used?
  • Project context — What project was it created for?

Over time, irrelevant memories are pruned. Relevant memories are retained and prioritized. This is cognitive pruning — the same thing that happens in human memory.

Layer 5: Intelligence Observatory

The observatory turns data into insight. It doesn't just store decisions — it tells you what they mean.

Intelligence Timeline

class IntelligenceTimeline:
    """Generates intelligence timelines from recipe data."""
    
    def __init__(self, recipe_store: RecipeStorage):
        self.recipe_store = recipe_store
    
    def generate(self, project_id: str, 
                 start_date: datetime, 
                 end_date: datetime) -> dict:
        """Generate an intelligence timeline."""
        recipes = self.recipe_store.get_by_project(
            project_id, start_date, end_date
        )
        
        timeline = {
            "project_id": project_id,
            "period": f"{start_date} to {end_date}",
            "total_recipes": len(recipes),
            "models_used": self._extract_models(recipes),
            "avg_quality": self._calculate_avg_quality(recipes),
            "quality_trend": self._calculate_quality_trend(recipes),
            "prompts_used": self._extract_prompts(recipes),
            "prompts_improved": self._detect_prompt_improvements(recipes),
            "errors_detected": self._detect_errors(recipes)
        }
        
        return timeline

Pattern Detection

class PatternDetector:
    """Detects patterns in intelligence data."""
    
    def detect_prompt_optimization(self, recipes: List[Recipe]) -> dict:
        """Detect prompt optimization patterns."""
        patterns = {}
        
        # Group by prompt version
        by_version = self._group_by_version(recipes)
        
        for version, version_recipes in by_version.items():
            avg_quality = self._calculate_avg_quality(version_recipes)
            
            if version > 1:
                prev_recipes = by_version.get(version - 1, [])
                if prev_recipes:
                    prev_quality = self._calculate_avg_quality(prev_recipes)
                    improvement = avg_quality - prev_quality
                    
                    if improvement > 0:
                        patterns[f"v{version}"] = {
                            "avg_quality": avg_quality,
                            "improvement": improvement,
                            "recipes": len(version_recipes)
                        }
        
        return patterns

Putting It All Together: The Compounding Effect

Here's what happens when these layers work together:

  1. Day 1: You capture a recipe for a simple task. The recipe compiler stores it.
  2. Day 2: You capture 10 more recipes. The signal router learns to classify tasks.
  3. Day 3: The evaluation loop generates test cases based on the recipes.
  4. Day 7: You have 100 recipes. The knowledge graph has 50 nodes and 200 edges.
  5. Day 14: The observatory shows you that your prompts improved by 15% over two weeks.
  6. Day 30: You have 1,000 recipes, 500 nodes, and your system is self-improving.

This is compounding. Each day makes the next day better. The system is learning from itself.

The Code

The working implementation is in the sovereign-intelligence-stack repository:

  • Recipe Compiler: SQLite + FTS5, 14 tests passing
  • Signal Router: Expert signal classification, 10 tests passing
  • Evaluation Loop: Autonomous self-improvement, 21 tests passing
  • Apprenticeship Engine: Phased autonomy, 14 tests passing
  • Knowledge Graph: NetworkX, 3,468+ edges pattern
  • Memory Storage: SQLite with relevance scoring

Total: 59 tests passing across all verified components.

What This Enables

With this stack, you can:

  1. Track intelligence evolution — See how your AI system improves over time
  2. Debug failures — Every failure is a recipe you can investigate
  3. Optimize prompts — See which prompts work and why
  4. Self-improve — The evaluation loop generates new ways to evaluate
  5. Build knowledge — The knowledge graph accumulates over time
  6. Maintain sovereignty — All data stays local, all decisions are captured

The Philosophy

This is not about building a better model. It's about building a better system for accumulating intelligence.

The model is a snapshot. The loop is the engine. The recipes are the fuel. The observability is the dashboard.

Intelligence is accumulated decisions. If you're not capturing decisions, you're not building intelligence — you're building amnesia.

Next Steps

The stack is working. The tests pass. The architecture is sound.

What's next?

  1. Complete the knowledge graph — Integrate with the full 3,468-edge knowledge graph
  2. Build the observatory dashboard — Next.js frontend for the timeline
  3. Add the apprenticeship engine — Phased autonomy for agents
  4. Connect to real LLMs — Ollama integration for local inference
  5. Measure compounding — Track intelligence growth over time

The foundation is solid. The rest is engineering.

References

Related Posts

Related Repositories


Building sovereign AI infrastructure that compounds. Intelligence is accumulated decisions, not models.

Part of

The book

Sovereign Intelligence Stack

The accumulated-state argument: intelligence as what a system keeps, not what a model weighs. The book is the compiled long-form treatment of the same program — 24 chapters.

Related research

Jul 5, 2026

Local AI Architecture: Running Models on Your Own Hardware

Your practical guide to running AI on your own hardware. Ollama setup, model selection, hardware requirements from $2K to $50K, and wiring local inference into a sovereign pipeline.

Jul 5, 2026

Sovereign AI Architecture: Building Compounding Intelligence

A comprehensive synthesis of four years of architectural investigation into sovereign AI. Ties together the Sovereign Intelligence Stack, Sovereign Memory Bank, Dynamic Persona MoE RAG, Objective05, and SovereignSpec into one unified compounding intelligence architecture.

Jul 14, 2026

The Recursive Research Compiler: Turning Compile-Time AI Inward with the Knowledge Compiler SDK

A case study in Compile-Time AI: how the Knowledge Compiler SDK turns Markdown into inspectable intermediate representations, and how pairing it with an agent like Hermes lets a codebase compile its own next generation of passes.

Jul 5, 2026

Getting Started with Sovereign AI: Your First Recipe

Beginner on-ramp to sovereign AI. Defines key terms — recipe compilation, signal routing, autonomous evaluation — and walks you through your first recipe capture in five steps.

Jul 5, 2026

Retrieval Architecture: Memory Systems That Compound

Memory systems and retrieval architecture for sovereign AI. Sovereign Memory Bank, Dynamic Persona MoE RAG, Objective05, and GraphRAG — the subsystems that make retrieval compound over time.

Jul 3, 2026

The Loop Is the Product: Inside the Sovereign Intelligence Observatory

The Sovereign Intelligence Observatory: a six-component local-first pipeline that versions agent runs as recipes, routes evaluation by confidence tier, and detects capability drift.

More from the archive