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/The Vue 3 admin console.

Pipeline

How one message decides between replying and staying quiet

  1. Receive and enqueue

    The platform adapter turns text, mentions, quotes, images, files and sender details into a single MessageEvent, which is written to a SQLite inbound queue before processing, so a crash or restart does not lose it; failures are retried with backoff.

  2. Backfill after reconnect

    After a reconnect Diana pulls the history it missed and checks group seq numbers for gaps. Only the newest few messages per session that would have triggered a reply directly enter the reply path; the rest only fill in history.

  3. Deterministic gates

    Checks group availability, whether the bot and group are enabled, mutes, model quota, member level, reply suppression and bot-to-bot suppression, recording the reason at every step.

  4. Trigger detection

    Direct messages are handled directly; groups look for explicit mentions, quotes, aliases, links and plugin commands. A follow-up or correction the same person sends while a reply is generating is merged into it.

  5. Unprompted reply rating

    Group messages that were not directly triggered are rated by the router model — "is this addressed to the bot?" plus a 0–1 chat score — then passed by chat level, cooldown and the bot's share of recent messages. Errors, timeouts (60 seconds) and unparsable output all mean silence.

  6. Assemble context

    The stable system prompt and history come first; memory, tool evidence and other per-turn content sit after the cache breakpoint, all trimmed to the token budget.

  7. Model and agent loop

    The agent runs one tool per step within step, per-tool timeout and finalization-reserve limits; when a limit is hit it is forced to finalize, and the reply is checked for line breaks, evidence and links before it returns.

  8. Pre-send review

    Model silence, semantic dedup, one audit model call (private closing, group stop, loops, account safety, unprompted reply quality), and send-time checks for interrupts, idempotency and pauses.

  9. Send and record

    Replies go back to the source channel in chunks, with only the first quoting and mentioning; group sends back off on separate text and media lanes. Outcome codes, reasons, delivery stages, latency and tokens are all persisted.

Flowcharts, conditions and outcome codes for every step are on the Pipeline page.

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 reference→download and verify→original cache→vision model / OCR→answer 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-updates under the data directoryKeep the last known-good version and the evidence needed to restore it.