[GH-ISSUE #6569] [Feature]: Let prompt conditionals ask the Decision model ({{#if decision:"..."}}) #3683

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

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}}, see docs/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 existing var:name. Nothing about {{#if}} itself changes, so it keeps working with {{else}}, {{else if}}, &&, ||, parentheses, nesting and group blocks.

{{#if decision:"The latest message moves the scene to a new place"}}
Open your reply by describing the new location in one or two sentences.
{{/if}}
{{#if decision:"A fight is happening or about to start"}}
Keep combat readable: one action per character, name who is hurt and how badly.
{{else if decision:"The characters are resting or talking calmly"}}
Slow down. Let the characters notice small details.
{{/if}}
{{#if char == "Dottore" && decision:"{{user}} is lying or hiding something"}}
Dottore notices the inconsistency and files it away.
{{/if}}

Written as a statement, the way activation questions are, because that is the shape the decision models are measured on.

What the operand means

  • It is true when the Decision model's probability meets that model's own threshold, the calibrated defaultThreshold the 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.
  • Numeric comparisons (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.
  • It is false when there is no answer: no Decision model is set, the request timed out or failed, or the model is a reasoning model that defers in front of the reply. The {{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

resolveMacros is 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.

  1. Defer. Prompt assembly (services/prompt/assembler.ts, called from generate.routes.ts and from the Peek Prompt dry run) passes a deferConditionalOperand predicate that also matches decision: operands. Each {{#if}} that names one is encoded as a private token, exactly as relocation conditionals are.
  2. Collect. After assembly, the route reads the questions out of those tokens with the same parser that deferred them, as collectDeferredRelocationConditionOperands does for relocation (#3449 is why the same parse matters). Duplicates are merged.
  3. Ask once. All questions for the turn go to the Decision model in one batched request, the same shape activation questions already use (resolveDecisionBackend, buildDecisionState). Where possible, this is the same request as the turn's activation questions, since the state is the same recent transcript.
  4. Decode. selectConditionalPayloadBranch picks 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 use promptTemplate gain 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: resolveMacros with deferConditionalOperand matching decision:, then collectDeferredRelocationConditionOperands and selectConditionalPayloadBranch. Plain blocks and mixed conditions (char == "Kaelen" && decision:"...") deferred and collected correctly. Three things need engine work first:

  1. An unknown 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 in resolveConditionalOperand that 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".
  2. Group blocks bypass the defer hook. expandBracketedCharacterBlocks calls resolveCharacterScopedMacros(block, profile, 0, ctx) without the resolve options, so a decision: 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.
  3. Decision blocks need their own token kind. The conversation route decodes every relocation token that does not name a relocation operand using its own context (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

  • Budget. Same timeouts as activation questions: 1.5 s for a hosted connection, 4 s for a local model. These decisions sit in front of the reply, so a model that has to reason first defers unless the user has opted into pre-generation gating.
  • Cap. At most 16 unique questions per turn. Beyond the cap, the remaining conditions are false and a warning is logged. An imported card or preset should not be able to run up a hosted bill.
  • Import. When an imported preset, card or lorebook uses decision:, the import says so. The editor warns when content uses the operand but no Decision model is set.
  • Debug logging. Each question and answer is logged at debug level with the branch it chose, alongside the existing decision request logging.

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:

  • The local model you already run, on the main or utility local slot. Nothing to download or pay for.
  • A hosted Decision connection: a System One provider such as TypeSafe's Jev, directly or through OpenRouter.
  • The installable decision model (Open-Jev), on a Linux PC with an NVIDIA GPU.

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:

  • Use a decision to add or trim guidance, never to carry content the story depends on. A missed branch should make a reply slightly less tailored, not break it.
  • Give every decision block a sensible default: either nothing, or an {{else}} that is fine on any turn.
  • Do not chain decisions so that one wrong answer changes several others.
  • Do not use a decision to gate consent, content warnings or safety instructions. Keep those deterministic or always present.
  • For an agent that only runs on a decision, set Bypass the question after this many messages so a model that keeps answering "no" cannot silence it forever.
  • Test with Test and on your own chats. The same statement can score very differently on different models.

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:

  1. No Decision model is set. Decision model is None (the default), so every decision: condition is false on every turn. This is the most common case, and the editor warning is there to catch it.
  2. Their Decision model is not answering. A hosted connection with a bad key, no credits or a rate limit; a local model that is stopped, or too slow for the budget (1.5 seconds hosted, 4 seconds local); or an installed decision model that failed to start. Any of these makes the condition fall back to false.
  3. Their Decision model is a reasoning model. A local model that has to think first defers in front of the reply, unless the user turned on Also gate agents that run before the reply.
  4. The turn asked too many questions. Past 16 unique questions in one turn, the rest read false.
  5. It answers, but below the threshold. Either the wording (see "Writing statements" below) or a model that rates that turn lower than you expect. Small models are more likely to.

What to ask the user for:

  • Which Decision model they have selected, and what Test next to it reports.
  • Peek Prompt for the turn: it shows which branch was actually sent, and marks decision branches that had no answer.
  • Debug logs, if they are willing: each question, its answer and the chosen branch are logged at debug level.

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.

Lesson Recommended Avoid Recommended score (2B / sidecar) Avoid score (2B / sidecar) What happened
A statement, not a question "The latest message moves the scene to a new place." "Did the scene change?" 4/4, 4/4 2/4, 4/4 The question pushed Open-Jev 2B's "no" answers over its threshold (0.10 and 0.13). The sidecar was unaffected.
Observable, not a judgement "In the latest message, a character draws a weapon or attacks someone." "The scene is intense." 4/4, 4/4 3/4, 3/4 Both called a heated argument "intense" (2B 0.74, sidecar 0.999). With a vague word, the model decides what it means, not the author.
About the latest message, not the whole chat "In the latest message, Mira asks Kaelen a direct question." "Mira asks questions." 4/4, 4/4 3/4, 2/4 The sidecar said yes (0.9999 and 0.9986) when Mira's latest message asked nothing, because an earlier message did.
Names, not pronouns "Kaelen is angry in the latest message." "He is angry." 4/4, 4/4 4/4, 3/4 The sidecar read "he" as the angry barkeep (0.98) when the author meant Kaelen.
Checkable in the text, not a hidden mental state "In the latest message, Mira says something that contradicts what she said earlier." "Mira is lying." 3/4, 4/4 2/4, 2/4 Neither model reliably called a contradiction "lying" (sidecar 0.41 and 0.03 on the two contradictions). 2B's one miss on the recommended form was 0.076, just under its 0.1 threshold.
A statement, not an instruction "The latest message moves the scene to a new place." "If the scene changed, describe the new location in two sentences." 4/4, 4/4 4/4, 2/4 The sidecar answered no to the instruction every time (0.001 to 0.002). An instruction is not true or false, so the block never fires.
One thing per statement "Someone is injured in the latest message." "A fight starts and someone is injured and the city guards arrive." 4/4, 4/4 4/4, 4/4 Both handled a three-part "and" correctly. Splitting is still easier to reuse and debug, but it did not fail here.
Positive, not negated "In the latest message, the characters stay in the same place." "The characters did not leave the room." 4/4, 4/4 4/4, 4/4 No difference. Open-Jev 2B actually separated the negated form more widely (0.69 against 0.18 for yes). Write whichever reads naturally.

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:

  • states a fact that is either true or false, in the present tense, like a line in a report, not a question or an instruction;
  • says "in the latest message" when it is about this turn, because the model sees several messages;
  • names who it is about, and does not use "he", "she" or "they";
  • describes something visible in the text, an action or a statement, not a mood word the model must interpret, and not a hidden intention like lying or secretly wanting;
  • stays short. One idea is easiest to test and reuse, though a plain "and" did not break either model here.

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.

  • Scene changes. Describe a new location or time skip only when the scene actually moved, instead of telling the model "if the scene changes, describe it" every turn.
  • Combat, intimacy, tension. Load the relevant pacing or formatting rules only while that kind of scene is happening.
  • Answer the question first. {{#if decision:"{{user}} asked a direct question in the latest message"}}Answer it before anything else.{{/if}}
  • Anti-repetition. {{#if decision:"The previous reply repeats phrasing from earlier replies"}}Vary sentence openings and avoid repeating descriptions.{{/if}}
  • Card-level moods. A character card can hold "when flustered" or "when angry" behavior that only appears when the recent messages show it.
  • Pacing guards. A slow-burn preset can hold back escalation instructions until the question says the relationship has actually progressed.
  • Group scenes. In a group block, {{#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

  • Conditional sub-instructions in an agent's prompt template. A tracker agent can include its "update the location" instructions only when the location changed, rather than asking the model to re-derive it every turn.
  • Package agents that render promptTemplate get 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.
  • Activation questions still decide whether an agent runs at all. The operand decides what an agent that is running is told. Together, an agent can skip quiet turns entirely and send a smaller prompt on the turns it does run.
  • Package runtime code that wants to ask a question directly, rather than through a template, would need a capability API method (for example 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:

  • a role from its skills and class (bruiser, bulwark, skirmisher, marksman, spellcaster, supporter or controller);
  • a proficiency, which is its competence: novice, trained, veteran or master, taken from its level unless the enemy sets one;
  • a temperament, such as reckless, cautious, opportunistic, protective, disciplined, cowardly, patient, methodical or coordinated. Beasts and monstrosities are always mindless.

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

  • Accuracy depends on the model. See "Writing statements" and "Small decision models can be wrong" above. Open-Jev 2B only works at its own calibrated threshold: at the default 0.5 it missed every turn where the scene changed.
  • Cost. Every unique question is part of a request on every turn where it appears. Batching keeps it to one request, but a hosted System One provider bills per request.
  • Prompt caching. A branch that flips changes the prompt from that point on and breaks the provider's prompt cache from there. Put decision blocks late in the prompt (post-history instructions, author's notes) instead of at the top of the system prompt.
  • Phrasing. Statements work better than questions for the purpose-built models, and object-shaped questions help them further. The engine already wraps questions for models that need it, so authors should write plain statements.

Suggested slices

  1. Engine: the 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".
  2. Generation and Peek Prompt wiring, including sharing the batch with activation questions.
  3. Agent executor wiring.
  4. Editor warnings, import notice, docs (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

  • I DID NOT read this template and provide the requested details.
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}}`, see `docs/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 existing `var:name`. Nothing about `{{#if}}` itself changes, so it keeps working with `{{else}}`, `{{else if}}`, `&&`, `||`, parentheses, nesting and group blocks. ``` {{#if decision:"The latest message moves the scene to a new place"}} Open your reply by describing the new location in one or two sentences. {{/if}} ``` ``` {{#if decision:"A fight is happening or about to start"}} Keep combat readable: one action per character, name who is hurt and how badly. {{else if decision:"The characters are resting or talking calmly"}} Slow down. Let the characters notice small details. {{/if}} ``` ``` {{#if char == "Dottore" && decision:"{{user}} is lying or hiding something"}} Dottore notices the inconsistency and files it away. {{/if}} ``` Written as a statement, the way activation questions are, because that is the shape the decision models are measured on. ### What the operand means - It is true when the Decision model's probability meets **that model's own threshold**, the calibrated `defaultThreshold` the 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. - Numeric comparisons (`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. - It is **false** when there is no answer: no Decision model is set, the request timed out or failed, or the model is a reasoning model that defers in front of the reply. The `{{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 `resolveMacros` is 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. 1. **Defer.** Prompt assembly (`services/prompt/assembler.ts`, called from `generate.routes.ts` and from the Peek Prompt dry run) passes a `deferConditionalOperand` predicate that also matches `decision:` operands. Each `{{#if}}` that names one is encoded as a private token, exactly as relocation conditionals are. 2. **Collect.** After assembly, the route reads the questions out of those tokens with the same parser that deferred them, as `collectDeferredRelocationConditionOperands` does for relocation (#3449 is why the same parse matters). Duplicates are merged. 3. **Ask once.** All questions for the turn go to the Decision model in one batched request, the same shape activation questions already use (`resolveDecisionBackend`, `buildDecisionState`). Where possible, this is the same request as the turn's activation questions, since the state is the same recent transcript. 4. **Decode.** `selectConditionalPayloadBranch` picks 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 use `promptTemplate` gain 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: `resolveMacros` with `deferConditionalOperand` matching `decision:`, then `collectDeferredRelocationConditionOperands` and `selectConditionalPayloadBranch`. Plain blocks and mixed conditions (`char == "Kaelen" && decision:"..."`) deferred and collected correctly. Three things need engine work first: 1. **An unknown `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 in `resolveConditionalOperand` that 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". 2. **Group blocks bypass the defer hook.** `expandBracketedCharacterBlocks` calls `resolveCharacterScopedMacros(block, profile, 0, ctx)` without the resolve options, so a `decision:` 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. 3. **Decision blocks need their own token kind.** The conversation route decodes every relocation token that does not name a relocation operand using its own context (`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 - **Budget.** Same timeouts as activation questions: 1.5 s for a hosted connection, 4 s for a local model. These decisions sit in front of the reply, so a model that has to reason first defers unless the user has opted into pre-generation gating. - **Cap.** At most 16 unique questions per turn. Beyond the cap, the remaining conditions are false and a warning is logged. An imported card or preset should not be able to run up a hosted bill. - **Import.** When an imported preset, card or lorebook uses `decision:`, the import says so. The editor warns when content uses the operand but no Decision model is set. - **Debug logging.** Each question and answer is logged at debug level with the branch it chose, alongside the existing decision request logging. ## 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: - **The local model you already run**, on the main or utility local slot. Nothing to download or pay for. - **A hosted Decision connection**: a System One provider such as TypeSafe's Jev, directly or through OpenRouter. - **The installable decision model** (Open-Jev), on a Linux PC with an NVIDIA GPU. 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: - Use a decision to **add or trim guidance**, never to carry content the story depends on. A missed branch should make a reply slightly less tailored, not break it. - Give every decision block a sensible default: either nothing, or an `{{else}}` that is fine on any turn. - Do not chain decisions so that one wrong answer changes several others. - Do not use a decision to gate consent, content warnings or safety instructions. Keep those deterministic or always present. - For an agent that only runs on a decision, set **Bypass the question after this many messages** so a model that keeps answering "no" cannot silence it forever. - Test with **Test** and on your own chats. The same statement can score very differently on different models. ### 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: 1. **No Decision model is set.** **Decision model** is **None** (the default), so every `decision:` condition is false on every turn. This is the most common case, and the editor warning is there to catch it. 2. **Their Decision model is not answering.** A hosted connection with a bad key, no credits or a rate limit; a local model that is stopped, or too slow for the budget (1.5 seconds hosted, 4 seconds local); or an installed decision model that failed to start. Any of these makes the condition fall back to false. 3. **Their Decision model is a reasoning model.** A local model that has to think first defers in front of the reply, unless the user turned on **Also gate agents that run before the reply**. 4. **The turn asked too many questions.** Past 16 unique questions in one turn, the rest read false. 5. **It answers, but below the threshold.** Either the wording (see "Writing statements" below) or a model that rates that turn lower than you expect. Small models are more likely to. What to ask the user for: - Which **Decision model** they have selected, and what **Test** next to it reports. - **Peek Prompt** for the turn: it shows which branch was actually sent, and marks decision branches that had no answer. - Debug logs, if they are willing: each question, its answer and the chosen branch are logged at debug level. 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. | Lesson | Recommended | Avoid | Recommended score (2B / sidecar) | Avoid score (2B / sidecar) | What happened | | --- | --- | --- | --- | --- | --- | | A statement, not a question | "The latest message moves the scene to a new place." | "Did the scene change?" | 4/4, 4/4 | 2/4, 4/4 | The question pushed Open-Jev 2B's "no" answers over its threshold (0.10 and 0.13). The sidecar was unaffected. | | Observable, not a judgement | "In the latest message, a character draws a weapon or attacks someone." | "The scene is intense." | 4/4, 4/4 | 3/4, 3/4 | Both called a heated argument "intense" (2B 0.74, sidecar 0.999). With a vague word, the model decides what it means, not the author. | | About the latest message, not the whole chat | "In the latest message, Mira asks Kaelen a direct question." | "Mira asks questions." | 4/4, 4/4 | 3/4, 2/4 | The sidecar said yes (0.9999 and 0.9986) when Mira's latest message asked nothing, because an earlier message did. | | Names, not pronouns | "Kaelen is angry in the latest message." | "He is angry." | 4/4, 4/4 | 4/4, 3/4 | The sidecar read "he" as the angry barkeep (0.98) when the author meant Kaelen. | | Checkable in the text, not a hidden mental state | "In the latest message, Mira says something that contradicts what she said earlier." | "Mira is lying." | 3/4, 4/4 | 2/4, 2/4 | Neither model reliably called a contradiction "lying" (sidecar 0.41 and 0.03 on the two contradictions). 2B's one miss on the recommended form was 0.076, just under its 0.1 threshold. | | A statement, not an instruction | "The latest message moves the scene to a new place." | "If the scene changed, describe the new location in two sentences." | 4/4, 4/4 | 4/4, 2/4 | The sidecar answered no to the instruction every time (0.001 to 0.002). An instruction is not true or false, so the block never fires. | | One thing per statement | "Someone is injured in the latest message." | "A fight starts and someone is injured and the city guards arrive." | 4/4, 4/4 | 4/4, 4/4 | Both handled a three-part "and" correctly. Splitting is still easier to reuse and debug, but it did not fail here. | | Positive, not negated | "In the latest message, the characters stay in the same place." | "The characters did not leave the room." | 4/4, 4/4 | 4/4, 4/4 | No difference. Open-Jev 2B actually separated the negated form more widely (0.69 against 0.18 for yes). Write whichever reads naturally. | 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: - **states a fact that is either true or false**, in the present tense, like a line in a report, not a question or an instruction; - **says "in the latest message"** when it is about this turn, because the model sees several messages; - **names who it is about**, and does not use "he", "she" or "they"; - **describes something visible in the text**, an action or a statement, not a mood word the model must interpret, and not a hidden intention like lying or secretly wanting; - **stays short**. One idea is easiest to test and reuse, though a plain "and" did not break either model here. 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. - **Scene changes.** Describe a new location or time skip only when the scene actually moved, instead of telling the model "if the scene changes, describe it" every turn. - **Combat, intimacy, tension.** Load the relevant pacing or formatting rules only while that kind of scene is happening. - **Answer the question first.** `{{#if decision:"{{user}} asked a direct question in the latest message"}}Answer it before anything else.{{/if}}` - **Anti-repetition.** `{{#if decision:"The previous reply repeats phrasing from earlier replies"}}Vary sentence openings and avoid repeating descriptions.{{/if}}` - **Card-level moods.** A character card can hold "when flustered" or "when angry" behavior that only appears when the recent messages show it. - **Pacing guards.** A slow-burn preset can hold back escalation instructions until the question says the relationship has actually progressed. - **Group scenes.** In a group block, `{{#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 - **Conditional sub-instructions in an agent's prompt template.** A tracker agent can include its "update the location" instructions only when the location changed, rather than asking the model to re-derive it every turn. - **Package agents** that render `promptTemplate` get 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](https://github.com/Pasta-Devs/Marinara-Agents). - Activation questions still decide whether an agent runs at all. The operand decides what an agent that is running is told. Together, an agent can skip quiet turns entirely and send a smaller prompt on the turns it does run. - Package runtime code that wants to ask a question directly, rather than through a template, would need a capability API method (for example `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: - a **role** from its skills and class (bruiser, bulwark, skirmisher, marksman, spellcaster, supporter or controller); - a **proficiency**, which is its competence: novice, trained, veteran or master, taken from its level unless the enemy sets one; - a **temperament**, such as reckless, cautious, opportunistic, protective, disciplined, cowardly, patient, methodical or coordinated. Beasts and monstrosities are always mindless. 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 - **Accuracy depends on the model.** See "Writing statements" and "Small decision models can be wrong" above. Open-Jev 2B only works at its own calibrated threshold: at the default 0.5 it missed every turn where the scene changed. - **Cost.** Every unique question is part of a request on every turn where it appears. Batching keeps it to one request, but a hosted System One provider bills per request. - **Prompt caching.** A branch that flips changes the prompt from that point on and breaks the provider's prompt cache from there. Put decision blocks late in the prompt (post-history instructions, author's notes) instead of at the top of the system prompt. - **Phrasing.** Statements work better than questions for the purpose-built models, and object-shaped questions help them further. The engine already wraps questions for models that need it, so authors should write plain statements. ### Suggested slices 1. Engine: the `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". 2. Generation and Peek Prompt wiring, including sharing the batch with activation questions. 3. Agent executor wiring. 4. Editor warnings, import notice, docs (`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 - [ ] 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#3683
No description provided.