Persona Sections
Overview
A persona today is one block of text (personas → persona_contents.prompt), and everything in it
reaches the model from the first message. There is a table for linking lorebooks to a persona
(persona_lorebook_bindings) and the lorebook read already uses it, but nothing writes to it yet. That fits what
anyone can see about you. It does not fit what the story hasn't reached yet: your apartment before anyone
has been there, a scar under your sleeve, the job you don't talk about. Writers work around this by keeping
copies: "Mira (start)", "Mira (after the flat)", "Mira (after the reveal)". The description column exists
for exactly that ("for version management"). Every copy drifts from the others, and each change has to be
made in all of them.
Persona sections replace the copies. A persona has a base, which is what everyone knows and is always on, plus any number of sections, each with its own title and text. The conversation decides which sections are switched on. When the story reaches your home, you switch on Home and the model learns about it from that point. A section can also bring its own lorebooks (Home brings the apartment lorebook with one entry per room), and those lorebooks are in play only while the section is on.
Design Goals
- One persona, many stories. The same persona is in three conversations at three different points in each story. So which sections are on is a property of the conversation, never of the persona.
- Unrevealed means unsent. A section that is off never reaches any model call: not the story prompt, not the tracker or journal eval, not summarization, not the hybrid planner. This is not a soft hint.
- One point of assembly. Every consumer already reads the persona through one path
(
fn_get_conversation_persona→IPipelineContext.GetPersonaAsync()). Section filtering happens there, so no consumer can forget it. - Nothing existing changes. A persona with no sections behaves exactly as it does today. The base is the current prompt, so there is no data migration.
- Revealed by the story, not by a keyword. A keyword lorebook entry fires when something is mentioned ("let's go to your place"). A section is in play when the story has reached it. These are different concepts, and sections don't replace keyword entries. Inside an active section's lorebooks, keywords work as usual.
Non-Goals
- Revealing a section automatically. Switching a section on when a tracker says
location = homeis the natural next step (Phase 2 below) and the schema leaves room for it. It is not in v1: v1 is a deliberate switch the writer flips. - Locking again when you rewind. If you switch on Home at message 40 and then delete back to message 30, Home stays on. Unlocking is an author decision, not an eval value, so it is not stored per message the way tracker snapshots are. Revisit only if writers ask for it.
- Sections on characters. A character's secrets revealed later is the obvious next request. Whether it shares this substrate is an open question (below). v1 is persona-only.
- Sections on persona templates (the creator-suggested roles in
persona-suggestions.md). Not in v1. - Discord. The bot has no per-conversation toggle surface. It sends the base plus the sections marked on by default, and nothing else.
- UI in the writing client.
beta.keeps its persona editor, which edits the base. It gets no section editor and no toggle panel.
Design
Where the state lives, and why not conversation settings
The switch appears among the conversation's settings: in the chat's settings drawer, next to the persona
picker (the Who drawer today). It is not stored in web_conversation_settings. That table is the
settings substrate's key/value override of default_settings keys (one scalar per key, looked up through
fn_get_web_settings). Section state is a set of references to persona rows. It needs a foreign key so that
deleting a section cleans up after itself, it has to be copied when a conversation is branched, and it has
to be joined in SQL by both the persona read and the lorebook read. Storing it as a JSON value in the
settings table would lose all three. So the UI home is the conversation's settings, and storage is a
dedicated table.
Data model
-- The base stays where it is: persona_contents.prompt. Sections are the additions.
CREATE TABLE IF NOT EXISTS persona_sections (
id SERIAL PRIMARY KEY,
uuid UUID NOT NULL DEFAULT gen_random_uuid(),
persona_id INTEGER NOT NULL REFERENCES personas(id) ON DELETE CASCADE,
title VARCHAR(80) NOT NULL,
body TEXT NOT NULL DEFAULT '',
sort_order INTEGER NOT NULL DEFAULT 0, -- MAX+1 on insert
active_by_default BOOLEAN NOT NULL DEFAULT FALSE,
character_count INTEGER NOT NULL DEFAULT 0,
-- Phase 2 hook, unused in v1: a tracker condition that switches the section on.
reveal_condition JSONB DEFAULT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Per-conversation override. No row = the section's active_by_default.
CREATE TABLE IF NOT EXISTS conversation_persona_section_states (
conversation_id INTEGER NOT NULL REFERENCES web_conversations(id) ON DELETE CASCADE,
section_id INTEGER NOT NULL REFERENCES persona_sections(id) ON DELETE CASCADE,
active BOOLEAN NOT NULL,
updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (conversation_id, section_id)
);
-- A lorebook can belong to one section. NULL = the base = always in play (today's behavior).
ALTER TABLE persona_lorebook_bindings
ADD COLUMN IF NOT EXISTS section_id INTEGER REFERENCES persona_sections(id) ON DELETE CASCADE;
ON DELETE CASCADE on the binding is deliberate. SET NULL would turn a deleted section's lorebooks into
base lorebooks, which means always on and exactly the leak this feature prevents.
Switching a conversation to a different persona leaves the old persona's state rows in place. They are ignored while another persona is attached and apply again if the writer switches back.
Assembly
fn_get_conversation_personareturnsdescription= the base followed by each active section insort_order, each under its title. "Active" meansCOALESCE(state.active, section.active_by_default).PersonaRecord.ToFormattedCard()is unchanged. Every consumer (PersonaContentProvider,PromptDisplayNames,HybridLegPlanner,WebJournalEvalService,WebSummarizationTriggerService,WebTrackerEvalService) gets the filtered card without any change of its own.fn_get_conversation_lorebook_ids: the persona branch keeps bindings wheresection_id IS NULL OR section is active in this conversation.- The Discord persona read includes only sections with
active_by_default. - Branching (
fn_branch_conversation) copies the source conversation's state rows along with the persona.
API (ServerAPI)
| Route | Purpose |
|---|---|
GET/POST /api/personas/{uuid}/sections |
list / create (owner only) |
PATCH/DELETE /api/personas/{uuid}/sections/{sectionUuid} |
edit (three-state semantics) / delete |
PUT /api/personas/{uuid}/sections/order |
reorder |
GET /api/conversations/{id}/persona-sections |
the attached persona's sections, each with its effective state and token estimate |
PATCH /api/conversations/{id}/persona-sections |
{ sectionUuid: bool, … }: switch sections on or off, surgical |
Binding lorebooks to a persona has no write path yet. persona_lorebook_bindings has a reader
(fn_get_conversation_lorebook_ids) but no writer anywhere. It was decided on 2026-07-20 that the
binding is wanted and deferred until it ships "with its write endpoint + Vault persona editor section
together" (docs-internal/architecture/content/ENTITY_LINKS.md §3.2). This feature is that ship: slice 2 adds
GET/PUT /api/personas/{uuid}/lorebooks (the full set, each entry { lorebookUuid, sectionUuid | null },
lorebooks the caller can use only). It also opts persona into the References panel, whose persona arm in
fn_get_entity_references (90_entity_references.sql) is already written and waits only for this.
UI (chatConsole)
- Persona editor. Base on top, then the list of sections: title, body, on by default, attached lorebooks, drag to reorder. One Save/Cancel pair for the whole form, as in every editor.
- In chat. A Persona sections block in the conversation's settings drawer, under the persona picker: one switch per section, a token count for each, and a line saying what switching it on adds ("+ 3 lorebooks"). A switch takes effect from the next message and does not rewrite earlier replies.
- The drawer answers the review ledger's question (
CHAT_DOOR_REVIEW_2026-09-18.md: should personas be reachable in chat?) for this part: switching sections happens in chat, and editing them stays one link away.
Implementation Plan (sliced)
| # | Slice | Where | State |
|---|---|---|---|
| 1 | Schema + assembly. Both tables, the filtered fn_get_conversation_persona, Discord default-only read, branch copy, the section CRUD and conversation-state endpoints, tests (DB: assembly and defaults. API: ownership, surgical PATCH) |
backend, any time | ✅ (M4; sections ride the persona save, the card is a new fn_get_conversation_persona_card, Discord reads no persona) |
| 2 | Persona lorebooks, base and per section. The first writer of persona_lorebook_bindings (GET/PUT /api/personas/{uuid}/lorebooks), section_id on the binding, the filtered lorebook read, persona added to the References panel (ENTITY_LINKS §3.2: ships together with the editor, so backend and slice 3 land in the same change) |
backend + slice 3 | ✅ per section (M5, through the persona save); base lorebooks and the References panel arm not built |
| 3 | Persona editor with sections | chatConsole, at the stop that rebuilds personas | ✅ (M4 + M5) |
| 4 | The in-chat switch panel | chatConsole, at the Story surface step (10+) | ✅ (M4, the story's persona panel) |
| 5 | Revealed by trackers (Phase 2): reveal_condition set in the editor. When the tracker eval sees the condition met, the section switches on and a notice appears in chat |
later | 📋 vision |
Slice 1 can ship before any chatConsole page exists: with no UI, every persona has only a base and nothing changes. Slice 2's write endpoint waits for the editor (slice 3), per the ENTITY_LINKS decision. Until then the References panel shows no persona arm.
Open Questions
For the owner:
- Do character secrets share this substrate? If progressive reveal for characters is part of the
vision,
persona_sectionsbecomes anentity_prompt_sections(owner_type, owner_id, …)table (theentity_tracker_bindingsshape), and the character editor and card reuse it. Decided (owner, 2026-10-17): persona-only. - Does a hidden section's existence show when a conversation is shared? Decided (owner, 2026-10-17): hidden means hidden. A shared story shows nothing of the sections: no titles, no count, no hint that more exists. A section that is off is never sent to the story model.
- Is there a limit on how many sections a persona can have? Decided (owner, 2026-10-17): 50 sections, each up to 10,000 characters. The cost is tokens, and the in-chat token count shows it.
- Should the base carry lorebooks too (always on)? Decided (owner, 2026-10-17): no. A section that is on by default does that.
Mine to decide at build time: the section header format in the assembled card; whether a switch toggled while a reply is streaming applies to that reply (proposed: no, it applies to the next one).
Acceptance Criteria
The feature is not done until every box below is verified ✅ against the running product. Boxes amended by the as-built record (PERSONA_SURFACE.md) say so inline; none was re-driven in the 2026-10-29 status pass.
User use cases: satisfiable + accessible (verify by driving the UI, not the code):
- UC-1 As a writer, I can add a Home section to my persona, with text and a lorebook attached, from the persona editor, without making a copy of the persona.
- UC-2 As a writer mid-story, I can switch Home on from the story's persona panel (Revealed so far), and the next reply knows about my home. No leaving the chat, no insider knowledge.
- UC-3 As a writer using one persona in two conversations, I can have Home on in one and off in the other at the same time.
- UC-4 As a writer, I can see before switching a section on how many tokens it adds and how many lorebooks it brings.
- UC-5 As a writer who branches a conversation, the branch starts with the same sections on as the message I branched from.
Behavior:
- With Home off, the captured prompt (mock LLM) contains neither Home's text nor any entry from its lorebook, even when the user message contains that lorebook's keywords.
- With Home on, both are in the prompt from the next message on.
- A section marked on by default is on in a conversation that has never touched it, and switching it off there sticks.
- Switching to another persona and back restores the first persona's switch states.
- Deleting a section removes it from every conversation's prompt and removes its lorebooks from play. They do not fall back to the base.
Invariants that must stay true:
- A persona with no sections produces a prompt byte-for-byte identical to today's (the pronoun card test still passes unchanged).
- A section that is off never reaches the tracker eval, journal eval, summarization or hybrid planner prompts (capture each one with the mock LLM).
- The writing client's persona editor still edits the persona and saves only the base. A persona edited there keeps its sections.
- Discord sends no persona text at all (it has no persona read), so no section reaches it. (Amended: the design said base plus on-by-default sections.)
- A lorebook linked to a section that is on by default is in play in every conversation that hasn't switched it off. (Amended: base lorebooks are not written; an on-by-default section does that job.)
- A persona can only be bound to a lorebook its owner can use. A private lorebook of someone else's is refused (404) and never reaches the prompt.
- The writing client's References panel shows no persona arm while it has no way to be filled. (Amended: the arm is a follow-up, R-REF.)
Edges:
- Switching sections on another user's conversation, or editing another user's persona's sections, returns 404 and changes nothing.
- A PATCH naming a section that doesn't belong to the conversation's persona is refused (400) and applies nothing from the request.
- A conversation with no persona: the persona panel shows no sections, and the endpoint returns an empty list.
- An empty section body contributes nothing to the prompt (no bare title).
- The in-story count shows the token total of the sections that are on, not of all sections. The persona page's card shows base plus every section, since it has no story. (Amended.)