Autonomous, sentient-like AI bots powered by local LLM inference
An open-source multi-platform AI assistant ecosystem with a modular architecture. The brain service (Emerald) connects to platform adapters (Discord, Matrix) and an LLM gateway (Sapphire) backed by llama.cpp (Krystal).
LUNA stands for Lifelike User-like Neural Agent -- an autonomous conversational AI designed to mimic human imperfections and social behavior.
flowchart TD
classDef platform fill:#2c3e50,color:#fff,stroke-width:2px
classDef jade fill:#1abc9c,color:#fff,stroke-width:2px
classDef pixie fill:#e84393,color:#fff,stroke-width:2px
classDef brain fill:#27ae60,color:#fff,stroke-width:2px
classDef service fill:#2980b9,color:#fff,stroke-width:2px
classDef inference fill:#8e44ad,color:#fff,stroke-width:2px
classDef alt fill:#c0392b,color:#fff,stroke-width:2px
Discord["Discord"]:::platform
Matrix["Matrix"]:::platform
Jade["Jade (Discord)"]:::jade
Pixieglow["Pixieglow (Matrix)"]:::pixie
Discord ~~~ Matrix
Emerald["Emerald (Brain)
behavior · triggers · routing"]:::brain
Sapphire["Sapphire (LLM Gateway)
classify · emotion · sessions"]:::service
KrystalS["Krystal (Small)
Luna 1.5B · :3124
FUTILE messages"]:::inference
KrystalL["Krystal (Large)
Discord-Hermes-8B · :3125
INTERESSANT messages"]:::inference
Ruby["Ruby (Markov Chain)
order-4 · SQLite · 0 latency"]:::alt
Discord --> Jade
Matrix --> Pixieglow
Jade -- ":3126 WS" --> Emerald
Pixieglow -- ":3126 WS" --> Emerald
Emerald -- ":3123 HTTP" --> Sapphire
Sapphire -- ":3124" --> KrystalS
Sapphire -- ":3125" --> KrystalL
Emerald -.->|":3127"| Ruby
- User sends a message on Discord or Matrix
- The adapter (Jade/Pixieglow) forwards it to Emerald via WebSocket
- Emerald evaluates behavior rules (burst, typo, sleep, mannerisms)
- Emerald decides: random/spontaneous triggers → Ruby (Markov chain), all others → Sapphire
- If Sapphire: classifies the message (emotion valence/arousal, category), manages conversation sessions, injects few-shot examples, and constructs the prompt
- Sapphire calls Krystal with emotion-aware sampling parameters
- Sapphire checks for degenerate responses and retries if needed
- Sapphire returns the response text (and optionally debug stats)
- Emerald applies typo/swap behavior and sends a
RespondCommandback to the adapter - The adapter posts the response to the platform
The bot doesn't just generate text -- it decides when, how, and whether to respond, simulating human imperfections:
| Behavior | Description |
|---|---|
| Sleep cycles | Circadian rhythm -- ignores messages during rest hours, slows down when drowsy |
| Typo injection | Keyboard-mistake realism with delayed self-correction |
| Hesitation | Filler words injected post-generation ("uh...", "hmm...") |
| Burst mode | Splits long responses into timed fragments |
| Topic fatigue | Gets bored of repetitive topics -- longer delays, higher ignore chance |
| Forget chance | Silently drops messages 3% of the time |
| Follow-up detection | Chains up to 3 rapid replies in active conversations |
- Multi-platform -- Discord (Jade) and Matrix (Pixieglow) with the same brain backend
- Emotion-aware LLM -- Valence/arousal classification adjusts sampling parameters
- Few-shot learning -- Category-matched example injection from YAML files
- Session management -- Per-channel conversation history
- Markov chain spontaneity -- Ruby generates context-free messages from real conversation data
- Debug mode -- End-to-end token counting and timing across all layers
- Single small model -- Luna Protocol 1.5B Q4_K_M fits in ~3 GB RAM
| Repository | Description | Language | Status |
|---|---|---|---|
| emerald | Brain & behavior engine | TypeScript | Active |
| sapphire | LLM gateway | Python | Active |
| krystal | LLM inference | C++ | Active |
| jade | Discord adapter | TypeScript | Active |
| pixieglow | Matrix adapter | TypeScript | Active |
| ruby | Markov chain | TypeScript | Active |
| protocol-luna.github.io | Website | HTML/CSS | Active |
- All services run on a single VPS managed by PM2
- WebSocket :3126 (Emerald ↔ bots)
- HTTP :3123 (Emerald ↔ Sapphire)
- HTTP :3124 (Sapphire ↔ Krystal)
- HTTP :3127 (Emerald ↔ Ruby)
- Cloudflared tunnel for Matrix federation
- GitHub Pages serves
protocol-luna.github.io
# 1. LLM inference
git clone https://github.com/protocol-luna/krystal.git && cd krystal && ./start.sh
# 2. LLM gateway
git clone https://github.com/protocol-luna/sapphire.git && cd sapphire && pip install -r requirements.txt && python server.py
# 3. Brain service
git clone https://github.com/protocol-luna/emerald.git && cd emerald && npm install && npm start
# 4. Markov chain (optional)
git clone https://github.com/protocol-luna/ruby.git && cd ruby && npm install && npm start
# 5. Platform adapter (Discord or Matrix)
git clone https://github.com/protocol-luna/jade.git # or pixieglowBuilt with ❤️ and llama.cpp





