[GH-ISSUE #4791] [Feature]: Teach workspace Professor Mari to author well-parameterized lorebooks (not just Name+Content+keys) #2639

Closed
opened 2026-10-21 05:51:59 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @kolacheee on GitHub (Aug 9, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4791

Originally assigned to: @kolacheee on GitHub.

What problem does this solve?

When a user asks the workspace Home assistant (Professor Mari) to build a lorebook — e.g. "make a lorebook for the setting Vlad the vampire lives in" — she produces near-skeletal entries: Name + Content + a couple of keys, and essentially nothing else. She never marks an always-on premise (constant), never chooses placement (position/depth/order), never fills the description the Knowledge Router reads, and never groups mutually-exclusive alternatives. The result is functional-but-shallow world info that under-uses the engine's own capabilities.

The root cause is not the runtime — it is guidance and process. Her lorebook.create runtime already persists far more than she's told about:

  • buildLorebookEntryCreateRow (packages/server/src/services/mari-db/mari-db.service.ts:822-869) persists name, content, description, tag, keys, secondaryKeys, constant, position, depth, order, role, and group.
  • The book-level create (packages/server/src/services/mari-db/mari-db.service.ts:2467-2488) accepts scanDepth, tokenBudget, entryLimit, recursion, and vector knobs.

But her tool schema and prompt don't teach her to use any of it, and there is no authoring process that would surface the advanced parameters:

  • Her data field description (packages/server/src/services/professor-mari/workspace-agent.service.ts:406) lists only name, content, keys, secondaryKeys, tag, constant, position, depth, role, order for entries — it omits group and entry description (both accepted by the runtime), and lists only name, description, category, tags for the book (omitting every tuning knob).
  • The field list is names-only: it never explains what constant/position/depth/order do or when to reach for them.
  • Her single worked example — the "Verified lorebook creation sequence" (workspace-agent.service.ts:590, "The Glass City") — uses only name/content/keys, so she mirrors that skeletal shape.
  • Her guided lorebook flow (packages/server/src/services/professor-mari/guided-sequences.ts:6) goes straight from category/scope/topic chips to a one-shot lorebook.create — no self-informing step and no review pass in between.

Net: she is aware some advanced fields exist but has no idea what they mean, when to use them, or what a good lorebook looks like — and nothing prompts her to double-check her own work — so she defaults to the lowest-common-denominator entry every time. The most visible casualty is the "always-true setting premise" (e.g. "vampires are real; the year is 1890"), which needs constant: true: she has the field but is never told non-keyworded lore requires it, so premise facts get awkwardly keyworded or silently never fire.

Scope note: this is specifically about workspace-Mari (the Home agentic assistant). The legacy conversation-mode <create_lorebook> command is a separate, lower-capability surface that is effectively obsolete/legacy-only and is intentionally out of scope here.

Proposed solution — a lorebook-authoring loop, not just a schema tweak

The fix is a small authoring workflow plus the guidance to power it. All of it is prompt / guided-sequence / schema-doc work in workspace-agent.service.ts (+ guided-sequences.ts) — no engine changes are required; the runtime already persists every field, and the read-back + refine tools already exist (lorebook.entries, lorebook.getEntry, lorebook.updateEntry).

The loop:

  1. Plan the setting/entries first (content, not parameters): decide what entries exist — the world's premise, locations, characters, factions, rules — before touching how each is configured.
  2. Apply a baked decision heuristic (the workhorse — see below) to choose each entry's parameters as she writes it.
  3. Create the first-draft lorebook with lorebook.create (entries carrying the chosen parameters, not just name/content/keys).
  4. Offer a user-gated second-pass fidelity review. Ask the user whether they want Mari to review the draft for fidelity, rather than doing it automatically (the review is the expensive part; opt-in respects token/latency cost and keeps the user in control).
  5. On yes, review and refine. Read the draft back (lorebook.entries / lorebook.getEntry) and critique each entry's parameters against the heuristic, then lorebook.updateEntry to fix them — e.g. "this key is too broad → enable whole-word matching," "this fact is rarely typed in chat but doesn't deserve permanent tokens as constant → make it semantic instead," "these two entries are alternates → put them in one group." updateEntry already surfaces the user an in-chat Keep/Restore review card, which fits this pass well.

The guidance that powers it:

  1. Expand the data field description into a short field glossary (workspace-agent.service.ts:406): give each entry field a one-clause "what it does / when to use," and add the two fields the runtime already accepts but the schema omits — entry description (read by the Knowledge Router agent) and group (mutually-exclusive selection). Also surface the book-level tuning fields (scanDepth, tokenBudget, entryLimit, recursion, vectorization).
  2. Bake a COMPACT insertion-strategy decision heuristic into the prompt — the primary mechanism. Keep it tight (a handful of lines), e.g.: always-true premise/background → constant: true, no keys; topical detail → non-constant + 3–8 keys; ambiguous keyword that mis-fires → Selective + secondaryKeys (+ whole-word); rarely-typed-but-relevant → semantic (vectorization), not constant; alternates → same group; always fill description for the Knowledge Router. This is what she carries in-context; it needs zero doc round-trips for the common case.
  3. Add one well-parameterized worked example near the "Verified lorebook creation sequence" (workspace-agent.service.ts:590) — a constant: true premise entry + a keyworded location entry + a filled description + a deliberate placement/order choice — so she has a non-skeletal pattern to imitate.
  4. Point her at targeted docs for depth (supplement, not workhorse). For the deeper knobs (recursion, token budgets, semantic setup) she can consult the lorebook docs via docs_read — which supports section-level reads by exact heading (unit-tested). Curate the exact {path, heading} targets in the heuristic so she reads only the relevant section (~250–425 tokens each) instead of whole files (~12K tokens for the full lorebook doc set) and never fumbles the keyword search. This depends on the docs actually teaching parameter use with examples — companion issue #4792.

Execution & efficiency notes (from investigation)

  • The lorebook guidance is always-on, not relevance-injected. workspaceCommandProtocolPrompt() (workspace-agent.service.ts:529) has no task-conditional branching; it and MARI_SYSTEM_PROMPT are pushed as system messages on every workspace turn (workspace-agent.service.ts:2115-2116), regardless of task. So anything baked in is resident for character/persona/theme/preset turns too. Implication: keep the baked heuristic compact and lean on targeted docs for depth.
  • Do NOT build conditional/relevance injection to dodge the always-on cost. The prompt is currently a static, cacheable prefix; making it dynamic would sacrifice prompt-prefix caching (which is what makes an always-on block cheap on caching providers). Compact-and-static beats big-and-conditional. (Note workspace-Mari runs on the user's own connection, so on non-caching/local providers the block costs input tokens every turn — another reason to keep it lean.)
  • docs_read section targeting is real and tested (packages/server/src/services/professor-mari/documentation-tools.ts, exact case-insensitive heading match; scripts/regressions/professor-mari-documentation.regression.ts). docs_search is keyword (not semantic). Curate exact headings rather than trusting search wording. Also note entries.md (~11.6K chars) exceeds docs_read's default maxChars of 8,000, so whole-file reads truncate — another reason to target sections.

Alternatives considered

  • Widening the legacy conversation-mode <create_lorebook> command — declined; obsolete/legacy-only and lower-capability.
  • Engine-side defaults (e.g. auto-marking keyless entries constant) — rejected as too magic; better for Mari to choose explicitly and correctly, and the review pass catches mistakes.
  • Making docs_read heading match fuzzy (to reduce Heading not found dead-ends) — recommend against. It's a shared tool with a regression asserting exact-section isolation, and a fuzzy near-miss that returns the wrong section silently is worse than a clean throw. Safer paths to the same goal: curate exact headings in the baked heuristic (no tool change) and rely on the docs_search → docs_read handshake. If dead-ends need softening, prefer changing the miss behavior to return the file's available-heading list (a cheap TOC) rather than a bare throw — this preserves exact-match precision. (Left as a design decision for the implementer; not required for this feature.)
  • Automatic (non-gated) second pass — rejected; the review is the expensive step, so it should be user-opt-in.

Additional context

  • Companion issue: docs comprehension / examples / use-cases → #4792 (the targeted-docs step depends on it).
  • Evidence (file:line personally verified): schema field list workspace-agent.service.ts:406; skeletal example workspace-agent.service.ts:590; always-on prompt assembly workspace-agent.service.ts:529,2115-2116; runtime persists description + group mari-db.service.ts:822-869; book-level create accepts tuning knobs mari-db.service.ts:2467-2488; guided flow with no docs/review step guided-sequences.ts:6; docs tooling documentation-tools.ts + regression scripts/regressions/professor-mari-documentation.regression.ts. That description is read only by the Knowledge Router and that group makes entries mutually-exclusive is corroborated by the user docs themselves (docs/lorebooks/entries.md:44 and :117).
  • Manual verification when implemented: prompt an actual workspace-Mari build ("make a lorebook for <setting>") and confirm (a) the first draft carries a constant premise entry + keyed detail entries + filled descriptions, not name/content/keys only; (b) she offers a fidelity review rather than auto-running it; (c) on acceptance she reads the entries back and refines parameters (e.g. narrows an over-broad key, switches a rarely-typed constant to semantic). No automated harness models real model output here.

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 @kolacheee on GitHub (Aug 9, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4791 Originally assigned to: @kolacheee on GitHub. ## What problem does this solve? When a user asks the workspace Home assistant (Professor Mari) to build a lorebook — e.g. *"make a lorebook for the setting Vlad the vampire lives in"* — she produces near-skeletal entries: **Name + Content + a couple of keys, and essentially nothing else.** She never marks an always-on premise (`constant`), never chooses placement (`position`/`depth`/`order`), never fills the `description` the Knowledge Router reads, and never groups mutually-exclusive alternatives. The result is functional-but-shallow world info that under-uses the engine's own capabilities. The root cause is **not** the runtime — it is guidance and process. Her `lorebook.create` runtime already persists far more than she's told about: - `buildLorebookEntryCreateRow` (`packages/server/src/services/mari-db/mari-db.service.ts:822-869`) persists `name, content, description, tag, keys, secondaryKeys, constant, position, depth, order, role,` **and** `group`. - The book-level create (`packages/server/src/services/mari-db/mari-db.service.ts:2467-2488`) accepts `scanDepth, tokenBudget, entryLimit`, recursion, and vector knobs. But her tool schema and prompt don't teach her to use any of it, and there is no authoring process that would surface the advanced parameters: - Her `data` field description (`packages/server/src/services/professor-mari/workspace-agent.service.ts:406`) lists only `name, content, keys, secondaryKeys, tag, constant, position, depth, role, order` for entries — it **omits `group` and entry `description`** (both accepted by the runtime), and lists only `name, description, category, tags` for the book (omitting every tuning knob). - The field list is **names-only**: it never explains what `constant`/`position`/`depth`/`order` *do* or when to reach for them. - Her single worked example — the "Verified lorebook creation sequence" (`workspace-agent.service.ts:590`, "The Glass City") — uses **only** `name`/`content`/`keys`, so she mirrors that skeletal shape. - Her guided lorebook flow (`packages/server/src/services/professor-mari/guided-sequences.ts:6`) goes straight from category/scope/topic chips to a one-shot `lorebook.create` — **no self-informing step and no review pass** in between. Net: she is *aware some advanced fields exist* but has no idea what they mean, when to use them, or what a good lorebook looks like — and nothing prompts her to double-check her own work — so she defaults to the lowest-common-denominator entry every time. The most visible casualty is the "always-true setting premise" (e.g. "vampires are real; the year is 1890"), which needs `constant: true`: she has the field but is never told non-keyworded lore requires it, so premise facts get awkwardly keyworded or silently never fire. **Scope note:** this is specifically about **workspace-Mari** (the Home agentic assistant). The legacy conversation-mode `<create_lorebook>` command is a separate, lower-capability surface that is effectively obsolete/legacy-only and is intentionally **out of scope** here. ## Proposed solution — a lorebook-authoring loop, not just a schema tweak The fix is a small **authoring workflow** plus the guidance to power it. All of it is prompt / guided-sequence / schema-doc work in `workspace-agent.service.ts` (+ `guided-sequences.ts`) — **no engine changes** are required; the runtime already persists every field, and the read-back + refine tools already exist (`lorebook.entries`, `lorebook.getEntry`, `lorebook.updateEntry`). **The loop:** 1. **Plan the setting/entries first** (content, not parameters): decide *what* entries exist — the world's premise, locations, characters, factions, rules — before touching how each is configured. 2. **Apply a baked decision heuristic** (the workhorse — see below) to choose each entry's parameters as she writes it. 3. **Create the first-draft lorebook** with `lorebook.create` (entries carrying the chosen parameters, not just name/content/keys). 4. **Offer a user-gated second-pass fidelity review.** Ask the user whether they want Mari to review the draft for fidelity, rather than doing it automatically (the review is the expensive part; opt-in respects token/latency cost and keeps the user in control). 5. **On yes, review and refine.** Read the draft back (`lorebook.entries` / `lorebook.getEntry`) and critique each entry's parameters against the heuristic, then `lorebook.updateEntry` to fix them — e.g. *"this key is too broad → enable whole-word matching," "this fact is rarely typed in chat but doesn't deserve permanent tokens as `constant` → make it semantic instead," "these two entries are alternates → put them in one `group`."* `updateEntry` already surfaces the user an in-chat Keep/Restore review card, which fits this pass well. **The guidance that powers it:** 1. **Expand the `data` field description into a short field glossary** (`workspace-agent.service.ts:406`): give each entry field a one-clause "what it does / when to use," and add the two fields the runtime already accepts but the schema omits — entry `description` (read by the Knowledge Router agent) and `group` (mutually-exclusive selection). Also surface the book-level tuning fields (`scanDepth`, `tokenBudget`, `entryLimit`, recursion, vectorization). 2. **Bake a COMPACT insertion-strategy decision heuristic into the prompt** — the primary mechanism. Keep it tight (a handful of lines), e.g.: always-true premise/background → `constant: true`, no keys; topical detail → non-constant + 3–8 keys; ambiguous keyword that mis-fires → Selective + `secondaryKeys` (+ whole-word); rarely-typed-but-relevant → semantic (vectorization), not `constant`; alternates → same `group`; always fill `description` for the Knowledge Router. This is what she carries in-context; it needs **zero doc round-trips** for the common case. 3. **Add one well-parameterized worked example** near the "Verified lorebook creation sequence" (`workspace-agent.service.ts:590`) — a `constant: true` premise entry + a keyworded location entry + a filled `description` + a deliberate placement/order choice — so she has a non-skeletal pattern to imitate. 4. **Point her at targeted docs for depth (supplement, not workhorse).** For the deeper knobs (recursion, token budgets, semantic setup) she can consult the lorebook docs via `docs_read` — which supports **section-level reads by exact heading** (unit-tested). Curate the exact `{path, heading}` targets in the heuristic so she reads only the relevant section (~250–425 tokens each) instead of whole files (~12K tokens for the full lorebook doc set) and never fumbles the keyword search. **This depends on the docs actually teaching parameter use with examples — companion issue #4792.** ## Execution & efficiency notes (from investigation) - **The lorebook guidance is always-on, not relevance-injected.** `workspaceCommandProtocolPrompt()` (`workspace-agent.service.ts:529`) has no task-conditional branching; it and `MARI_SYSTEM_PROMPT` are pushed as system messages on **every** workspace turn (`workspace-agent.service.ts:2115-2116`), regardless of task. So anything baked in is resident for character/persona/theme/preset turns too. **Implication: keep the baked heuristic compact and lean on targeted docs for depth.** - **Do NOT build conditional/relevance injection** to dodge the always-on cost. The prompt is currently a static, cacheable prefix; making it dynamic would sacrifice prompt-prefix caching (which is what makes an always-on block cheap on caching providers). Compact-and-static beats big-and-conditional. (Note workspace-Mari runs on the *user's own* connection, so on non-caching/local providers the block costs input tokens every turn — another reason to keep it lean.) - **`docs_read` section targeting is real and tested** (`packages/server/src/services/professor-mari/documentation-tools.ts`, exact case-insensitive heading match; `scripts/regressions/professor-mari-documentation.regression.ts`). `docs_search` is keyword (not semantic). Curate exact headings rather than trusting search wording. Also note `entries.md` (~11.6K chars) exceeds `docs_read`'s default `maxChars` of 8,000, so whole-file reads truncate — another reason to target sections. ## Alternatives considered - **Widening the legacy conversation-mode `<create_lorebook>` command** — declined; obsolete/legacy-only and lower-capability. - **Engine-side defaults** (e.g. auto-marking keyless entries `constant`) — rejected as too magic; better for Mari to choose explicitly and correctly, and the review pass catches mistakes. - **Making `docs_read` heading match fuzzy** (to reduce `Heading not found` dead-ends) — **recommend against.** It's a shared tool with a regression asserting exact-section isolation, and a fuzzy near-miss that returns the *wrong* section silently is worse than a clean throw. Safer paths to the same goal: curate exact headings in the baked heuristic (no tool change) and rely on the `docs_search → docs_read` handshake. If dead-ends need softening, prefer changing the miss behavior to return the file's available-heading list (a cheap TOC) rather than a bare throw — this preserves exact-match precision. (Left as a design decision for the implementer; not required for this feature.) - **Automatic (non-gated) second pass** — rejected; the review is the expensive step, so it should be user-opt-in. ## Additional context - Companion issue: docs comprehension / examples / use-cases → #4792 (the targeted-docs step depends on it). - Evidence (file:line personally verified): schema field list `workspace-agent.service.ts:406`; skeletal example `workspace-agent.service.ts:590`; always-on prompt assembly `workspace-agent.service.ts:529,2115-2116`; runtime persists `description` + `group` `mari-db.service.ts:822-869`; book-level create accepts tuning knobs `mari-db.service.ts:2467-2488`; guided flow with no docs/review step `guided-sequences.ts:6`; docs tooling `documentation-tools.ts` + regression `scripts/regressions/professor-mari-documentation.regression.ts`. That `description` is read only by the Knowledge Router and that `group` makes entries mutually-exclusive is corroborated by the user docs themselves (`docs/lorebooks/entries.md:44` and `:117`). - **Manual verification when implemented:** prompt an actual workspace-Mari build ("make a lorebook for &lt;setting&gt;") and confirm (a) the first draft carries a `constant` premise entry + keyed detail entries + filled `description`s, not name/content/keys only; (b) she offers a fidelity review rather than auto-running it; (c) on acceptance she reads the entries back and refines parameters (e.g. narrows an over-broad key, switches a rarely-typed constant to semantic). No automated harness models real model output here. ## 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#2639
No description provided.