The Sovereign Intelligence Stack: Building Compounding AI Infrastructure
Building a 5-layer architecture where every AI decision compounds into the next layer. The recipe compiler, signal router, autonomous evaluation loop, and more — with working code.
Daniel Kliewer
Author, Sovereign AI

From the Book
This is from Sovereign AI: An Architectural Investigation into Local-First Intelligence.

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.
text1Layer 1: Recipe Compiler → Captures AI decisions (immutable records)2Layer 2: Signal Router → Routes tasks to appropriate evaluation paths3Layer 3: Evaluation Loop → Autonomous self-improvement with drift detection4Layer 4: Knowledge Systems → GraphRAG + Persistent Memory5Layer 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:
| Tool | Stars | Significance |
|---|---|---|
| Context Engineering | 13.5K | Systematic replacement for vibe coding |
| Agent Harnesses (ECC/Superpowers) | 225K+244K | The operating system layer for agents |
| Persistent Memory (Claude Mem) | 85K | Stateful agent collaboration |
| Multi-Agent Orchestration (CrewAI) | 55K | Collaborative intelligence |
| Spec-Driven Development | 117K | Structured specifications |
| GraphRAG (Microsoft) | 70K+ | Knowledge graph retrieval |
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:
python1@dataclass2class Recipe:3 """Immutable AI decision record."""45 # Objective - what was the task?6 objective: str78 # Core identity9 id: str = field(default_factory=lambda:10 f"recipe-{datetime.now().strftime('%Y%m%d-%H%M%S')}-{uuid.uuid4().hex[:8]}")11 model_name: str12 memory_context: str13 prompt_version: int = 114 prompt_text: str15 reasoning_patterns: list = field(default_factory=list)16 evaluation_method: str17 evaluation_score: float = 0.018 outcome: str19 outcome_details: str = ""20 created_at: datetime = field(default_factory=datetime.now)21 tags: list = field(default_factory=list)22 metadata: dict = field(default_factory=dict)
The storage layer uses SQLite with FTS5 (full-text search) for performance:
python1class SchemaManager:2 def __init__(self, db_path: str):3 self.db_path = db_path4 self.init_schema()56 def init_schema(self):7 with self.get_connection() as conn:8 conn.executescript("""9 CREATE TABLE IF NOT EXISTS recipes (10 id TEXT PRIMARY KEY,11 objective TEXT NOT NULL,12 model_name TEXT NOT NULL,13 memory_context TEXT,14 prompt_version INTEGER DEFAULT 1,15 prompt_text TEXT NOT NULL,16 reasoning_patterns TEXT,17 evaluation_method TEXT,18 evaluation_score REAL DEFAULT 0.0,19 outcome TEXT NOT NULL,20 outcome_details TEXT,21 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,22 tags TEXT,23 metadata TEXT24 );2526 -- Full-text search index27 CREATE VIRTUAL TABLE recipes_fts USING fts5(28 objective, prompt_text, outcome,29 content='recipes', content_rowid='id'30 );31 """)
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:
- Local-first — No external dependencies. Runs on your machine, offline, forever.
- FTS5 is fast — Full-text search at query time, not build time.
- 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:
| Signal Type | Complexity | Evaluation |
|---|---|---|
| Cheap | Low | Direct comparison (exact match) |
| Expert | High | Multi-criteria evaluation |
| Hybrid | Medium | Cheap first, expert if fails |
python1@dataclass2class SignalClassification:3 """Classification of a signal as cheap/expert/hybrid."""4 signal_id: str5 classification: str # "cheap", "expert", "hybrid"6 reasoning: str7 confidence: float8 suggested_path: str
The router doesn't just classify — it routes. Each classification maps to an evaluation path:
python1class SignalRouter:2 def __init__(self):3 self.classifier = SignalClassifier()4 self.evaluation_paths = {5 "cheap": [self._cheap_path],6 "expert": [self._expert_path],7 "hybrid": [self._cheap_path, self._expert_path]8 }910 def route(self, signal: SignalDefinition) -> RoutingDecision:11 """Route a signal to the appropriate evaluation path."""12 classification = self.classifier.classify(signal)1314 path = self.evaluation_paths[classification.classification]15 results = []1617 for evaluator in path:18 result = evaluator(signal)19 results.append(result)2021 # For hybrid: stop if cheap succeeds22 if classification.classification == "hybrid" and result.success:23 break2425 return RoutingDecision(26 signal=signal,27 classification=classification,28 path=path,29 results=results30 )
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
python1class SignalRegistry:2 """Central registry for all evaluation signals."""34 def __init__(self):5 self._signals = {}67 def register(self, signal: EvaluationSignal):8 """Register a new signal definition."""9 self._signals[signal.name] = signal10 self._validate_signal(signal)1112 def get(self, name: str) -> Optional[EvaluationSignal]:13 return self._signals.get(name)1415 def get_all(self) -> List[EvaluationSignal]:16 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:
python1class SignalDrifter:2 """Detects when evaluation signals have drifted."""34 def __init__(self):5 self.history = [] # Historical signal definitions67 def add_signal(self, signal: EvaluationSignal):8 """Add a new signal definition to history."""9 self.history.append(signal)10 self._check_for_drift(signal)1112 def _check_for_drift(self, new_signal: EvaluationSignal):13 """Check if the new signal has drifted from the previous version."""14 if len(self.history) > 0:15 prev = self.history[-1]16 drift_detected = False1718 # Check for changes in validation criteria19 if prev.validation_criteria != new_signal.validation_criteria:20 drift_detected = True2122 # Check for changes in expected results23 if prev.expected_results != new_signal.expected_results:24 drift_detected = True2526 if drift_detected:27 self._log_drift(new_signal)
Autonomous Loop
The loop runs continuously:
python1class EvaluationLoop:2 """Autonomous evaluation loop that generates and evaluates signals."""34 def __init__(self, config: EvaluationLoopConfig):5 self.config = config6 self.generator = TestCaseGenerator()7 self.drifter = SignalDrifter()8 self._running = False9 self._iteration = 01011 async def run(self):12 """Run the autonomous evaluation loop."""13 self._running = True14 while self._running:15 self._iteration += 11617 # Generate new test cases18 test_cases = self.generator.generate(19 self.config.signal_names,20 count=self.config.test_count21 )2223 # Evaluate against existing recipes24 results = await self._evaluate_test_cases(test_cases)2526 # Update signal definitions based on results27 self.drifter.add_signal(results)2829 # Log progress30 self._log_progress()3132 # Wait before next iteration33 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."
python1class GraphRAG:2 """Hybrid retrieval combining vector and graph search."""34 def __init__(self, vector_store: VectorStore, graph: KnowledgeGraph):5 self.vector_store = vector_store6 self.graph = graph7 self._alpha = 0.5 # Weight for vector vs graph results89 def retrieve(self, query: str, top_k: int = 10) -> GraphRAGResult:10 """Perform hybrid retrieval."""11 # Vector search12 vector_results = self.vector_store.search(query, top_k=top_k)1314 # Graph search15 graph_results = self._graph_search(query, top_k=top_k)1617 # Combine results18 combined = self._combine_results(vector_results, graph_results)1920 return GraphRAGResult(21 query=query,22 vector_results=vector_results,23 graph_results=graph_results,24 combined_results=combined,25 retrieval_time_ms=combined["retrieval_time_ms"]26 )
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.
python1class MemoryStorage:2 """Persistent memory storage with pruning."""34 def __init__(self, db_path: str):5 self.db_path = db_path6 self.init_schema()78 def add_memory(self, content: str, project_id: str,9 relevance_score: float = 0.5) -> MemoryEntry:10 """Add a memory entry with relevance scoring."""11 entry = MemoryEntry(12 id=f"mem-{datetime.now().strftime('%Y%m%d-%H%M%S')}-{uuid.uuid4().hex[:8]}",13 content=content,14 project_id=project_id,15 relevance_score=relevance_score,16 created_at=datetime.now(),17 last_accessed=datetime.now()18 )19 self._store_memory(entry)20 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
python1class IntelligenceTimeline:2 """Generates intelligence timelines from recipe data."""34 def __init__(self, recipe_store: RecipeStorage):5 self.recipe_store = recipe_store67 def generate(self, project_id: str,8 start_date: datetime,9 end_date: datetime) -> dict:10 """Generate an intelligence timeline."""11 recipes = self.recipe_store.get_by_project(12 project_id, start_date, end_date13 )1415 timeline = {16 "project_id": project_id,17 "period": f"{start_date} to {end_date}",18 "total_recipes": len(recipes),19 "models_used": self._extract_models(recipes),20 "avg_quality": self._calculate_avg_quality(recipes),21 "quality_trend": self._calculate_quality_trend(recipes),22 "prompts_used": self._extract_prompts(recipes),23 "prompts_improved": self._detect_prompt_improvements(recipes),24 "errors_detected": self._detect_errors(recipes)25 }2627 return timeline
Pattern Detection
python1class PatternDetector:2 """Detects patterns in intelligence data."""34 def detect_prompt_optimization(self, recipes: List[Recipe]) -> dict:5 """Detect prompt optimization patterns."""6 patterns = {}78 # Group by prompt version9 by_version = self._group_by_version(recipes)1011 for version, version_recipes in by_version.items():12 avg_quality = self._calculate_avg_quality(version_recipes)1314 if version > 1:15 prev_recipes = by_version.get(version - 1, [])16 if prev_recipes:17 prev_quality = self._calculate_avg_quality(prev_recipes)18 improvement = avg_quality - prev_quality1920 if improvement > 0:21 patterns[f"v{version}"] = {22 "avg_quality": avg_quality,23 "improvement": improvement,24 "recipes": len(version_recipes)25 }2627 return patterns
Putting It All Together: The Compounding Effect
Here's what happens when these layers work together:
- Day 1: You capture a recipe for a simple task. The recipe compiler stores it.
- Day 2: You capture 10 more recipes. The signal router learns to classify tasks.
- Day 3: The evaluation loop generates test cases based on the recipes.
- Day 7: You have 100 recipes. The knowledge graph has 50 nodes and 200 edges.
- Day 14: The observatory shows you that your prompts improved by 15% over two weeks.
- 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:
- Track intelligence evolution — See how your AI system improves over time
- Debug failures — Every failure is a recipe you can investigate
- Optimize prompts — See which prompts work and why
- Self-improve — The evaluation loop generates new ways to evaluate
- Build knowledge — The knowledge graph accumulates over time
- 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?
- Complete the knowledge graph — Integrate with the full 3,468-edge knowledge graph
- Build the observatory dashboard — Next.js frontend for the timeline
- Add the apprenticeship engine — Phased autonomy for agents
- Connect to real LLMs — Ollama integration for local inference
- Measure compounding — Track intelligence growth over time
The foundation is solid. The rest is engineering.
References
- Architecture of Autonomy
- The Model Is Not the Product
- Building Autonomous Sovereign AI
- Context Engineering
- GraphRAG (70K+ stars)
- Agent Harnesses (225K stars)
- Claude Mem (85K stars)
- Context Engineering (13.5K stars)
Related Posts
- Sovereign AI Architecture — Comprehensive synthesis of four years of work
- Getting Started with Sovereign AI — Beginner on-ramp
- Local AI Architecture — Local-first implementation guide
- Retrieval Architecture — Memory and retrieval systems
Related Repositories
- Sovereign Memory Bank — 7-layer autonomous cognitive memory
- Dynamic Persona MoE RAG — Persona-driven mixture-of-experts
- Objective05 — Persistent intelligence infrastructure in Rust
- SovereignSpec — Spec-driven development engine
Building sovereign AI infrastructure that compounds. Intelligence is accumulated decisions, not models.

Sovereign AI: An Architectural Investigation into Local-First Intelligence
by Daniel Kliewer · Paperback · 72 pages
An examination of the architecture of intelligence that you own — from first principles through production deployment.