# Saki

> Saki is a private Discord community platform: permission-aware AI agent, deterministic moderation, dual-node Lavalink music, social automation, and a custom K-System with elections, Bias Wars, and persistent profiles.

- HTML: https://estebanech.com/projects/saki
- Markdown: https://estebanech.com/projects/saki.md

## The server assistant that became the server infrastructure.

Saki combines a permission-aware AI agent, deterministic moderation, Lavalink music, social automation, persistent memory, and a custom K-pop community engine inside one private Discord guild.

## Metadata

- Role: Sole Designer and Engineer
- Type: Independent Production Project
- Status: Live
- Scope: Single Guild · By Design
- Repository: Private

## Overview

Saki began as a private Discord assistant for one server. Over time, it grew into the system behind much of the community itself.

Today, Saki handles natural-language assistance, moderation, music, reminders, onboarding, social embeds, Reddit feeds, server statistics, and a custom K-pop subsystem with profiles, birthdays, elections, Elo-based battles, and community analytics.

Discord remains the interface. Behind it is a long-running event-driven application with its own agent runtime, schedulers, persistent state, permission model, media infrastructure, and failure boundaries.

It is intentionally built for one guild rather than generalized into a multi-tenant product.

## Problem

Saki started as a Discord assistant. The interesting part is what happened next: AI became one component among many, while moderation, music, social automation, and community mechanics grew into their own durable systems.

The engineering question shifted from “can the bot answer questions?” to:

> How do you run an agent, deterministic ops, music failover, social automation, and a custom community engine as one single-guild platform — without letting the LLM become the control plane?

## Solution

### Agent Runtime

Natural-language interaction with tool calling, vision, web research, memories, skills, knowledge, and model fallbacks — invoked only on explicit mentions, replies, and AI commands.

### Server Operations

Deterministic infrastructure for moderation, permissions, roles, scheduled events, onboarding, stats, and context menus — independent of model availability.

### Music

Real voice infrastructure with Lavalink, radio and playlists, queue state, preferred home-node + Railway fallback, and empty-VC presence handling.

### Social Layer

Automation outside the agent: Twitter/X, Instagram, TikTok, Reddit, YouTube embed rewriting, and Reddit feed polling with dedupe and media normalization.

### Delulu Engine

The custom community product: K-Profiles, birthdays, Supremacy elections, Bias Wars, idol analytics, name history, and hall of fame — all with persistent state and scheduled jobs.

## Capabilities

### Agent Runtime

Natural-language interaction with tool calling, vision, web research, memories, skills, knowledge, and model fallbacks — invoked only on explicit mentions, replies, and AI commands.

### Server Operations

Deterministic infrastructure for moderation, permissions, roles, scheduled events, onboarding, stats, and context menus — independent of model availability.

### Music

Real voice infrastructure with Lavalink, radio and playlists, queue state, preferred home-node + Railway fallback, and empty-VC presence handling.

### Social Layer

Automation outside the agent: Twitter/X, Instagram, TikTok, Reddit, YouTube embed rewriting, and Reddit feed polling with dedupe and media normalization.

### Delulu Engine

The custom community product: K-Profiles, birthdays, Supremacy elections, Bias Wars, idol analytics, name history, and hall of fame — all with persistent state and scheduled jobs.

## Design Decisions

### Run as a persistent Discord Gateway process.

Message events, member events, voice state, moderation, K-System jobs, and Lavalink require a long-running connection — not an interaction-only webhook architecture.

### Keep AI off the control plane.

Moderation, music, feeds, embeds, reminders, and K-System schedulers must keep working when Groq is unavailable.

### Filter tools before inference, re-check at execution.

A user cannot persuade the model to call a capability it was never given, and visibility is never a substitute for server-side authorization.

### Build for one guild on purpose.

Single-guild scope keeps SQLite, allowlists, and community mechanics honest instead of pretending to be unfinished multi-tenant SaaS.

### Prefer a home Lavalink node with cloud fallback.

Tailscale-connected home audio with Railway failover improves latency and resilience without coupling music to the bot process.

### Give community mechanics real state machines.

Supremacy, Bias Wars, and profiles persist, resume after restart, and mutate Discord — they are product systems, not slash-command toys.

### Bound agent rounds and fail closed on bad tool args.

Limits reduce runaway loops; invalid JSON must not become empty defaults for destructive operations.

### Restrict allowed mentions in AI replies.

Model-generated responses must not mass-ping roles or @everyone.

## The Delulu Engine

**Custom community mechanics with persistent state, scheduled jobs, and consequences.**

There are thousands of Discord bots with an LLM and moderation. Far fewer run server-wide monthly K-pop elections that rename the guild, maintain a hall of fame, track dynasties and landslides, plus Elo-based idol wars and persistent bias profiles.

### K-Profiles

Derived from profile state, bias records, ult history, idol mention analytics, and search relationships.

### Supremacy

A monthly server-wide election where members nominate idols, vote on a theme, and the winning result becomes the server name. Saki persists election state, resumes unfinished cycles after restart, tracks historical renames, and maintains hall-of-fame statistics.

### Bias Wars

Time-boxed idol-vs-idol battles update persistent Elo ratings and head-to-head history after voting closes.

## Permissions

### Public

Knowledge, memory, music, polls, reminders, events, and self-service tools.

### Moderator

Timeout, kick, ban, purge, channels, roles, voice controls, and locks.

### Owner

Invites, webhooks, emoji, and AutoMod — higher-risk administrative surface.

## Music topology

Music is real voice infrastructure with a preferred home node over Tailscale and a Railway fallback — not a single cloud Lavalink box.

- Preferred home node with Tailscale connectivity
- Railway fallback when the home node is unreachable
- Queue mutations serialized through a guild music lock
- Empty VC pause and resume when humans return
- YouTube / SoundCloud resolution plus Spotify / Apple metadata mapping
- Music failures do not disable moderation, commands, or the agent

## AI is not the control plane

Saki works even when the LLM doesn’t.

Still works without the LLM:

- Moderation
- Music
- Welcome roles
- Server stats
- Reddit feeds
- Social embeds
- Reminders
- K-System jobs
- Slash commands

Unavailable:

- Natural-language agent

## Social content, automatically normalized

Non-agent messages can still trigger deterministic transformations — embed fixers and feed pipelines that keep working when Groq is down.

## Personality

Saki’s persona is a configurable layer — Normal, Sarcastic, Overkill, Cute — separate from authorization and deterministic rules. Changing the personality does not grant permissions.

The public presentation leans K-pop idol themed (Sakura Miyawaki / LE SSERAFIM inspiration), while the engineering story stays primary.

## Privacy

The source repository is private because it contains server-specific configuration, private knowledge, moderation behavior, internal prompts, Discord resource identifiers, infrastructure conventions, and security-sensitive integrations.

This case study focuses on architecture, authorization, persistence, agent orchestration, community systems, and non-sensitive demonstrations.

## Highlights

- 01 guild — by design, not an unfinished SaaS
- 03 authority tiers — Public · Mod · Owner
- 05 max agent rounds — bounded tool execution
- 02 Lavalink nodes — preferred home + cloud fallback
- 01 SQLite database — core, social, jobs, and K-System state
- Multiple event planes — Gateway · schedulers · voice · presence · guild state

## Technology

### Runtime

- TypeScript
- Node.js 22
- tsx
- pnpm

### Discord

- discord.js v14
- Discord Gateway
- Slash commands
- Context menus
- Interactive components

### AI

- Groq
- OpenAI-compatible APIs
- Tool calling
- Vision models
- Model routing / fallback

### Persistence

- better-sqlite3
- SQLite WAL
- FTS5

### Music

- Lavalink 4
- Home node + Railway
- Tailscale

### Infrastructure

- Docker
- Railway
- Persistent volume
- Dual-node failover

## Status

Saki is live as a persistent private-server platform. Agent, moderation, music, social automation, and K-System modules are separated so individual services can degrade without taking down the guild.

## Next Steps

- Sanitized demo capture for the public case study
- Destructive-action confirmation workflows
- Richer tool-execution audit logs
- Protected user, role, and channel configuration
- Expanded permission-boundary tests
- Structured privacy and data-export controls
- Automated SQLite backup validation
- Agent evaluation tasks and tool-success metrics

Author: Andres Echeverria (estebanech)
