02.1: Prompt Items
The top of the context list — the LLM’s identity framing.
File: src/utils/text/context/templates.ts:94-197
Mission
Section titled “Mission”Emit the system-role items that frame the LLM’s identity for this
turn: the humanizer block (base behavioral rules), an optional per-channel
prompt block, the persona prompt (the persona’s distinctive instructions), and
the tomori-attributes block (the personality bullets). Multi-persona turns can
also add public attributes from other personas triggered by the same message.
For impersonation turns, emits a single impersonated-user prompt instead.
Per-channel prompt override (/server channel-prompt)
Section titled “Per-channel prompt override (/server channel-prompt)”When channelPromptOverride is set for the active channel, it modifies only the
system-prompt slot — persona prompt and attributes are never affected:
append— the server system prompt (orDEFAULT_SYSTEM_PROMPT) stays in theSYSTEM_HUMANIZER_RULESblock, and the channel prompt is emitted as a distinctSYSTEM_CHANNEL_PROMPTblock immediately after it.replace— the channel prompt’s text takes over theSYSTEM_HUMANIZER_RULESblock content (no separate channel block is emitted).
The override is resolved at each call site (contextPipeline.ts, cost.ts,
snapshot.ts, hiddenImageTurn.ts) via getCachedChannelPrompt(serverId, channelId)
and threaded in as BuildContextParams.channelPromptOverride. Under an active
SillyTavern preset, SYSTEM_CHANNEL_PROMPT rides with the main marker so it
stays directly after the system prompt.
Subset of BuildContextParams plus carried state — see signature in
templates.ts:94-108. Notable fields:
botName,tomoriAttributes,publicPersonaAttributes,personaPrompttomoriConfig.system_prompt,tomoriConfig.personal_memories_enabledchannelPromptOverride—{ prompt, mode }for the active channel, or nullisUserImpersonation,impersonatedIdentityName,impersonatedUserPromptsuppressDefaultSystemPrompt— set by the routing wrapper when a preset is active andsystem_promptis empty (preset fully controls the prompt)toolPromptMacroResolver,convertMentions(shared helpers)
Output
Section titled “Output”Promise<StructuredContextItem[]> — up to four items:
| Condition | Item | Metadata tag |
|---|---|---|
Not impersonation, replace override | Channel prompt (occupies the system-prompt slot) | SYSTEM_HUMANIZER_RULES |
Not impersonation, no replace override, system_prompt present OR !suppressDefaultSystemPrompt | Humanizer (system prompt or DEFAULT_SYSTEM_PROMPT) | SYSTEM_HUMANIZER_RULES |
Not impersonation, append override | Channel prompt (distinct block after the humanizer) | SYSTEM_CHANNEL_PROMPT |
Not impersonation, personaPrompt present | Persona prompt | SYSTEM_PERSONA_PROMPT |
Impersonation, impersonatedUserPrompt present | Impersonated user prompt | SYSTEM_HUMANIZER_RULES |
| Not impersonation | tomoriAttributes.join("\n") | SYSTEM_PERSONALITY |
All emitted items are role: "system".
Side effects
Section titled “Side effects”- Tool-prompt macro expansion — every emitted text passes through
toolPromptMacroResolver.expand(...)so{short_term_memory_tool}etc. become provider-correct tool names. - Mention conversion — every emitted text passes through
convertMentions(...)for<@id>/<#id>/{bot}/{user}resolution. ThetriggererNameargument is hardcoded to"User"here (the prompt items are persona-facing, not user-facing).
Invariants
Section titled “Invariants”After this stage runs:
- For non-impersonation turns with a non-empty
system_promptor attributes, at least one item is emitted. - For impersonation turns, only the impersonated-user prompt is emitted (no persona prompt, no attributes, no humanizer fallback) — keeping the prompt strictly about the impersonated identity.
- When
suppressDefaultSystemPromptis true andsystem_promptis empty, no humanizer item is emitted — the preset’s reassembly is expected to provide the system framing.
Extension points
Section titled “Extension points”| Surface | Plugin-relevance |
|---|---|
DEFAULT_SYSTEM_PROMPT constant | Internal — exported from templates.ts for callers that need to know what the fallback is, but not user-configurable directly. The system_prompt config column is the user-facing surface. |
Tag emission (SYSTEM_HUMANIZER_RULES, SYSTEM_PERSONA_PROMPT, SYSTEM_PERSONALITY, SYSTEM_PUBLIC_PERSONA_ATTRIBUTES) | The tag scheme is the seam — preset reassembly relies on these tags to slot items into preset blocks. A plugin adding a new prompt-item kind would add a new ContextItemTag and document its slot ordering. |
| Impersonation prompt handling | Tightly coupled to chat pipeline’s impersonation flow. A plugin adding a new “alternate identity” mode would extend here + chat pipeline stage 02. |
Configuration
Section titled “Configuration”| Source | Field | Effect |
|---|---|---|
tomoriConfig | system_prompt | Overrides DEFAULT_SYSTEM_PROMPT when present |
channelPromptOverride | { prompt, mode } | append adds a SYSTEM_CHANNEL_PROMPT block after the system prompt; replace substitutes the system-prompt slot content. Set per channel via /server channel-prompt. |
tomoriConfig | personal_memories_enabled | Passed to convertMentions for blacklist/privacy behavior |
tomoriState | persona_prompt | The persona’s distinctive prompt |
tomoriState | attribute_list | Personality bullets (joined with \n) |
ChatTurn | triggeredPersonaIds | Limits public attribute exposure to the original matched persona set |
Related docs
Section titled “Related docs”- Tool-prompt macros: covered in native-assembly README.
- Mention conversion: covered in native-assembly README.
- SillyTavern preset reassembly: → preset-routing stage
01-preset-routing.md