Ekco-S64QTN6/Kaiacord

Linux-native Local hosted AI chatbot for Discord

2

stars

397

commits

Python

primary language

Sep 8, 2026

updated

README

🌌 KAIACORD

A self-hosted Discord AI persona with cognitive persistence, hybrid RAG, and fully local inference.

Python Ollama discord.py Model VRAM Tests License: MIT

Overview Β· Cognitive Pipeline Β· Architecture Β· Install Β· Configuration Β· Operations Β· Docs


Overview

Kaia is an autonomous Discord persona that runs entirely on local hardware β€” no cloud API, no telemetry, no per-token billing. She keeps a persistent emotional state, per-user relationships that deepen over time, a revisable belief store, and a nightly consolidation cycle that turns the day's conversations into long-term memory.

The design goal is continuity rather than capability: a bot that remembers the outage you were both awake for, notices you have been quiet for a week, and holds an opinion it formed last month.

What makes it different from a chat wrapper

Runs entirely offlineOne 12 GB consumer GPU. Inference, embeddings, and classification are all local.
State survives restartsMood, relationships, beliefs, and episodic anchors are persisted atomically to disk.
Deterministic where it mattersCombat maths, budgeting, and safety filtering are plain Python. The LLM is used for language, not arithmetic.
Grounded by defaultHybrid BM25 + vector retrieval over a curated Markdown knowledge base, fused with Reciprocal Rank Fusion.
Guarded outputA ten-layer post-generation pipeline strips hallucinations, roleplay artifacts, and prompt echoes before anything reaches Discord.

Cognitive Pipeline

Every message flows through a deterministic feature layer before generation. These are heuristics in Python, not auxiliary model calls, so they add context without costing VRAM.

                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚      Message Input     β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚  28-Feature Cognitive Filter             β”‚
             β”‚  Mood Β· Stance Β· History Β· Relationships β”‚
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚  System Prompt Assembly & Hybrid RAG     β”‚
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚ Local Inference Engine β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core subsystems

  • Persistent emotional arc β€” mood tracked as a valence / arousal / energy vector with 6-hour decay, modulating vocabulary, reaction frequency, and Discord status text.
  • Staged relationships β€” per-user event logs across five familiarity levels (stranger β†’ inner_circle), with behavioural gating and trust thresholds.
  • Nightly dream cycle β€” between 03:00 and 05:00 the engine aggregates the day's logs, extracts assertions into a 100-entry revisable belief store, and updates a rolling identity journal.
  • Memory anchors β€” up to 100 weighted episodic memories with exponential decay, enabling callbacks to events from weeks earlier.
  • Passive inner monologue β€” background commentary from room observation, woven into the active context as private intuition.
  • Proactive initiation β€” a nine-source trigger engine (absence, beliefs, dreams, mood, curiosity, memory, silence, anchors, overheard digest), rate-capped to a lifelike frequency.
  • Temporal awareness β€” time-of-day adjustments, fatigue multipliers on long threads, and reunion detection when a user returns after an absence.
  • Consistency watchdog β€” compares each response against active high-confidence beliefs and corrects capitulation before the message is sent.

Architecture

Kaiacord uses a classify β†’ retrieve β†’ generate flow, keeping latency low by skipping retrieval entirely on high-confidence fast paths.

flowchart TD
    MSG([Message]) --> GK[Gatekeeper<br/>Rate limit Β· Blacklist Β· Boot guard]
    GK --> CL{Classify intent}

    CL -- "Fast path<br/>high confidence" --> SKIP[Skip RAG<br/>Greeting / Command]
    CL -- "Full path" --> RET

    subgraph RET ["Parallel Hybrid Retrieval"]
        direction LR
        P[Persona Context]
        U[User History]
        N[News Briefs]
        D[Dreams & Beliefs]
        W[Knowledge Base]
    end

    SKIP --> GEN
    RET --> RRF[Reciprocal Rank Fusion]
    RRF --> CTX[Build Grounded Context]
    CTX --> GEN

    subgraph GEN ["Self-Healing Generation Loop"]
        direction TB
        G1[Attempt 1] --> HC{Guards}
        HC -- Pass --> OUT([Response])
        HC -- Fail --> G2[Attempt 2<br/>Scaled temperature]
        G2 --> HC2{Guards}
        HC2 -- Pass --> OUT
        HC2 -- Fail --> G3[Attempt 3<br/>Fallback template]
        G3 --> OUT
    end

1 Β· Intent classification (CPU). A dual-path classifier routes common patterns through regex matchers and sends ambiguous input to a CPU-pinned gemma2:2b, so the primary model is never woken just to label a message.

2 Β· Hybrid retrieval. BM25 lexical search and dense vectors (nomic-embed-text-cpu) run in parallel over the Markdown knowledge base, then merge via Reciprocal Rank Fusion. Sources include the persona file, curated books and articles, daily news briefs, dream reflections, and per-user conversation history.

3 Β· Guarded generation. Two temperatures are used: 0.70 for conversation, 0.35 for document-grounded answers. Output passes a ten-layer safety pipeline that removes prompt echoes, roleplay artifacts, fabricated citations, and sycophancy before delivery.


Installation

Prerequisites

RequirementNotes
OSLinux (developed on Arch; Ubuntu/Debian fine)
GPUNVIDIA, 12 GB VRAM (RTX 3060 or better)
Python3.12+
OllamaLocal inference runtime
pandoc, popplerOptional β€” only for importing EPUB/PDF into the knowledge base

Setup

git clone https://github.com/Ekco-S64QTN6/Kaiacord.git
cd Kaiacord

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Pull the models

ollama pull gemma3:12b            # chat, narration, vision  (GPU)
ollama pull gemma2:2b             # intent classification    (CPU)
ollama pull nomic-embed-text-cpu  # RAG embeddings           (CPU)

Configure

cp .env.example .env

DISCORD_TOKEN is the only required value. Everything else is optional: Bluesky, X, and the Project 1999 forum each need both credentials and their enabled flag in config/kaia.yaml. GEMINI_API_KEY is used only by background summarisation tasks β€” leave it blank to run fully offline.

Run

python Kaiacord.py            # curses dashboard (default)
python Kaiacord.py --no-gui   # headless, for systemd

Configuration

Settings resolve in order: environment variables β†’ config/kaia.yaml (your overrides) β†’ config/default_config.yaml (defaults). Edit kaia.yaml; leave the defaults file alone.

Notable toggles

KeyDefaultEffect
features.self_model_injectionfalseSkips injecting memory/kaia_self_model.md (~900 tokens/turn). Its content duplicates the relationship manager, personalisation engine, and per-user profile documents already in RAG.
features.constitution_injectiontrueInjects memory/kaia_constitution.md (~2,400 tokens/turn). Disable to reclaim the largest single block of per-turn budget for retrieval.
generation.max_response_tokens1024Reserved from the context window every turn. Measured maximum response across 352 generations: 852 tokens.
generation.base_temperature0.70Conversational generation.
generation.rag_temperature0.35Document-grounded generation only.
bluesky.enabled / x_twitter.enabledfalseWith both disabled the social mention poller is never started.

GPU budget

The build targets a single 12 GB card. Classification and embeddings are hard-pinned to CPU so the full context window stays available to the chat model.

ModelRoleDeviceVRAMHost RAM
gemma3:12bChat, narration, visionGPU~8.2 GB~1.2 GB KV cache
gemma2:2bIntent classificationCPUβ€”~1.6 GB
nomic-embed-text-cpuRAG embeddingsCPUβ€”~500 MB

[!NOTE] performance.max_context_tokens is 16,384. The per-turn budget reserves system_reserve_tokens and max_response_tokens before allocating the remainder to retrieval and history, so raising the identity-injection blocks directly reduces RAG recall.


Operations

Interactive tool panel

bash scripts/kaia-tools.sh

Maintenance

# Health check: Ollama, models, GPU, knowledge base, config
venv/bin/python3 tools/maintenance/health_check.py

# Incremental RAG re-index against the running bot
venv/bin/python3 tools/maintenance/reindex_rag.py --trigger

# Full vector database wipe and rebuild
venv/bin/python3 tools/maintenance/reindex_rag.py --clear

Adding books and documents

# Interactive picker over ~/Downloads (EPUB Β· PDF Β· TXT Β· HTML)
bash knowledge_base/epub-to-md.sh

# Or convert directly
venv/bin/python3 tools/maintenance/ebook_to_kb_md.py ~/Downloads/book.epub \
  --outdir knowledge_base/books --category "Science Fiction" \
  --title "Title" --author "Author" --summary "One paragraph…" --keywords "a,b,c"

The converter strips pandoc/Calibre artifacts, rebuilds paragraph and chapter structure, and writes the project's frontmatter schema. Naming follows the existing conventions: books/ uses Book - <Title> by <Author>.md, documents/ uses <Topic> - <Title>.md (--prefix). A hand-written --summary improves retrieval considerably over the auto-extracted fallback. Re-index afterwards.

To repair structure in books whose source file is gone:

venv/bin/python3 tools/maintenance/repair_kb_book_structure.py          # dry run
venv/bin/python3 tools/maintenance/repair_kb_book_structure.py --apply

Behavioural probes

./scripts/run_jspace_probe.sh full         # static probes + log replay
./scripts/run_jspace_probe.sh static-only

Testing

venv/bin/python3 -m pytest tools/tests/unit/ tools/tests/integration/ -q
# current baseline: 182 passed, 3 skipped

[!TIP] Test runs write to logs/kaiacord.test.log, never to the production telemetry log logs/kaiacord.log. Override with KAIACORD_LOG_FILE=/path/to.log.


Additional Systems

βš”οΈ Aethelgard TTRPG engine

A deterministic, persistent turn-based RPG. All combat maths and state transitions are computed in Python; the LLM is used only for narration.

  • 77-floor mega-dungeon ("Spine of the World") with Resonance Lift checkpoints and per-floor encounter pools.
  • 369 monsters (44 bosses), 453 equipment items across 7 tiers, 253 fish, 12 quests.
  • 10 classes with distinct progression, passive buffs, and triggerable combat procs.
  • Housing, procedural farming, pets, and alchemy.
  • Defence soft-cap min(10, raw) + max(0, raw - 10) // 2 and absolute stat budgets prevent scaling breakage.

See docs/ttrpg/aethelgard_system.md.

🎨 Fractal art engine

A CPU-rendered fractal flame generator based on the Electric Sheep algorithm: 20 variation functions, 10 curated colour LUTs, and adaptive density estimation. Each image is accompanied by commentary driven by Kaia's current emotional vector.

🏟️ Project 1999 forum integration

Periodic scraping of Off-Topic and Technical Discussion forums, with a Discord moderation queue offering Accept/Reject on drafted replies, RAG-grounded support answers, and profile caching to model active users.

See docs/02-user-guide/forum-integration.md.

πŸ–₯️ Curses dashboard

A three-pane terminal UI β€” System Stats, Bot Status, and Cognitive Pipeline β€” showing live CPU/GPU metrics, cognitive counters (beliefs, anchors, affinity), and a stream of elevated log events.

See docs/02-user-guide/dashboard.md.


Repository Layout

Kaiacord/
β”œβ”€β”€ Kaiacord.py               Entry point and orchestrator
β”œβ”€β”€ AGENTS.md                 Developer instructions & runtime constraints
β”œβ”€β”€ config/                   YAML configuration (kaia.yaml overrides defaults)
β”œβ”€β”€ knowledge_base/           Grounding corpus
β”‚   β”œβ”€β”€ books/                Long-form reference works
β”‚   β”œβ”€β”€ documents/            Articles, specs, scraped reports
β”‚   β”œβ”€β”€ wiki/                 Project 1999 wiki articles
β”‚   └── troubleshooting/      Synthesised support guides
β”œβ”€β”€ memory/                   Runtime state β€” never committed
β”‚   β”œβ”€β”€ beliefs.json          100-entry revisable belief store
β”‚   β”œβ”€β”€ bot_state.json        Mood, familiarity, global variables
β”‚   β”œβ”€β”€ anchors.json          100-entry episodic callbacks with decay
β”‚   β”œβ”€β”€ identity_stream.md    Rolling identity journal
β”‚   └── relationships/        Per-user trust events
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ core/                 Cognitive layer
β”‚   β”‚   β”œβ”€β”€ message_processor.py   Primary intelligence flow
β”‚   β”‚   β”œβ”€β”€ safety_pipeline.py     10-layer post-generation guard
β”‚   β”‚   β”œβ”€β”€ response_filter.py     Persona & bot-speak filtering
β”‚   β”‚   β”œβ”€β”€ context_optimizer.py   Token budgeting
β”‚   β”‚   β”œβ”€β”€ kaia_rag*.py           Retrieval, indexing, scoring
β”‚   β”‚   └── kaia_dream.py          Nightly consolidation
β”‚   β”œβ”€β”€ ttrpg/                Combat, dungeon, housing state
β”‚   β”œβ”€β”€ commands/             Discord command routers
β”‚   β”œβ”€β”€ social/               Forum crawler & social responders
β”‚   └── infrastructure/       DI context, dashboard, logging, GPU pinning
β”œβ”€β”€ tools/
β”‚   β”œβ”€β”€ maintenance/          Health checks, re-indexing, KB ingestion
β”‚   β”œβ”€β”€ diagnostics/          RAG deep-dive and index health
β”‚   β”œβ”€β”€ development/          Self-model and profile utilities
β”‚   └── tests/                Unit and integration suites
β”œβ”€β”€ finetune/                 LoRA pipeline for Gemma 3 12B
└── docs/                     Technical and gameplay documentation

Documentation

Operational audit reports live in docs/reports/, which is git-ignored β€” they contain transcript excerpts and runtime telemetry, so they stay local to a deployment.


License

Released under the MIT License β€” use it, fork it, ship it.

Kaiacord depends on other open-source projects, all under permissive licenses (MIT, Apache-2.0, BSD). The one exception is browser_cookie3 (LGPL), used only for optional X/Twitter cookie import; it is imported dynamically and carries no copyleft obligation for this project. The models themselves ship under their own terms β€” see Gemma and Nomic Embed.


Built by Ekco Β· Local AI, no cloud required.

Contributors

Ekco-S64QTN6

397 commits

Ekco-S64QTN6/Kaiacord

Linux-native Local hosted AI chatbot for Discord

2

stars

397

commits

Python

primary language

Sep 8, 2026

updated

README

🌌 KAIACORD

A self-hosted Discord AI persona with cognitive persistence, hybrid RAG, and fully local inference.

Python Ollama discord.py Model VRAM Tests License: MIT

Overview Β· Cognitive Pipeline Β· Architecture Β· Install Β· Configuration Β· Operations Β· Docs


Overview

Kaia is an autonomous Discord persona that runs entirely on local hardware β€” no cloud API, no telemetry, no per-token billing. She keeps a persistent emotional state, per-user relationships that deepen over time, a revisable belief store, and a nightly consolidation cycle that turns the day's conversations into long-term memory.

The design goal is continuity rather than capability: a bot that remembers the outage you were both awake for, notices you have been quiet for a week, and holds an opinion it formed last month.

What makes it different from a chat wrapper

Runs entirely offlineOne 12 GB consumer GPU. Inference, embeddings, and classification are all local.
State survives restartsMood, relationships, beliefs, and episodic anchors are persisted atomically to disk.
Deterministic where it mattersCombat maths, budgeting, and safety filtering are plain Python. The LLM is used for language, not arithmetic.
Grounded by defaultHybrid BM25 + vector retrieval over a curated Markdown knowledge base, fused with Reciprocal Rank Fusion.
Guarded outputA ten-layer post-generation pipeline strips hallucinations, roleplay artifacts, and prompt echoes before anything reaches Discord.

Cognitive Pipeline

Every message flows through a deterministic feature layer before generation. These are heuristics in Python, not auxiliary model calls, so they add context without costing VRAM.

                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚      Message Input     β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚  28-Feature Cognitive Filter             β”‚
             β”‚  Mood Β· Stance Β· History Β· Relationships β”‚
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚  System Prompt Assembly & Hybrid RAG     β”‚
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚ Local Inference Engine β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Core subsystems

  • Persistent emotional arc β€” mood tracked as a valence / arousal / energy vector with 6-hour decay, modulating vocabulary, reaction frequency, and Discord status text.
  • Staged relationships β€” per-user event logs across five familiarity levels (stranger β†’ inner_circle), with behavioural gating and trust thresholds.
  • Nightly dream cycle β€” between 03:00 and 05:00 the engine aggregates the day's logs, extracts assertions into a 100-entry revisable belief store, and updates a rolling identity journal.
  • Memory anchors β€” up to 100 weighted episodic memories with exponential decay, enabling callbacks to events from weeks earlier.
  • Passive inner monologue β€” background commentary from room observation, woven into the active context as private intuition.
  • Proactive initiation β€” a nine-source trigger engine (absence, beliefs, dreams, mood, curiosity, memory, silence, anchors, overheard digest), rate-capped to a lifelike frequency.
  • Temporal awareness β€” time-of-day adjustments, fatigue multipliers on long threads, and reunion detection when a user returns after an absence.
  • Consistency watchdog β€” compares each response against active high-confidence beliefs and corrects capitulation before the message is sent.

Architecture

Kaiacord uses a classify β†’ retrieve β†’ generate flow, keeping latency low by skipping retrieval entirely on high-confidence fast paths.

flowchart TD
    MSG([Message]) --> GK[Gatekeeper<br/>Rate limit Β· Blacklist Β· Boot guard]
    GK --> CL{Classify intent}

    CL -- "Fast path<br/>high confidence" --> SKIP[Skip RAG<br/>Greeting / Command]
    CL -- "Full path" --> RET

    subgraph RET ["Parallel Hybrid Retrieval"]
        direction LR
        P[Persona Context]
        U[User History]
        N[News Briefs]
        D[Dreams & Beliefs]
        W[Knowledge Base]
    end

    SKIP --> GEN
    RET --> RRF[Reciprocal Rank Fusion]
    RRF --> CTX[Build Grounded Context]
    CTX --> GEN

    subgraph GEN ["Self-Healing Generation Loop"]
        direction TB
        G1[Attempt 1] --> HC{Guards}
        HC -- Pass --> OUT([Response])
        HC -- Fail --> G2[Attempt 2<br/>Scaled temperature]
        G2 --> HC2{Guards}
        HC2 -- Pass --> OUT
        HC2 -- Fail --> G3[Attempt 3<br/>Fallback template]
        G3 --> OUT
    end

1 Β· Intent classification (CPU). A dual-path classifier routes common patterns through regex matchers and sends ambiguous input to a CPU-pinned gemma2:2b, so the primary model is never woken just to label a message.

2 Β· Hybrid retrieval. BM25 lexical search and dense vectors (nomic-embed-text-cpu) run in parallel over the Markdown knowledge base, then merge via Reciprocal Rank Fusion. Sources include the persona file, curated books and articles, daily news briefs, dream reflections, and per-user conversation history.

3 Β· Guarded generation. Two temperatures are used: 0.70 for conversation, 0.35 for document-grounded answers. Output passes a ten-layer safety pipeline that removes prompt echoes, roleplay artifacts, fabricated citations, and sycophancy before delivery.


Installation

Prerequisites

RequirementNotes
OSLinux (developed on Arch; Ubuntu/Debian fine)
GPUNVIDIA, 12 GB VRAM (RTX 3060 or better)
Python3.12+
OllamaLocal inference runtime
pandoc, popplerOptional β€” only for importing EPUB/PDF into the knowledge base

Setup

git clone https://github.com/Ekco-S64QTN6/Kaiacord.git
cd Kaiacord

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Pull the models

ollama pull gemma3:12b            # chat, narration, vision  (GPU)
ollama pull gemma2:2b             # intent classification    (CPU)
ollama pull nomic-embed-text-cpu  # RAG embeddings           (CPU)

Configure

cp .env.example .env

DISCORD_TOKEN is the only required value. Everything else is optional: Bluesky, X, and the Project 1999 forum each need both credentials and their enabled flag in config/kaia.yaml. GEMINI_API_KEY is used only by background summarisation tasks β€” leave it blank to run fully offline.

Run

python Kaiacord.py            # curses dashboard (default)
python Kaiacord.py --no-gui   # headless, for systemd

Configuration

Settings resolve in order: environment variables β†’ config/kaia.yaml (your overrides) β†’ config/default_config.yaml (defaults). Edit kaia.yaml; leave the defaults file alone.

Notable toggles

KeyDefaultEffect
features.self_model_injectionfalseSkips injecting memory/kaia_self_model.md (~900 tokens/turn). Its content duplicates the relationship manager, personalisation engine, and per-user profile documents already in RAG.
features.constitution_injectiontrueInjects memory/kaia_constitution.md (~2,400 tokens/turn). Disable to reclaim the largest single block of per-turn budget for retrieval.
generation.max_response_tokens1024Reserved from the context window every turn. Measured maximum response across 352 generations: 852 tokens.
generation.base_temperature0.70Conversational generation.
generation.rag_temperature0.35Document-grounded generation only.
bluesky.enabled / x_twitter.enabledfalseWith both disabled the social mention poller is never started.

GPU budget

The build targets a single 12 GB card. Classification and embeddings are hard-pinned to CPU so the full context window stays available to the chat model.

ModelRoleDeviceVRAMHost RAM
gemma3:12bChat, narration, visionGPU~8.2 GB~1.2 GB KV cache
gemma2:2bIntent classificationCPUβ€”~1.6 GB
nomic-embed-text-cpuRAG embeddingsCPUβ€”~500 MB

[!NOTE] performance.max_context_tokens is 16,384. The per-turn budget reserves system_reserve_tokens and max_response_tokens before allocating the remainder to retrieval and history, so raising the identity-injection blocks directly reduces RAG recall.


Operations

Interactive tool panel

bash scripts/kaia-tools.sh

Maintenance

# Health check: Ollama, models, GPU, knowledge base, config
venv/bin/python3 tools/maintenance/health_check.py

# Incremental RAG re-index against the running bot
venv/bin/python3 tools/maintenance/reindex_rag.py --trigger

# Full vector database wipe and rebuild
venv/bin/python3 tools/maintenance/reindex_rag.py --clear

Adding books and documents

# Interactive picker over ~/Downloads (EPUB Β· PDF Β· TXT Β· HTML)
bash knowledge_base/epub-to-md.sh

# Or convert directly
venv/bin/python3 tools/maintenance/ebook_to_kb_md.py ~/Downloads/book.epub \
  --outdir knowledge_base/books --category "Science Fiction" \
  --title "Title" --author "Author" --summary "One paragraph…" --keywords "a,b,c"

The converter strips pandoc/Calibre artifacts, rebuilds paragraph and chapter structure, and writes the project's frontmatter schema. Naming follows the existing conventions: books/ uses Book - <Title> by <Author>.md, documents/ uses <Topic> - <Title>.md (--prefix). A hand-written --summary improves retrieval considerably over the auto-extracted fallback. Re-index afterwards.

To repair structure in books whose source file is gone:

venv/bin/python3 tools/maintenance/repair_kb_book_structure.py          # dry run
venv/bin/python3 tools/maintenance/repair_kb_book_structure.py --apply

Behavioural probes

./scripts/run_jspace_probe.sh full         # static probes + log replay
./scripts/run_jspace_probe.sh static-only

Testing

venv/bin/python3 -m pytest tools/tests/unit/ tools/tests/integration/ -q
# current baseline: 182 passed, 3 skipped

[!TIP] Test runs write to logs/kaiacord.test.log, never to the production telemetry log logs/kaiacord.log. Override with KAIACORD_LOG_FILE=/path/to.log.


Additional Systems

βš”οΈ Aethelgard TTRPG engine

A deterministic, persistent turn-based RPG. All combat maths and state transitions are computed in Python; the LLM is used only for narration.

  • 77-floor mega-dungeon ("Spine of the World") with Resonance Lift checkpoints and per-floor encounter pools.
  • 369 monsters (44 bosses), 453 equipment items across 7 tiers, 253 fish, 12 quests.
  • 10 classes with distinct progression, passive buffs, and triggerable combat procs.
  • Housing, procedural farming, pets, and alchemy.
  • Defence soft-cap min(10, raw) + max(0, raw - 10) // 2 and absolute stat budgets prevent scaling breakage.

See docs/ttrpg/aethelgard_system.md.

🎨 Fractal art engine

A CPU-rendered fractal flame generator based on the Electric Sheep algorithm: 20 variation functions, 10 curated colour LUTs, and adaptive density estimation. Each image is accompanied by commentary driven by Kaia's current emotional vector.

🏟️ Project 1999 forum integration

Periodic scraping of Off-Topic and Technical Discussion forums, with a Discord moderation queue offering Accept/Reject on drafted replies, RAG-grounded support answers, and profile caching to model active users.

See docs/02-user-guide/forum-integration.md.

πŸ–₯️ Curses dashboard

A three-pane terminal UI β€” System Stats, Bot Status, and Cognitive Pipeline β€” showing live CPU/GPU metrics, cognitive counters (beliefs, anchors, affinity), and a stream of elevated log events.

See docs/02-user-guide/dashboard.md.


Repository Layout

Kaiacord/
β”œβ”€β”€ Kaiacord.py               Entry point and orchestrator
β”œβ”€β”€ AGENTS.md                 Developer instructions & runtime constraints
β”œβ”€β”€ config/                   YAML configuration (kaia.yaml overrides defaults)
β”œβ”€β”€ knowledge_base/           Grounding corpus
β”‚   β”œβ”€β”€ books/                Long-form reference works
β”‚   β”œβ”€β”€ documents/            Articles, specs, scraped reports
β”‚   β”œβ”€β”€ wiki/                 Project 1999 wiki articles
β”‚   └── troubleshooting/      Synthesised support guides
β”œβ”€β”€ memory/                   Runtime state β€” never committed
β”‚   β”œβ”€β”€ beliefs.json          100-entry revisable belief store
β”‚   β”œβ”€β”€ bot_state.json        Mood, familiarity, global variables
β”‚   β”œβ”€β”€ anchors.json          100-entry episodic callbacks with decay
β”‚   β”œβ”€β”€ identity_stream.md    Rolling identity journal
β”‚   └── relationships/        Per-user trust events
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ core/                 Cognitive layer
β”‚   β”‚   β”œβ”€β”€ message_processor.py   Primary intelligence flow
β”‚   β”‚   β”œβ”€β”€ safety_pipeline.py     10-layer post-generation guard
β”‚   β”‚   β”œβ”€β”€ response_filter.py     Persona & bot-speak filtering
β”‚   β”‚   β”œβ”€β”€ context_optimizer.py   Token budgeting
β”‚   β”‚   β”œβ”€β”€ kaia_rag*.py           Retrieval, indexing, scoring
β”‚   β”‚   └── kaia_dream.py          Nightly consolidation
β”‚   β”œβ”€β”€ ttrpg/                Combat, dungeon, housing state
β”‚   β”œβ”€β”€ commands/             Discord command routers
β”‚   β”œβ”€β”€ social/               Forum crawler & social responders
β”‚   └── infrastructure/       DI context, dashboard, logging, GPU pinning
β”œβ”€β”€ tools/
β”‚   β”œβ”€β”€ maintenance/          Health checks, re-indexing, KB ingestion
β”‚   β”œβ”€β”€ diagnostics/          RAG deep-dive and index health
β”‚   β”œβ”€β”€ development/          Self-model and profile utilities
β”‚   └── tests/                Unit and integration suites
β”œβ”€β”€ finetune/                 LoRA pipeline for Gemma 3 12B
└── docs/                     Technical and gameplay documentation

Documentation

Operational audit reports live in docs/reports/, which is git-ignored β€” they contain transcript excerpts and runtime telemetry, so they stay local to a deployment.


License

Released under the MIT License β€” use it, fork it, ship it.

Kaiacord depends on other open-source projects, all under permissive licenses (MIT, Apache-2.0, BSD). The one exception is browser_cookie3 (LGPL), used only for optional X/Twitter cookie import; it is imported dynamically and carries no copyleft obligation for this project. The models themselves ship under their own terms β€” see Gemma and Nomic Embed.


Built by Ekco Β· Local AI, no cloud required.

Contributors

Ekco-S64QTN6

397 commits

Languages

Python

98.7%

Shell

1.3%