Skip to content

02.1: Prompt Items

The top of the context list — the LLM’s identity framing.

File: src/utils/text/context/templates.ts:94-197

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 (or DEFAULT_SYSTEM_PROMPT) stays in the SYSTEM_HUMANIZER_RULES block, and the channel prompt is emitted as a distinct SYSTEM_CHANNEL_PROMPT block immediately after it.
  • replace — the channel prompt’s text takes over the SYSTEM_HUMANIZER_RULES block 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, personaPrompt
  • tomoriConfig.system_prompt, tomoriConfig.personal_memories_enabled
  • channelPromptOverride{ prompt, mode } for the active channel, or null
  • isUserImpersonation, impersonatedIdentityName, impersonatedUserPrompt
  • suppressDefaultSystemPrompt — set by the routing wrapper when a preset is active and system_prompt is empty (preset fully controls the prompt)
  • toolPromptMacroResolver, convertMentions (shared helpers)

Promise<StructuredContextItem[]> — up to four items:

ConditionItemMetadata tag
Not impersonation, replace overrideChannel prompt (occupies the system-prompt slot)SYSTEM_HUMANIZER_RULES
Not impersonation, no replace override, system_prompt present OR !suppressDefaultSystemPromptHumanizer (system prompt or DEFAULT_SYSTEM_PROMPT)SYSTEM_HUMANIZER_RULES
Not impersonation, append overrideChannel prompt (distinct block after the humanizer)SYSTEM_CHANNEL_PROMPT
Not impersonation, personaPrompt presentPersona promptSYSTEM_PERSONA_PROMPT
Impersonation, impersonatedUserPrompt presentImpersonated user promptSYSTEM_HUMANIZER_RULES
Not impersonationtomoriAttributes.join("\n")SYSTEM_PERSONALITY

All emitted items are role: "system".

  • 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. The triggererName argument is hardcoded to "User" here (the prompt items are persona-facing, not user-facing).

After this stage runs:

  • For non-impersonation turns with a non-empty system_prompt or 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 suppressDefaultSystemPrompt is true and system_prompt is empty, no humanizer item is emitted — the preset’s reassembly is expected to provide the system framing.
SurfacePlugin-relevance
DEFAULT_SYSTEM_PROMPT constantInternal — 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 handlingTightly coupled to chat pipeline’s impersonation flow. A plugin adding a new “alternate identity” mode would extend here + chat pipeline stage 02.
SourceFieldEffect
tomoriConfigsystem_promptOverrides 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.
tomoriConfigpersonal_memories_enabledPassed to convertMentions for blacklist/privacy behavior
tomoriStatepersona_promptThe persona’s distinctive prompt
tomoriStateattribute_listPersonality bullets (joined with \n)
ChatTurntriggeredPersonaIdsLimits public attribute exposure to the original matched persona set