Internals

How messages, models, tools and memory fit together

Platform adapters only send and normalise. The assistant runtime owns the decisions, models and tools run inside explicit permissions, and SQLite holds recoverable state.

Architecture

Core modules and who owns what

DirectoryResponsibility
cmd/webui/Process entry point, environment assembly, SQLite and runtime dependency injection.
model/assistant/Message events, channels, reply decisions, agent, media, memory and tasks.
model/llm/Unified requests, provider adapters, model catalogue, token budget and retries.
model/storage/Schema and persistence for configuration, messages, events, memory and tasks.
webui/Gin API, authentication, configuration, events, updates and SSE.
frontend-next/The Vue 3 admin console.

Pipeline

How one message decides between replying and staying quiet

  1. Receive and normalise

    The platform adapter turns text, mentions, quotes, images, files and sender details into a single MessageEvent.

  2. Enrich and cache

    Quotes, forwards and media references are resolved, and short-lived platform images are written into the local history media cache.

  3. Deterministic gates

    Checks whether the bot and group are enabled, the reply window, muted users, member level and bot-to-bot suppression.

  4. Trigger detection

    Direct messages are handled directly; groups look for explicit mentions, quotes, trigger words and plugin commands. An explicit mention outranks a quote.

  5. Semantic routing for unprompted replies

    Ordinary group messages that were not directly triggered are judged immediately by the intent model, waiting at most 60 seconds so nothing queues forever.

  6. Assemble context

    Combines the system prompt, relationships, long-term memory, recent history, images and tool evidence, trimmed to the token budget.

  7. Model and tool loop

    Selects the chat or vision role; the agent runs the permitted tools and records every step.

  8. Send and audit

    The reply goes back to the source channel, and the detailed reason, send result, latency and tokens are all persisted.

Memory

Long histories are not stuffed into every request

01

Recent context

Keeps the latest messages of the current session, serving quotes, follow-ups and continuous conversation first.

02

Compacted summaries

Once history passes a threshold, topics, conclusions and open items are distilled to cut repeated tokens.

03

Long-term facts

Stable facts, preferences and relationships are extracted asynchronously with their source, confidence and update time.

04

Retrieval on demand

Searchable by time, keyword, user, group and platform; cross-group and cross-channel access are gated by separate switches.

Retrieval narrows with structured filters first, then ranks by textual relevance and time decay, and finally passes the model only the matching evidence. Summaries are not recomputed when configuration reloads — they expire only when the input history changes or the summary version is bumped.

Multimodal

Originals, OCR and history descriptions each have a job

platform media referencedownload and verifyoriginal cachevision model / OCRanswer and description cache
  • Ordinary images are converted into whatever the provider accepts; the media layer does not shrink originals unconditionally.
  • Text-heavy screenshots use both a high-detail vision input and OCR evidence.
  • History image descriptions are cached by content SHA-256 and algorithm version.
  • Image count and vision tokens are budgeted so base64 history cannot grow without bound.
  • Video contributes a limited number of context frames, and temporary files are cleaned up afterwards.

Storage

One SQLite database plus a manageable media cache

DataDefault locationBackup requirement
Configuration, credentials, sessions, messages, memory, tasksdata/diana.dbMust be backed up, keeping the main database consistent with WAL/SHM.
Inbound mediadata/mediaCan be evicted by size; back it up when historical image recognition matters.
Runtime logslogs/diana.logRotate regularly; never publish platform events or debug context.
Install and update backups.installer/backups, .diana-updatesKeep the last known-good version and the evidence needed to restore it.