[GH-ISSUE #8359] [Feature]: Skip built-in memory recall when Long-Term Memory is on, and put its text in the conversation memories slot #8293

Closed
opened 2026-10-27 06:07:03 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Promansis on GitHub (Oct 26, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/8359

Originally assigned to: @Promansis on GitHub.

What problem does this solve?

When the Long-Term Memory agent is on for a chat, a turn can get memories from two systems at once:

  • Built-in memory recall. This is the memory_chunks transcript search, injected by injectMemoryRecallContext. It is on by default in conversation mode and scene chats, and opt-in for roleplay.
  • Long-Term Memory recall (recallLongTermMemory).

Nothing dedupes the two. In a conversation chat with Long-Term Memory on, the prompt carries the built-in block in the memories slot and the Long-Term Memory block as a separate agent injection. Often they describe the same past events in two formats. The turn also runs two embedding passes over the same history.

Advanced Memory already avoids this in roleplay and game: !advancedMemoryEnabled gates built-in recall in the generate route, and the memory-recall-exclusivity regression keeps the two settings apart. Long-Term Memory has no such rule.

Regenerate is uneven too. Long-Term Memory recall skips regenerated turns (!input.regenerateMessageId), but built-in recall does not. A regenerated reply in a Long-Term Memory chat therefore gets a different memory source from the reply it replaces.

Proposed solution

When Long-Term Memory is active for a chat's turn, Long-Term Memory replaces built-in recall in the prompt. Chats without it are unchanged. This is a host-only change to the generate route; the package needs no change for it.

References are to packages/server/src/routes/generate.routes.ts at 5b7d81b83.

  1. One predicate. Name the existing check once: longTermMemoryActive = chatEnableAgents && chatActiveAgentIds.includes("long-term-memory"). It is already evaluated early, at about line 3254, where the runtime section is made eligible.

  2. Skip built-in prompt recall when it is true. This covers both injectMemoryRecallContext prompt paths in the "Memory recall" block (about lines 5779-5830):

    • the conversation-mode memories slot path;
    • the roleplay/scene path behind !advancedMemoryEnabled.

    The following stay unchanged:

    • conversationImportantMemoryBlock;
    • background transcript chunking (chunkAndEmbedMessages), so built-in recall still works if Long-Term Memory is turned off later;
    • the custom-agent access_vectors path. It passes messages: [], feeds only custom agents and never reaches the main prompt. The same goes for its twin in routes/generate/retry-agents-route.ts.
  3. Conversation mode: put Long-Term Memory's text in the memories slot.

    • When the preset has a memories slot (conversationContextMacroSlots.memories): call recallLongTermMemory inside that block. Join its text after conversationImportantMemoryBlock into conversationMemoriesBlockValue, so {{#if memories}} and the deferred relocation decode (#3448) see it. Then skip the later injection at about line 7792 for that turn.
    • Inputs are already in place. Every input the call uses is declared before line 5779: agentSignal, roleplayTimeline, agentWhisperNames, conversationRecallHistory and promptCharacterIds.
    • Everywhere else, placement is unchanged. Roleplay, game, and conversation presets without the slot keep today's preset-section or fallback placement.
  4. Regenerate. The built-in skip uses longTermMemoryActive without the regenerate clause, so a regenerated turn never falls back to built-in recall. For regenerated turns, the proposal is:

    • Long-Term Memory recall also runs, with includeRecallHistory (about line 4158) relaxed the same way.
    • The turn still skips recordLongTermMemoryPromptAccepted: leave the receipt undefined on regenerate, as today, so the package's usage counts are not doubled.
  5. Regression. Put the decision in a small exported helper, in the style of resolveRetryAgentContextPolicy. Inputs: chat mode, Long-Term Memory active, Advanced Memory enabled, recall setting, vectorizer available, has memories slot, regenerate. It returns which recall runs and where Long-Term Memory's text goes. Add a scripts/regressions/ case for:

    • Long-Term Memory on: no built-in prompt recall, including on regenerate;
    • Long-Term Memory off: today's behaviour;
    • conversation with a memories slot: slot placement;
    • conversation without the slot, and roleplay: agent placement.

Second part (small, same area). Add persistence.listChatSummaries(chatId) to services/capability-packages/capability-persistence.service.ts. It would return the chat's day, week, rolling (summaryEntries) and game-session summaries (gamePreviousSessionSummaries). The shapes are in packages/shared/src/types/chat.ts. Long-Term Memory reads these today from raw chat metadata through getChat. A declared method would turn that into a contract the package can test against.

Alternatives considered

  • Dedupe the two blocks by text. Built-in recall returns transcript fragments and Long-Term Memory returns extracted notes. The two rarely match word for word, and both embedding passes would still run.
  • A settings-level exclusivity rule like Advanced Memory's (flip enableMemoryRecall off when the agent is turned on). Long-Term Memory is turned on per chat through the agent list, not a chat setting. Rewriting the user's recall setting would also stick after Long-Term Memory is turned off. A per-turn gate leaves the setting alone.
  • No recall on regenerated turns. Consistent, but a regenerated reply would lose the memory context its original had.
  • Let the package turn built-in recall off itself. The package has no capability for it and should not get one: prompt assembly is the host's job.

Additional context

  • The Long-Term Memory side waits on this. Its next minor release adds the chat transcript as a recall source and raises engine.min to the Engine release that ships this change. Until then, a chat that uses both would recall the transcript twice.
  • generate.routes.ts is still being split (#7686). If the memory-recall block moves first, the steps above apply to wherever it lands.
  • Proof for the PR: one conversation turn with Long-Term Memory on shows exactly one memories block, holding Long-Term Memory's text in the memories slot. The same turn with it off shows today's built-in block. A regenerated turn with it on shows no built-in block.

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 @Promansis on GitHub (Oct 26, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/8359 Originally assigned to: @Promansis on GitHub. ## What problem does this solve? When the Long-Term Memory agent is on for a chat, a turn can get memories from two systems at once: - **Built-in memory recall.** This is the `memory_chunks` transcript search, injected by `injectMemoryRecallContext`. It is on by default in conversation mode and scene chats, and opt-in for roleplay. - **Long-Term Memory recall** (`recallLongTermMemory`). Nothing dedupes the two. In a conversation chat with Long-Term Memory on, the prompt carries the built-in block in the `memories` slot and the Long-Term Memory block as a separate agent injection. Often they describe the same past events in two formats. The turn also runs two embedding passes over the same history. Advanced Memory already avoids this in roleplay and game: `!advancedMemoryEnabled` gates built-in recall in the generate route, and the `memory-recall-exclusivity` regression keeps the two settings apart. Long-Term Memory has no such rule. Regenerate is uneven too. Long-Term Memory recall skips regenerated turns (`!input.regenerateMessageId`), but built-in recall does not. A regenerated reply in a Long-Term Memory chat therefore gets a different memory source from the reply it replaces. ## Proposed solution When Long-Term Memory is active for a chat's turn, Long-Term Memory replaces built-in recall in the prompt. Chats without it are unchanged. This is a host-only change to the generate route; the package needs no change for it. References are to `packages/server/src/routes/generate.routes.ts` at 5b7d81b83. 1. **One predicate.** Name the existing check once: `longTermMemoryActive = chatEnableAgents && chatActiveAgentIds.includes("long-term-memory")`. It is already evaluated early, at about line 3254, where the runtime section is made eligible. 2. **Skip built-in prompt recall when it is true.** This covers both `injectMemoryRecallContext` prompt paths in the "Memory recall" block (about lines 5779-5830): - the conversation-mode `memories` slot path; - the roleplay/scene path behind `!advancedMemoryEnabled`. The following stay unchanged: - `conversationImportantMemoryBlock`; - background transcript chunking (`chunkAndEmbedMessages`), so built-in recall still works if Long-Term Memory is turned off later; - the custom-agent `access_vectors` path. It passes `messages: []`, feeds only custom agents and never reaches the main prompt. The same goes for its twin in `routes/generate/retry-agents-route.ts`. 3. **Conversation mode: put Long-Term Memory's text in the `memories` slot.** - **When the preset has a `memories` slot** (`conversationContextMacroSlots.memories`): call `recallLongTermMemory` inside that block. Join its text after `conversationImportantMemoryBlock` into `conversationMemoriesBlockValue`, so `{{#if memories}}` and the deferred relocation decode (#3448) see it. Then skip the later injection at about line 7792 for that turn. - **Inputs are already in place.** Every input the call uses is declared before line 5779: `agentSignal`, `roleplayTimeline`, `agentWhisperNames`, `conversationRecallHistory` and `promptCharacterIds`. - **Everywhere else, placement is unchanged.** Roleplay, game, and conversation presets without the slot keep today's preset-section or fallback placement. 4. **Regenerate.** The built-in skip uses `longTermMemoryActive` without the regenerate clause, so a regenerated turn never falls back to built-in recall. For regenerated turns, the proposal is: - Long-Term Memory recall also runs, with `includeRecallHistory` (about line 4158) relaxed the same way. - The turn still skips `recordLongTermMemoryPromptAccepted`: leave the receipt `undefined` on regenerate, as today, so the package's usage counts are not doubled. 5. **Regression.** Put the decision in a small exported helper, in the style of `resolveRetryAgentContextPolicy`. Inputs: chat mode, Long-Term Memory active, Advanced Memory enabled, recall setting, vectorizer available, has `memories` slot, regenerate. It returns which recall runs and where Long-Term Memory's text goes. Add a `scripts/regressions/` case for: - Long-Term Memory on: no built-in prompt recall, including on regenerate; - Long-Term Memory off: today's behaviour; - conversation with a `memories` slot: slot placement; - conversation without the slot, and roleplay: agent placement. **Second part (small, same area).** Add `persistence.listChatSummaries(chatId)` to `services/capability-packages/capability-persistence.service.ts`. It would return the chat's day, week, rolling (`summaryEntries`) and game-session summaries (`gamePreviousSessionSummaries`). The shapes are in `packages/shared/src/types/chat.ts`. Long-Term Memory reads these today from raw chat metadata through `getChat`. A declared method would turn that into a contract the package can test against. ## Alternatives considered - **Dedupe the two blocks by text.** Built-in recall returns transcript fragments and Long-Term Memory returns extracted notes. The two rarely match word for word, and both embedding passes would still run. - **A settings-level exclusivity rule like Advanced Memory's** (flip `enableMemoryRecall` off when the agent is turned on). Long-Term Memory is turned on per chat through the agent list, not a chat setting. Rewriting the user's recall setting would also stick after Long-Term Memory is turned off. A per-turn gate leaves the setting alone. - **No recall on regenerated turns.** Consistent, but a regenerated reply would lose the memory context its original had. - **Let the package turn built-in recall off itself.** The package has no capability for it and should not get one: prompt assembly is the host's job. ## Additional context - The Long-Term Memory side waits on this. Its next minor release adds the chat transcript as a recall source and raises `engine.min` to the Engine release that ships this change. Until then, a chat that uses both would recall the transcript twice. - `generate.routes.ts` is still being split (#7686). If the memory-recall block moves first, the steps above apply to wherever it lands. - Proof for the PR: one conversation turn with Long-Term Memory on shows exactly one memories block, holding Long-Term Memory's text in the `memories` slot. The same turn with it off shows today's built-in block. A regenerated turn with it on shows no built-in block. ## 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.
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#8293
No description provided.