[GH-ISSUE #8832] [Feature]: Layered summarization for long Roleplay context #8515

Closed
opened 2026-11-07 16:43:28 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @qvazzar on GitHub (Nov 4, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/8832

Originally assigned to: @SpicyMarinara on GitHub.

What problem does this solve?

Long Roleplay chats eventually exceed the model's useful context window. Users currently have three imperfect choices:

  • keep more raw messages, which consumes most of the prompt with atmospheric prose and degrades attention;
  • rely on a flat list of rolling summaries, where old entries stay separate and are never recursively compressed;
  • use semantic retrieval over summaries, which helps find relevant entries but does not guarantee chronological continuity or a predictable token budget.

Marinara already has Chat Summary, automatic summaries, hidden-from-AI messages, summary connections, prompt markers, and Advanced Memory. However, the Roleplay Chat Summary path has no concept of a bounded, layered memory: old summaries remain a flat list, and there is no automatic promotion of older material into progressively denser summaries. This makes it difficult to keep a long chat both coherent and small in the prompt.

The goal is a layered summarization mode for Roleplay that keeps recent turns verbatim, compresses older turns into short snippets, and recursively compresses old snippets into deeper layers. It should use Marinara's own storage and prompt pipeline rather than introducing a second parallel memory system.

Proposed solution

Add an optional Layered engine mode to the existing Roleplay Chat Summary:

Core behavior

  • Keep the most recent N assistant turns word-for-word.
  • Summarize the oldest eligible turns into compact Layer 0 snippets.
  • When a layer reaches its snippet limit, promote its oldest snippets into the next layer:
    • the first promotion into an empty layer can move one snippet directly without an LLM call;
    • later promotions merge a configurable number of snippets with the destination layer's existing context.
  • Cascade promotions when the destination layer also overflows, up to a configurable maximum depth.
  • Preserve chronological order when compiling the prompt: deeper layers first, then Layer 0, then the verbatim tail.
  • Keep every original message. Summarized messages are hidden from the model only, never deleted or hidden from the user's chat view.

Data model

Reuse the existing ChatSummaryEntry storage shape where possible rather than adding a second list of memory records. Layered entries need enough metadata to identify:

  • the layer number;
  • whether the entry is a direct turn summary, a promotion, or a seed;
  • the source entries for a promotion;
  • the covered message IDs and hidden message IDs;
  • the usual enabled/disabled state and token estimate.

ChatMetadata needs per-chat settings and a small checkpoint so an interrupted run can resume.

Settings

Per chat, at minimum:

  • verbatim assistant turns;
  • turns per snippet;
  • snippets per layer;
  • snippets per promotion;
  • maximum layers;
  • pause summarization;
  • hide summarized messages from model context;
  • selected prompt template.

Global settings and templates:

  • system prompt;
  • user prompt with variables for persona name, prior context, and the new passage;
  • promotion prompt;
  • injection wrapper template;
  • narrative and game-state presets;
  • optional output-cleaning patterns.

Reuse the existing Summary Connection and Maximum output size controls.

Automatic behavior and recovery

  • After an assistant reply, process at most one new snippet per run, unless a backlog requires catch-up.
  • On failure, do not advance the checkpoint and do not hide the failed batch.
  • Support Force Summarize, Stop, catch-up, and a backlog prompt.
  • Support editing, regenerating Layer 0 snippets from their source messages, and deleting snippets.
  • Return hidden messages to the model context when their covering entry is deleted or disabled, unless another enabled entry still covers them.

UI

  • Engine selector: Flat / Layered.
  • Layer statistics and token estimate.
  • Snippet browser grouped by layer.
  • Injection preview.
  • Progress and errors for background runs.
  • Backlog detection with clear choices.
  • Import/export of layered memory and conversion of existing automated Chat Summary entries.

Scope and interactions

  • Roleplay only. Conversation and Game modes should not expose or call this mode.
  • Advanced Memory stays separate. When Advanced Memory is enabled, layered auto-summarization should not also inject a second memory system. The precedence or mutual exclusion must be explicit in the UI.
  • Flat Chat Summary remains the default and must keep working unchanged.
  • New UI copy must use semantic localization keys; docs must be updated with the feature.
  • The implementation should build on clear existing Chat Summary semantics:
    • Summary Scope must clearly state how many messages the summarizer reads;
    • "hide summarized messages" must clearly describe model-context exclusion, not visual hiding;
    • Recent message tail must behave as a strict limit for covered messages, or clearly report unsummarized backlog.

Out of scope

  • Conversation and Game modes.
  • Silent deletion of messages or summaries.
  • A new connection/provider system separate from existing Connections.
  • Changes to Advanced Memory's scene detection or character recollections.

Alternatives considered

  • Keep more verbatim turns. This delays the problem and increases cost; it does not bound the prompt.
  • Keep the flat summary list. This works for short chats but grows without a predictable ceiling and never compresses older summaries into denser context.
  • Rely only on semantic retrieval. Retrieval helps select relevant items but does not guarantee chronological coverage, and it can omit old context that still matters.
  • Use Advanced Memory for everything. Advanced Memory is scene-aware and intentionally more complex; a simpler layered mode is useful for users who want predictable turn-based compression without scene detection, audience rules, or recollections.
  • Store memory outside chat metadata. This would duplicate branch, import/export, and hidden-message handling that Chat Summary already has.

Additional context

  • The feature should reuse existing summary connection resolution, prompt assembly, hidden-from-AI storage, and summary entry normalization.
  • Existing chats must keep the current flat behavior unless the user explicitly selects the layered mode.
  • A layered mode should be testable without an LLM by exercising snippet selection, promotion decisions, checkpointing, and hide/unhide behavior.
  • Long-running catch-up must be resumable and must not block normal reply generation.
  • UI changes should be validated on desktop and mobile.
  • Implementation intent: I am willing to implement this myself and open a PR
    against staging. I can start once the scope is agreed. I have
    read CONTRIBUTING.md and will follow the repository's validation and review
    process.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @qvazzar on GitHub (Nov 4, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/8832 Originally assigned to: @SpicyMarinara on GitHub. ## What problem does this solve? Long Roleplay chats eventually exceed the model's useful context window. Users currently have three imperfect choices: - keep more raw messages, which consumes most of the prompt with atmospheric prose and degrades attention; - rely on a flat list of rolling summaries, where old entries stay separate and are never recursively compressed; - use semantic retrieval over summaries, which helps find relevant entries but does not guarantee chronological continuity or a predictable token budget. Marinara already has Chat Summary, automatic summaries, hidden-from-AI messages, summary connections, prompt markers, and Advanced Memory. However, the Roleplay Chat Summary path has no concept of a bounded, layered memory: old summaries remain a flat list, and there is no automatic promotion of older material into progressively denser summaries. This makes it difficult to keep a long chat both coherent and small in the prompt. The goal is a **layered summarization mode for Roleplay** that keeps recent turns verbatim, compresses older turns into short snippets, and recursively compresses old snippets into deeper layers. It should use Marinara's own storage and prompt pipeline rather than introducing a second parallel memory system. ## Proposed solution Add an optional **Layered** engine mode to the existing Roleplay **Chat Summary**: ### Core behavior - Keep the most recent N assistant turns word-for-word. - Summarize the oldest eligible turns into compact Layer 0 snippets. - When a layer reaches its snippet limit, promote its oldest snippets into the next layer: - the first promotion into an empty layer can move one snippet directly without an LLM call; - later promotions merge a configurable number of snippets with the destination layer's existing context. - Cascade promotions when the destination layer also overflows, up to a configurable maximum depth. - Preserve chronological order when compiling the prompt: deeper layers first, then Layer 0, then the verbatim tail. - Keep every original message. Summarized messages are hidden from the model only, never deleted or hidden from the user's chat view. ### Data model Reuse the existing `ChatSummaryEntry` storage shape where possible rather than adding a second list of memory records. Layered entries need enough metadata to identify: - the layer number; - whether the entry is a direct turn summary, a promotion, or a seed; - the source entries for a promotion; - the covered message IDs and hidden message IDs; - the usual enabled/disabled state and token estimate. `ChatMetadata` needs per-chat settings and a small checkpoint so an interrupted run can resume. ### Settings Per chat, at minimum: - verbatim assistant turns; - turns per snippet; - snippets per layer; - snippets per promotion; - maximum layers; - pause summarization; - hide summarized messages from model context; - selected prompt template. Global settings and templates: - system prompt; - user prompt with variables for persona name, prior context, and the new passage; - promotion prompt; - injection wrapper template; - narrative and game-state presets; - optional output-cleaning patterns. Reuse the existing **Summary Connection** and **Maximum output size** controls. ### Automatic behavior and recovery - After an assistant reply, process at most one new snippet per run, unless a backlog requires catch-up. - On failure, do not advance the checkpoint and do not hide the failed batch. - Support Force Summarize, Stop, catch-up, and a backlog prompt. - Support editing, regenerating Layer 0 snippets from their source messages, and deleting snippets. - Return hidden messages to the model context when their covering entry is deleted or disabled, unless another enabled entry still covers them. ### UI - Engine selector: Flat / Layered. - Layer statistics and token estimate. - Snippet browser grouped by layer. - Injection preview. - Progress and errors for background runs. - Backlog detection with clear choices. - Import/export of layered memory and conversion of existing automated Chat Summary entries. ### Scope and interactions - **Roleplay only.** Conversation and Game modes should not expose or call this mode. - **Advanced Memory stays separate.** When Advanced Memory is enabled, layered auto-summarization should not also inject a second memory system. The precedence or mutual exclusion must be explicit in the UI. - **Flat Chat Summary remains the default** and must keep working unchanged. - New UI copy must use semantic localization keys; docs must be updated with the feature. - The implementation should build on clear existing Chat Summary semantics: - Summary Scope must clearly state how many messages the summarizer reads; - "hide summarized messages" must clearly describe model-context exclusion, not visual hiding; - `Recent message tail` must behave as a strict limit for covered messages, or clearly report unsummarized backlog. ### Out of scope - Conversation and Game modes. - Silent deletion of messages or summaries. - A new connection/provider system separate from existing Connections. - Changes to Advanced Memory's scene detection or character recollections. ## Alternatives considered - **Keep more verbatim turns.** This delays the problem and increases cost; it does not bound the prompt. - **Keep the flat summary list.** This works for short chats but grows without a predictable ceiling and never compresses older summaries into denser context. - **Rely only on semantic retrieval.** Retrieval helps select relevant items but does not guarantee chronological coverage, and it can omit old context that still matters. - **Use Advanced Memory for everything.** Advanced Memory is scene-aware and intentionally more complex; a simpler layered mode is useful for users who want predictable turn-based compression without scene detection, audience rules, or recollections. - **Store memory outside chat metadata.** This would duplicate branch, import/export, and hidden-message handling that Chat Summary already has. ## Additional context - The feature should reuse existing summary connection resolution, prompt assembly, hidden-from-AI storage, and summary entry normalization. - Existing chats must keep the current flat behavior unless the user explicitly selects the layered mode. - A layered mode should be testable without an LLM by exercising snippet selection, promotion decisions, checkpointing, and hide/unhide behavior. - Long-running catch-up must be resumable and must not block normal reply generation. - UI changes should be validated on desktop and mobile. - **Implementation intent:** I am willing to implement this myself and open a PR against `staging`. I can start once the scope is agreed. I have read `CONTRIBUTING.md` and will follow the repository's validation and review process. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-11-07 16:43:28 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Nov 4, 2026):

Already covered by Advanced Memory Recall.

<!-- gh-comment-id:6636696028 --> @SpicyMarinara commented on GitHub (Nov 4, 2026): Already covered by Advanced Memory Recall.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8515
No description provided.