mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #6570] [Feature]: Let lorebook entries activate on a Decision model statement #3685
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#3685
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Sep 23, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6570
Originally assigned to: @kolacheee on GitHub.
What problem does this solve?
Lorebook entries activate on keywords, on being constant, or on semantic similarity. None of these can tell what is happening from what is mentioned:
Since #6569,
{{#if decision:"..."}}already works inside an entry's content. But that only trims the text of an entry that has already activated. The entry still counts as active: it uses its share of the token budget, feeds recursion, and starts its sticky and cooldown timers. It cannot decide whether the entry activates at all.Proposed solution
Give each entry an optional Decision activation setting: a statement, like an agent's activation question, and a mode.
Two modes
dragon, statement "In the latest message, a dragon is physically present". It also makes a constant entry situational: a constant "Combat rules" entry with the statement "A fight is happening in the latest message".Mode Off (the default) keeps today's behavior. No answer reads as no, exactly like decision statements in prompts: a Require entry does not activate, and a Trigger entry is not triggered by the statement. With no Decision model, both modes behave as if the statement were false, so a Require entry never fires. The editor must say that plainly (see UI below).
Fields
On the entry (
packages/shared/src/schemas/lorebook.schema.ts,createLorebookEntrySchema, and the matching columns inpackages/server/src/db/schema/lorebooks.ts):decisionStatement: string, default"", at most 500 characters like an activation question. Macros such as{{char}}and{{user}}work, and a statement naming{{char}}in a group is asked per character, as in prompts.decisionMode: "off" | "require" | "trigger", default"off".Adding optional columns with defaults has not needed a storage-format bump before (for example
sourceMessageRefs, added in2dde0f6c0without one). Confirm that when implementing.How it runs
Entry matching is one synchronous pass:
scanForActivatedEntries()inpackages/server/src/services/lorebook/keyword-scanner.ts, orchestrated by the asyncprocessLorebooks()inpackages/server/src/services/lorebook/index.ts. Semantic matching already works around that by computing every embedding in one batch before the pass (buildLorebookSemanticEmbeddingsById()inservices/lorebook/embeddings.ts), then only looking results up inside it. Decision activation follows the same shape:decisionAnswersmap, and reports the entries that would activate but for an unanswered statement. An entry is reported only after its cheap checks pass: enabled, filters, activation conditions, schedule, timing (sticky, cooldown, delay), keywords for Require, and its probability roll. So a statement is never paid for when the entry would be skipped anyway.processLorebooks()asks the reported statements in one batch, through the same backend, per-turn cache and Decision statements per turn limit as prompt statements (services/decision/prompt-decisions.ts), then runs the pass again with the answers. Probability rolls are already shared across passes (probabilityDecisions), so the second pass sees the same rolls.Trigger statements do not depend on the scan, so they can join the turn's first decision batch (the one prompt statements already use in
generate.routes.ts), leaving the second batch for keyword-matched Require entries.Other rules:
"decision"inactivationSources, next tokeyword,semantic,constant,stickyandrecursive, and show it wherever those are shown (for example the lorebook activation list inpackages/client/src/components/chat/ChatRoleplayPanels.tsx).UI
In the entry editor (
packages/client/src/components/lorebooks/LorebookEntryRow.tsx, the activation area with the probability and timing fields), add a Decision row: an Off / Require / Trigger control copied from the existing selective-logic buttons, and a statement field. Reuse the existing pieces:DecisionStatementNotefor the "no Decision model is set" warning.docs/prompts/conditional-prompts.md.All strings go through the English catalog.
Import and export
extensionsso a round trip through Marinara keeps them; SillyTavern itself ignores them.packages/client/src/lib/decision-import-notice.ts) should also recognise entries with a Decision mode set.Docs
docs/lorebooks/entries.md: a section on Decision activation, with Require and Trigger examples, the cost difference, and the "no Decision model means a Require entry never fires" rule.docs/connections/decision-models.md: add it to "Where Marinara uses it".docs/prompts/conditional-prompts.md: point from the in-content{{#if decision}}section to this, and say when to use which (activation versus trimming an active entry's text).Alternatives considered
{{#if decision}}inside the content. Works today, but the entry still activates: it takes budget, feeds recursion and starts timers. Fine for trimming text, wrong for deciding activation.activationConditions. Conditions today compare game-state fields (evaluateConditions()inkeyword-scanner.ts) and pass when there is no game state. A decision is a different thing (asked, cached, cost-limited, can fail), and folding it into that list would hide the cost and the "no answer means no" rule.decision_choice) for entries, for example activating one of several location entries from a single "current location" question. Useful later. Yes/no covers the cases above with one field.Additional context
docs/connections/decision-models.md(added in the #6569 PR).Suggested slices
decisionAnswersand the pending report, the two-round ask inprocessLorebooks(), the"decision"activation source, and regressions: Require blocks without a yes, Trigger activates, sticky skips the ask, a failing model reads as no, the limit applies, previews never ask.Implementation owner: @kolacheee.
Template check