Recent context
Keeps the latest messages of the current session, serving quotes, follow-ups and continuous conversation first.
Internals
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
| Directory | Responsibility |
|---|---|
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
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.
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.
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.
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.
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.
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.
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.
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.
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
Keeps the latest messages of the current session, serving quotes, follow-ups and continuous conversation first.
Once history passes a threshold, topics, conclusions and open items are distilled to cut repeated tokens.
Stable facts, preferences and relationships are extracted asynchronously with their source, confidence and update time.
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
Storage
| Data | Default location | Backup requirement |
|---|---|---|
| Configuration, credentials, sessions, messages, memory, tasks | data/diana.db | Must be backed up, keeping the main database consistent with WAL/SHM. |
| Inbound media | data/media | Can be evicted by size; back it up when historical image recognition matters. |
| Runtime logs | logs/diana.log | Rotate regularly; never publish platform events or debug context. |
| Install and update backups | .installer/backups, .diana-updates under the data directory | Keep the last known-good version and the evidence needed to restore it. |