[GH-ISSUE #437] [Feature]: Lorebook Keeper: Multi-book routing and auto-creation to separate generic world lore from scene-specific data #224

Closed
opened 2026-10-20 17:25:32 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @szaki2 on GitHub (Aug 19, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/437

Originally assigned to: @SpicyMarinara on GitHub.

What problem does this solve?

The Lorebook Keeper currently writes ALL entries to a single target lorebook (preferredTargetLorebookId or writableLorebookIds[0]). This means scene-specific data (NPCs that only exist in this story, events that happened in this chat, player character details) gets dumped into the same lorebook as generic world lore (setting rules, mechanics, factions, cultures).

This corrupts the world book. A user's carefully curated generic world lorebook — designed to be reusable across any RP set in that world — becomes polluted with scene-specific entries from one particular playthrough. The world book is no longer clean, portable, or reusable for other stories set in the same setting.

The user cannot prevent this. Even with multiple lorebooks linked to the chat, the keeper ignores all but one. There is no way to say "world rules go here, NPC data goes there, scene events go somewhere else."
Proposed package or change

Add three capabilities to the Lorebook Keeper executor:

  1. Inject writable lorebook list into the prompt

The executor already injects <existing_entries> for the target book. It should also inject a <writable_lorebooks> block listing all writable lorebooks by name and ID, so the LLM knows what books exist and can target them:
<writable_lorebooks>
[0] "World Lore" (id: abc123)
[1] "NPC Registry" (id: def456)
[2] "Scene Log" (id: ghi789)
</writable_lorebooks>

When the LLM creates a new book with create_lorebook, that book appears in <writable_lorebooks> on the next turn so the LLM can target it directly.
2. Multi-book targeting via targetLorebook field

Add an optional targetLorebook field to the keeper's JSON output schema. When present, the executor routes the entry to the matching lorebook from writableLorebookIds:
json{
"updates": [
{
"action": "create",
"targetLorebook": "world",
"entryName": "Magic System Rules",
"content": "...",
"keys": ["magic", "spell"],
"tag": "lore",
"reason": "Generic world mechanic — belongs in the world book"
},
{
"action": "create",
"targetLorebook": "scene",
"entryName": "Tavern Keeper",
"content": "...",
"keys": ["tavern", "keeper"],
"tag": "character",
"reason": "Scene-specific NPC — belongs in the scene book"
}
]
}

The targetLorebook value matches a lorebook by:
Exact name match (e.g. "My World — World Lore")
Or a shorter alias/tag the user sets in the agent config (e.g. "world", "npc", "scene", "player")

When targetLorebook is absent, behavior stays as-is (write to preferred/first target) — fully backward compatible.

The classification logic (which category a fact belongs to) happens entirely in the custom promptTemplate — the executor just reads the targetLorebook field and routes accordingly. This keeps the server change minimal.
3. Auto-create missing lorebooks

When the keeper outputs targetLorebook: "npc" but no lorebook with that alias exists yet, the executor creates one automatically using a naming scheme from the agent config:
Agent config gets a lorebookNamingScheme field, e.g.:
json{
"lorebookNamingScheme": {
"world": "[WorldName] — World Lore",
"npc": "[WorldName] — NPC Registry",
"scene": "[WorldName] — Scene Log",
"player": "[WorldName] — Player Character"
}
}
[WorldName] is extracted from the character card name, scenario, or first message
The new lorebook is auto-linked to the current chat and added to writableLorebookIds

This makes the keeper fully autonomous — it discovers a fact, classifies it via the prompt, checks if the target book exists, creates it if not, then writes the entry there. No user pre-setup required.

Supports Roleplay mode (same as current keeper). No Game Mode change needed. Requires server code change in the executor and a small agent config schema addition for the naming scheme.
Why should this be optional?

Most users have one lorebook and don't need routing. Backward compatible — no targetLorebook field means write to the default book as before. The naming scheme and alias mapping add config complexity that casual users don't need. Keeping it in the downloadable agent package lets advanced users opt in without burdening the default experience.
Alternatives considered
Server-side classification — Executor reads the tag field and routes automatically. Rejected: the LLM is better at deciding what's generic vs scene-specific. Routing belongs in the prompt, not in code.
Manual splitting after the fact — Rejected: the world book is already polluted by the time you clean up.
Multiple keeper instances — Rejected: multiplies token cost and still can't target different books without this change.
Additional context

The client already handles lorebook_created actions, so auto-creation of lorebooks from agent output has precedent in the codebase.
Template check

I DID NOT read this template and provide the requested details.

Originally created by @szaki2 on GitHub (Aug 19, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Agents/issues/437 Originally assigned to: @SpicyMarinara on GitHub. What problem does this solve? The Lorebook Keeper currently writes ALL entries to a single target lorebook (preferredTargetLorebookId or writableLorebookIds[0]). This means scene-specific data (NPCs that only exist in this story, events that happened in this chat, player character details) gets dumped into the same lorebook as generic world lore (setting rules, mechanics, factions, cultures). This corrupts the world book. A user's carefully curated generic world lorebook — designed to be reusable across any RP set in that world — becomes polluted with scene-specific entries from one particular playthrough. The world book is no longer clean, portable, or reusable for other stories set in the same setting. The user cannot prevent this. Even with multiple lorebooks linked to the chat, the keeper ignores all but one. There is no way to say "world rules go here, NPC data goes there, scene events go somewhere else." Proposed package or change Add three capabilities to the Lorebook Keeper executor: 1. Inject writable lorebook list into the prompt The executor already injects <existing_entries> for the target book. It should also inject a <writable_lorebooks> block listing all writable lorebooks by name and ID, so the LLM knows what books exist and can target them: <writable_lorebooks> [0] "World Lore" (id: abc123) [1] "NPC Registry" (id: def456) [2] "Scene Log" (id: ghi789) </writable_lorebooks> When the LLM creates a new book with create_lorebook, that book appears in <writable_lorebooks> on the next turn so the LLM can target it directly. 2. Multi-book targeting via targetLorebook field Add an optional targetLorebook field to the keeper's JSON output schema. When present, the executor routes the entry to the matching lorebook from writableLorebookIds: json{ "updates": [ { "action": "create", "targetLorebook": "world", "entryName": "Magic System Rules", "content": "...", "keys": ["magic", "spell"], "tag": "lore", "reason": "Generic world mechanic — belongs in the world book" }, { "action": "create", "targetLorebook": "scene", "entryName": "Tavern Keeper", "content": "...", "keys": ["tavern", "keeper"], "tag": "character", "reason": "Scene-specific NPC — belongs in the scene book" } ] } The targetLorebook value matches a lorebook by: Exact name match (e.g. "My World — World Lore") Or a shorter alias/tag the user sets in the agent config (e.g. "world", "npc", "scene", "player") When targetLorebook is absent, behavior stays as-is (write to preferred/first target) — fully backward compatible. The classification logic (which category a fact belongs to) happens entirely in the custom promptTemplate — the executor just reads the targetLorebook field and routes accordingly. This keeps the server change minimal. 3. Auto-create missing lorebooks When the keeper outputs targetLorebook: "npc" but no lorebook with that alias exists yet, the executor creates one automatically using a naming scheme from the agent config: Agent config gets a lorebookNamingScheme field, e.g.: json{ "lorebookNamingScheme": { "world": "[WorldName] — World Lore", "npc": "[WorldName] — NPC Registry", "scene": "[WorldName] — Scene Log", "player": "[WorldName] — Player Character" } } [WorldName] is extracted from the character card name, scenario, or first message The new lorebook is auto-linked to the current chat and added to writableLorebookIds This makes the keeper fully autonomous — it discovers a fact, classifies it via the prompt, checks if the target book exists, creates it if not, then writes the entry there. No user pre-setup required. Supports Roleplay mode (same as current keeper). No Game Mode change needed. Requires server code change in the executor and a small agent config schema addition for the naming scheme. Why should this be optional? Most users have one lorebook and don't need routing. Backward compatible — no targetLorebook field means write to the default book as before. The naming scheme and alias mapping add config complexity that casual users don't need. Keeping it in the downloadable agent package lets advanced users opt in without burdening the default experience. Alternatives considered Server-side classification — Executor reads the tag field and routes automatically. Rejected: the LLM is better at deciding what's generic vs scene-specific. Routing belongs in the prompt, not in code. Manual splitting after the fact — Rejected: the world book is already polluted by the time you clean up. Multiple keeper instances — Rejected: multiplies token cost and still can't target different books without this change. Additional context The client already handles lorebook_created actions, so auto-creation of lorebooks from agent output has precedent in the codebase. Template check I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:25:32 +07:00
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-Agents#224
No description provided.