KAE SYSTEM ARCHITECTURE

Six layers from file system events to continuous self-improvement — tap any layer to expand

1
FILE SYSTEM WATCHER
Event source — monitors Systems/**/*.md in real time
INPUT
tap ▾
file-watcher.js
chokidar, 400ms stability, 2s debounce
client-watcher.js
Specialized intake file detection
amendment-watcher
Watches for approved GAIA amendments
Events detected: change, add  |  Ignored: Logs/, Health/, .swp, ~tmp
Triggers: File stabilizes → router.route(filePath, content, eventType)
chokidar 4.0
Node.js fs
path.relative()
2
GAIA HEURISTIC NETWORK (GHN)
Routing brain — extracts signals, scores patterns, selects guardians
ROUTING
tap ▾
core.js
Signal extraction + pattern scoring engine
router.js
Dispatches to guardians, writes SQLite events
learning-loop.js
Observes decisions, promotes patterns at 3+ successes
patterns table (kae.db)
Authoritative routing rules (seeded + learned) — live in SQLite, not JSON
Confidence modes: ≥0.80 → AUTONOMOUS (no API), 0.50–0.80 → VERIFY, <0.50 → FULL
Fallback: score <0.30 → route to APOLLO (knowledge preservation)
Registry: guardians/registry.js is the single source of truth feeding both the router and the batch processor
ghn/core.js
ghn/router.js
ghn/learning-loop.js
SQLite events table
3
EVENT QUEUE & BATCH PROCESSOR
Sliding 30s window — deduplicates, batches, and throttles API calls
QUEUE
tap ▾
Strategy A — Latest Wins
Same file + guardian: only process most recent content
Strategy B — Hash Dedup
Same content within 1 hour: skip entirely
Strategy C — Batch
Multiple files → one API call per guardian
batch-processor.js
Cron every 30s: dequeue → group → execute
Max snapshot: 24,000 chars (truncated files get a note)
Batch limit: Up to 3 files per guardian per cycle
Retry: failed batch items retry automatically; after 3 strikes they move to a dead-letter queue (evolution_queue / event_queue in kae.db) instead of blocking the pipeline
node-cron 3.0
SHA-256 content hash
event-queue.js
3-strike dead-letter
4
15 GUARDIAN AGENTS
Specialized AI agents — each owns exactly one business domain, organized across three pillars
EXECUTION
tap ▾
DELIVERY PILLAR
APOLLO
Knowledge preservation — local only
POSEIDON
Data intelligence & pipeline
ELEUTHIA
Client lifecycle (stages 0–4)
HADES
Failsafe & engagement reset
HEPHAESTUS
Digital infrastructure + OGUN three-layer artifacts
ACQUISITION PILLAR
ESHU
Client intake & ICP gates
MINERVA
Systemic constraint mapping
AETHER
Brand narrative & positioning
ARTEMIS
Campaign activation
HERMES
Multi-channel content execution
DEMETER
Process integrity enforcement
OPERATIONS PILLAR
OYA
Finance tracking & cash flow
MAAT
Legal document & contract review
YEMOJA
HR & team management
GAIA
Three-pillar health & meta-orchestration
Note: EVOLUTION is not a 16th guardian — it's a pipeline that reads guardian outputs and drafts instruction-amendment proposals (see Layer 5).
Models: Haiku 4.5 (extraction: APOLLO, MINERVA, POSEIDON, OYA, YEMOJA) | Sonnet 4.6 (judgment: all others) — set per guardian in its guardian.json manifest
LEGBA tools: GAIA, HADES, ELEUTHIA, HERMES, AETHER, DEMETER, ESHU, POSEIDON, MAAT, HEPHAESTUS, ARTEMIS have tool access, called in-process from a shared lib (Systems/Library/LEGBA/lib/tools.js) — no process spawn per tool call
Tool set: get_client, get_brand_style, get_guardian_status, get_apollo_log, invoke_minerva, kuji_render, read_doc, search_ip, tasks_list, patterns_query, perplexity_search, oxylabs_search
Structured output: every guardian responds via a forced emit_result tool call — {status: ok|flag|error, summary, flags[], data} — validated against guardians/<name>/schema.json. No regex parsing of prose. Batch results are keyed by file path.
Manifests: each guardian ships a guardian.json (model, max tokens, tool access) read by guardians/registry.js
OGUN — THREE-LAYER DESIGN SYSTEM
Layer 1 — Components: 30-type registry (tier 1 primitives → tier 3 high-level). kuji registry --list.
Layer 2 — StyleTokens (@style.*): brand character — cornerRadius, elevation, buttonVariant, typeDensity, borderWeight, motionScale. Declared in ogun-config.json → kuji.style per client.
Layer 3 — DesignTokens (@tokens.*): hex colours + font names. Resolved at render time.
Pipeline: *.kuji.json → kuji smell → kuji validate → kuji render → pdf / pptx / html / card-jpg
Web: shadcn MCP for HTML artifact component generation
guardians/base.js
guardians/registry.js
guardian.json manifests
emit_result + schema.json
@anthropic-ai/sdk
Claude Haiku / Sonnet
LEGBA lib (in-process)
5
LEARNING & EVOLUTION ENGINE
Continuously improves routing rules and guardian instructions
LEARNING
tap ▾
GHN Learning Loop
observe() records every occurrence; recordOutcome() records real executed results. 3+ occurrences where every routed guardian has an actual recorded success → new routing rule. Queued-but-never-run work never counts.
Amendment Proposer
Extracts evidence from guardian logs
Batch Submitter
Hourly: sends batches to Claude Message Batch API (50% cost discount)
Batch Poller
Every 10 min: checks for completed amendment suggestions
Amendment Writer
Applies approved changes to instruction .md files
Pattern confidence: success → +0.02 (max 0.98) | failure → −0.05 (min 0.10) — losing hurts more than winning helps, on purpose
Amendment lifecycle: Propose → Human Review → Approved → Applied → Improved
Build ledger: Systems/Library/OGUN/Learning/build-ledger.md — cross-client lessons, Impact: High guards mandatory for HEPHAESTUS
Spec-first: HEPHAESTUS writes engagement spec before any complex build — ambiguities surfaced before a single line of code is written
evolution/
Message Batch API
observations table (kae.db)
patterns table (kae.db)
6
MONITORS, STATE & PERSISTENCE
Health checks, quality scoring, alerts, single SQLite persistence (kae.db)
OBSERVE
tap ▾
health-check.js
Hourly system health scan across all guardians
quality-scorer.js
Measures guardian output quality metrics
amendment-review.js
Daily digest at 05:30 SAST
content-alert.js
Daily content calendar alert at 06:30 SAST
SQLite (kae.db)
patterns, observations, guardian_patterns, guardian_data, run_log, event_queue, evolution_queue, shared tables — the ONE runtime store
shared tables (kae.db)
Cross-guardian: client stages, gates, escalations — no longer a separate shared-store.json
Alerts: "Severity: Critical" or "Red Flag" in guardian output → SMTP email via nodemailer
Process mgmt: PM2 (production) | PID lockfile prevents race conditions
Backups: nightly export (03:41 SAST) writes readable JSON snapshots to KAE/state/backup/ — seed/export only, never read back at runtime
CI: 79 unit tests + GitHub Actions gate every PR touching KAE/**
SQLite
nodemailer
node-cron
PM2
fs-extra atomic writes

🧒 Explain It Like I'm 10

Think of KAE as a restaurant kitchen. Files are orders, and every part of the system has one job in getting each order cooked right.

1. Black Box 2. Architecture 3. GHN Routing 4. Guardians 5. Event Pipeline 6. Queue 7. Learning 8. Monitors