01: Preset Routing
This content is not available in your language yet.
The routing stage determines whether the LLM prompt follows TomoriBot’s native fixed-order layout or is rearranged through an active SillyTavern preset.
Flow and ownership
Section titled “Flow and ownership”The public buildContext wrapper in src/utils/text/context/builder.ts coordinates preset routing:
- Native execution:
buildContextNativeruns first on every turn. Preset reassembly needs native structured context items to populate preset markers. When a preset is active,presetOwnsSystemPromptis set: the server’s storedsystem_promptandDEFAULT_SYSTEM_PROMPTare both skipped, so the preset’s system blocks control the prompt. The stored prompt stays in the database and applies again once the preset is turned off./config> Behavior > General locks its system prompt controls for the same reason. - Preset check: The wrapper queries
getCachedActivePreset(serverId)using the guild’s server ID. If no preset is active, or if the turn is a user impersonation, the native output is returned directly. - Preset reassembly: When a preset is active and the turn is not an impersonation,
reassembleWithPresetinsrc/utils/text/presetContextBuilder.tsbuckets native items bymetadataTagand maps them into the preset’s ordered nodes. - Random macro resolution: After either path completes,
resolveRandomChoiceMacrosInBuildOutputrolls{{random:a::b}}and{random::a::b}choices across context items, tail directives, and deferred short-term memory blocks. Lorebook blocks keep their text literal. - World info routing:
worldInfoBeforeandworldInfoAfterconsume only their Always On lore groups. Activated lore, documents, presence, and clock items bypass marker buckets and are positioned at the tail slot downstream.
Constraints and rationale
Section titled “Constraints and rationale”- Native build runs first: Presets do not fetch or format database state independently. They rearrange structured items already tagged by the native pipeline (
SYSTEM_HUMANIZER_RULES,KNOWLEDGE_SERVER_INFO,DIALOGUE_HISTORY, etc.). - Impersonation bypass: User impersonation turns always bypass preset reassembly. This prevents third-party prompt templates from overriding the required imitation directive and framing.
- Preserved out-of-band items: Tail directives, uncensor directives, the unified short-term memory nudge (
nudgeItem), and deferred memory blocks (memoryInjectionItems) pass through preset reassembly unchanged. Downstream chat pipeline stages apply the registry anchors, preventing preset anchors from misplacing recency-sensitive context. - Unmapped item preservation: Preset reassembly flushes TomoriBot-specific knowledge items (server info, server memories, emojis, stickers, sprites) and dialogue-adjacent items (participant profiles, inline short-term memory, conditioning, and unclaimed Always On lore) at configured anchor markers (
main,charDescription,charPersonality,dialogueExamples,chatHistory). Any remaining unpulled items append at the end of the system block list so no native context is dropped.
NovelAI attempts receive a separate native context captured before preset reassembly. This preserves personality and real dialogue even when preset macros consume their buckets or inject text into history parts. The shared pipeline retains the ordinary preset result for other providers, including fallbacks, while each NovelAI attempt applies its own content allowlist and fitter.
Source pointers
Section titled “Source pointers”src/utils/text/context/builder.ts:buildContextrouting wrapper.src/utils/text/presetContextBuilder.ts:reassembleWithPresetnode mapping and item bucketing.src/utils/cache/stPresetCache.ts:getCachedActivePresetcache lookup.src/utils/text/context/templates.ts:resolveRandomChoiceMacrosInBuildOutputmacro expansion.- SillyTavern Preset System: user-facing preset features and node types.