mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #6569] [Feature]: Let prompt conditionals ask the Decision model ({{#if decision:"..."}}) #3683
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#3683
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/6569
Originally assigned to: @kolacheee on GitHub.
What problem does this solve?
Conditional prompts (
{{#if}}, seedocs/prompts/conditional-prompts.md) can only test values Marinara already knows: names, card fields, preset variables, other macros. A preset or card cannot ask about what is happening in the scene. So authors either send every instruction every turn ("if a fight breaks out, ...", "if the scene moves, describe the new place", "if {{user}} asks a direct question, answer it first"), or they leave the instruction out.Sending everything every turn costs tokens, and it dilutes the prompt: a model that reads ten "if X then Y" rules on every turn follows all of them less well than one that reads the two that apply.
Marinara now has a Decision model setting (#6530, #6539, #6555) that answers a yes/no question about the recent messages in one cheap call: a hosted System One provider, the user's own local model, or a managed Open-Jev. Activation questions use it to decide whether a custom agent runs. The same answer could decide which branch of a conditional is sent.
Proposed solution
Syntax
A new condition operand,
decision:"question", next to the existingvar:name. Nothing about{{#if}}itself changes, so it keeps working with{{else}},{{else if}},&&,||, parentheses, nesting and group blocks.Written as a statement, the way activation questions are, because that is the shape the decision models are measured on.
What the operand means
defaultThresholdthe catalog already carries: 0.5 for a local chat model or a hosted connection, 0.1 for Open-Jev 2B. Probabilities are not comparable between models, so a threshold baked into a shared preset would be wrong for anyone on a different model.decision:"..." >= 0.3) are not supported at first, for the same reason. If they are added later, the docs have to say plainly that they tie the preset to one model.{{else}}branch is therefore the safe default, and an author can rely on it.{{char}},{{user}}and other identity macros inside the question are resolved before it is asked. In a group block, that makes one question per character, and all of them go in the same batch.How it runs
resolveMacrosis synchronous and has dozens of callers, including the client's previews, so the question cannot be asked while a condition is evaluated. The engine already has the mechanism this needs:deferConditionalOperand, which conversation relocation uses today.services/prompt/assembler.ts, called fromgenerate.routes.tsand from the Peek Prompt dry run) passes adeferConditionalOperandpredicate that also matchesdecision:operands. Each{{#if}}that names one is encoded as a private token, exactly as relocation conditionals are.collectDeferredRelocationConditionOperandsdoes for relocation (#3449 is why the same parse matters). Duplicates are merged.resolveDecisionBackend,buildDecisionState). Where possible, this is the same request as the turn's activation questions, since the state is the same recent transcript.selectConditionalPayloadBranchpicks each block's branch with the answers in the macro context. Any token left over is removed, as relocation tokens already are, so a private token can never reach a provider.Agent prompt templates (
services/agents/agent-executor.ts) get the same three steps, so custom agents and package agents that usepromptTemplategain the operand with no package change.What a prototype against the current engine showed
The defer hook was tried as-is against the shared macro engine:
resolveMacroswithdeferConditionalOperandmatchingdecision:, thencollectDeferredRelocationConditionOperandsandselectConditionalPayloadBranch. Plain blocks and mixed conditions (char == "Kaelen" && decision:"...") deferred and collected correctly. Three things need engine work first:decision:operand is currently true. It falls through to the generic operand path, resolves to its own literal text, and non-empty text passes the truthy check. The operand needs an explicit branch inresolveConditionalOperandthat reads the answer from the macro context and returns an empty value when there is none. A regression must pin "no answer means the{{else}}branch".expandBracketedCharacterBlockscallsresolveCharacterScopedMacros(block, profile, 0, ctx)without the resolve options, so adecision:condition inside[ ... ]is evaluated on the spot (and, per point 1, as true). Passing the options through defers each character's copy with that character's{{char}}already filled in. This is what makes "one question per character" work.generate.routes.ts, the relocation decode). A decision block sharing that token would be decoded there without its answer. A separate token prefix (or a kind field in the payload) keeps the two passes apart.The deferred payload also keeps the question as written, with
{{user}}unresolved. The collector resolves macros in the question with the turn's context before asking, and the decode step looks answers up by that same resolved text.Answers per turn, not per request
Answers are cached per chat and per latest message. Regenerating, swiping, Peek Prompt and the agent pipeline for that turn all see the same answers, and the chat is only asked again when a new message arrives. Without this, a swipe could flip a branch, and Peek Prompt would show a prompt that was never sent.
Peek Prompt uses the cached answers, and it never makes its own decision request. When nothing is cached yet, it shows the
{{else}}branch and a note that the branch is decided at generation. Client-side previews behave the same way.Limits and visibility
decision:, the import says so. The editor warns when content uses the operand but no Decision model is set.Alternatives considered
A new block tag (
{{#decision "..."}}...{{/decision}}). Clearer to read in isolation, but it would not combine with&&,||or{{else if}}without duplicating the conditional grammar, and every existing tool that understands{{#if}}(deferral, group blocks, trimming, editor highlighting) would need a second path.A value macro (
{{decision::question}}printing the probability). Useful for debugging. It is a poor fit for prompts on its own, since a model reading "0.84" learns nothing, and shared presets would then compare raw numbers. It could be added later for authors who want to see the value.Semantic lorebook activation instead. A lorebook entry that activates on a question instead of keywords is a good idea too. It is a different seam (activation, not content) and deserves its own issue. The operand already covers conditional content inside an entry that keywords have activated.
Choice questions. Marinara's decision client speaks Noul (yes/no) today. A Choice operand (
decision_choice:"mood" == "angry") could come later if authors ask for it.Additional context
What a decision model is
A decision model answers one kind of question. It is given the recent messages of a chat and a statement, such as "The latest message moves the scene to a new place", and it replies with how likely that statement is to be true: a number from 0 to 1. It does not write text and it never replies in the chat. Marinara compares that number with a threshold and treats the result as yes or no.
Because it only has to score one statement, a decision is short and cheap compared with a normal AI reply. A local model produces a single token, and a purpose-built decision model scores the statement in one pass.
There are three ways to have one, all chosen under Decision model in the Connections panel:
Marinara uses it in two places today. Activation questions decide whether a custom agent runs on a turn. Smart response order can use it to decide who speaks next in a group chat. This issue adds a third: choosing which part of a prompt is sent.
You do not need Jev or Open-Jev
A Decision model is whatever the user picked under Decision model, and for many users that will be the local model they already run. In the tests below, a Gemma 4 E4B running as the main local model answered every recommended statement correctly, with answers near 0 or 1. The purpose-built Open-Jev 2B got 31 of 32 right, with much thinner margins. A capable sidecar can match or beat a small decision model at this job.
Hosted Jev through OpenRouter and the managed Open-Jev are options, not requirements. Presets, cards and agents should be written for "a Decision model", never "requires Jev".
Small decision models can be wrong, so design for it
Open-Jev 2B missed one of the recommended statements even at its own calibrated threshold. Several of its correct "yes" answers sat between 0.18 and 0.5 against a threshold of 0.1, which leaves little room. Any model, large or small, will sometimes answer wrongly. Build so that a wrong answer costs little:
{{else}}that is fine on any turn.When a decision branch never fires (for prompt makers)
By design, a
decision:condition with no answer is false. That keeps a preset working for users without a Decision model, but it also means a decision branch can quietly never appear. When a user reports something like "the combat instructions never show up" or "I always get the calm version", the likely causes, in order, are:decision:condition is false on every turn. This is the most common case, and the editor warning is there to catch it.What to ask the user for:
The fix is rarely in the preset. If it is, it is usually the wording, or a branch that carries something the preset cannot do without. See "Small decision models can be wrong, so design for it" above.
Writing statements (measured)
Eight wording lessons, each a recommended statement against a pattern to avoid, were run through the engine's own decision code on labelled roleplay turns: Open-Jev 2B (object-shaped question, threshold 0.1) and a Gemma 4 E4B local sidecar (one-token method, Thinking off, threshold 0.5). Each statement saw four turns: two where the author means "yes" and two where the author means "no". That is a small, single-scene sample: read it as direction, not as a benchmark.
Totals: recommended statements scored 31/32 on Open-Jev 2B and 32/32 on the sidecar. The patterns to avoid scored 26/32 and 24/32.
Put simply, a good statement:
The last two lessons in the table did not show the problem they were expected to show. They are kept so authors do not constrain themselves for nothing.
What prompt makers could do with it
These are examples for the docs and for the announcement to preset and card authors. Each one sends an instruction only on the turns where it applies.
{{#if decision:"{{user}} asked a direct question in the latest message"}}Answer it before anything else.{{/if}}{{#if decision:"The previous reply repeats phrasing from earlier replies"}}Vary sentence openings and avoid repeating descriptions.{{/if}}{{#if decision:"{{char}} was addressed in the latest message"}}tells only the addressed character's section to respond directly.What agent contributors could do with it
promptTemplateget the operand automatically once the Engine supports it. The same examples apply to Illustrator (describe a new image only when the scene is visually different) or Music DJ (switch tracks only when the mood shifted), though the packages decide that in Pasta-Devs/Marinara-Agents.decision.ask). That is a separate, later change and needs a capability API version bump.A note for Game Mode Experience developers
Engine combat was recently updated with its own AI for non-boss enemies, the units on the GM's side of a fight. Each one gets:
All of this is chosen by Engine code from a seed, with no model call. The game's difficulty changes how consistently enemies play to type. Only authored bosses are directed by the GM through a model call.
More combat improvements are on the way. Before involving a decision model anywhere in the combat pipeline, check that vanilla Engine combat does not already do what you need. If an enemy needs a particular personality, give it the matching proficiency and temperament first. A decision call per enemy turn would add a network request, cost and a timeout to something the Engine settles locally and instantly. It would also make a fight depend on a model the user may not have set up, which by design reads as "no".
Honest limits to state in the docs
Suggested slices
decision:operand, the deferral predicate, collection, decode, the per-turn answer cache, and regressions. These cover truthy, false-on-unknown, macros inside questions, group-block expansion, the cap, and "no private token reaches a provider".conditional-prompts.md,macros.md, the custom agents page), the examples above, and the "When a decision branch never fires" troubleshooting section, so prompt makers can answer user reports without reading the code.Depends on #6530, #6539 and #6555, all merged. Implementation owner: @kolacheee.
Template check