[GH-ISSUE #1505] [Issue]: refactor; lorebook retrievers are missing scoping options from main #753

Closed
opened 2026-10-20 17:32:56 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @jake9000 on GitHub (May 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1505

Originally assigned to: @SpicyMarinara on GitHub.

Summary

for #1482

On MAIN, there is a function which informs the RAG agents which lorebooks they can search. On REFACTOR, they are using a legacy method.

related: ebc75bab — "Implement chat-active lorebooks for knowledge agents"

I was kinda happy about this because I had previously made an extremely bad extension to get a similar effect.

Expected behavior

Only lorebooks that are linked to a chat (or a character/persona in a chat) should be in scope for the retrieval agents

Actual behavior

The retrieval agent utilizes all lorebooks that 'seem relevant.' In my case it meant that trackers would suddenly display an incorrect city name and I could not shake it no matter how many messages or tracker clears I clicked on. You can't have more than one active chat session utilizing a retrieval agent unless you want to reconfigure it every time you switch tabs.

Additional context

sorry but here is a quick ai output as well.

Here's the definitive comparison:

Main branch — ✅ Feature works as described

The flow in packages/server/src/routes/generate.routes.ts:

  1. resolveKnowledgeSourceLorebookIds() determines which lorebooks to source from:
  // packages/server/src/routes/generate/generate-route-utils.ts:89                                                                             
  export function resolveKnowledgeSourceLorebookIds(args) {                                                                                     
    if (manualIds.length > 0) return { sourceLorebookIds: manualIds };                                                                          
    if (settings.useChatActiveLorebooks === false) return { sourceLorebookIds: [] };                                                            
    // Otherwise: ONLY lorebooks linked to this chat                                                                                            
    return { sourceLorebookIds: chatActiveLorebookIds };                                                                                        
  }                                                                                                                                             
  1. Entries are loaded only from those lorebook IDs → formatted as source material → passed to executeKnowledgeRetrieval()
  2. The knowledge router additionally applies lorebookEntryPassesContextFilters() (character/tag/trigger gates) and per-chat entry state overrides

Unlinked lorebooks can never leak into knowledge retrieval on main.

Refactor branch — ❌ Not implemented

  • resolveKnowledgeSourceLorebookIds doesn't exist
  • _knowledgeRetrievalMaterial is never set
  • executeKnowledgeRetrieval() and executeKnowledgeRouter() are defined in /src/engine/agents-runtime/knowledge/ but never called
  • The knowledge agents run through the standard agent pipeline, which references <source_material> in its prompt but nothing populates it —
    they'd always produce "No relevant information found"

The lorebook-to-chat scope filter (lorebookAppliesToContext in prompt-assembly.ts) exists in refactor, but it only applies to the keyword-scan
activation pipeline, not to knowledge retrieval.

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 @jake9000 on GitHub (May 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/1505 Originally assigned to: @SpicyMarinara on GitHub. ## Summary for #1482 On MAIN, there is a function which informs the RAG agents which lorebooks they can search. On REFACTOR, they are using a legacy method. related: ebc75bab — "Implement chat-active lorebooks for knowledge agents" I was kinda happy about this because I had previously made an extremely bad extension to get a similar effect. ## Expected behavior Only lorebooks that are linked to a chat (or a character/persona in a chat) should be in scope for the retrieval agents ## Actual behavior The retrieval agent utilizes all lorebooks that 'seem relevant.' In my case it meant that trackers would suddenly display an incorrect city name and I could not shake it no matter how many messages or tracker clears I clicked on. You can't have more than one active chat session utilizing a retrieval agent unless you want to reconfigure it every time you switch tabs. ## Additional context sorry but here is a quick ai output as well. Here's the definitive comparison: Main branch — ✅ Feature works as described The flow in packages/server/src/routes/generate.routes.ts: 1. resolveKnowledgeSourceLorebookIds() determines which lorebooks to source from: ```ts // packages/server/src/routes/generate/generate-route-utils.ts:89 export function resolveKnowledgeSourceLorebookIds(args) { if (manualIds.length > 0) return { sourceLorebookIds: manualIds }; if (settings.useChatActiveLorebooks === false) return { sourceLorebookIds: [] }; // Otherwise: ONLY lorebooks linked to this chat return { sourceLorebookIds: chatActiveLorebookIds }; } ``` 2. Entries are loaded only from those lorebook IDs → formatted as source material → passed to executeKnowledgeRetrieval() 3. The knowledge router additionally applies lorebookEntryPassesContextFilters() (character/tag/trigger gates) and per-chat entry state overrides Unlinked lorebooks can never leak into knowledge retrieval on main. Refactor branch — ❌ Not implemented - resolveKnowledgeSourceLorebookIds doesn't exist - _knowledgeRetrievalMaterial is never set - executeKnowledgeRetrieval() and executeKnowledgeRouter() are defined in /src/engine/agents-runtime/knowledge/ but never called - The knowledge agents run through the standard agent pipeline, which references <source_material> in its prompt but nothing populates it — they'd always produce "No relevant information found" The lorebook-to-chat scope filter (lorebookAppliesToContext in prompt-assembly.ts) exists in refactor, but it only applies to the keyword-scan activation pipeline, not to knowledge retrieval. ## 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-10-20 17:32:56 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@SpicyMarinara commented on GitHub (May 29, 2026):

Addressed in b2cebc28 on refactor. Knowledge retrieval/router agents now use the dedicated knowledge executors with scoped source material from active chat lorebooks, chat-linked lorebooks, character/persona-linked lorebooks, or explicit agent source settings. Router candidates also pass the lorebook context filters before injection. Added regression tests for active-chat and active-character lorebook scoping.

<!-- gh-comment-id:4572042667 --> @SpicyMarinara commented on GitHub (May 29, 2026): Addressed in b2cebc28 on refactor. Knowledge retrieval/router agents now use the dedicated knowledge executors with scoped source material from active chat lorebooks, chat-linked lorebooks, character/persona-linked lorebooks, or explicit agent source settings. Router candidates also pass the lorebook context filters before injection. Added regression tests for active-chat and active-character lorebook scoping.
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#753
No description provided.