[GH-ISSUE #6559] [Feature]: Route Smart response order (and group card relevance) through the decision-model endpoint #3675

Closed
opened 2026-10-21 06:05:47 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kevin-ho on GitHub (Sep 23, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6559

Originally assigned to: @kolacheee on GitHub.

What problem does this solve?

Two prompt-cost hotspots in individual-mode group chats currently pay a
regular chat-model round trip for what is essentially a classification job,
while #6555 introduces an endpoint built for exactly this shape of decision.

  1. Smart response order — selectSmartGroupResponders() in
    packages/server/src/routes/generate.routes.ts (staging, ~L6416–6566)
    sends every candidate's summary
    (formatSmartGroupCandidates(), services/generation/conversation-context-utils.ts)
    plus a 5-message transcript to a chat completion and asks for a JSON array
    of character IDs (~L6530–6547), parsed tolerantly at
    parseSmartGroupSelectionIds() (~L6372). One full generation call per
    turn to pick a speaker.

  2. Group card scoping — scopeIndividualGroupMessagesForTarget() in
    packages/server/src/services/generation/prompt-message-scope.ts (~L319)
    strips non-responder profile blocks after assembly. The base prompt still
    assembles every active roster card first, and the stripper depends on
    recognizable XML/markdown wrappers or exact field-text matches. Nothing
    scores relevance: a 2000-token card for a character who hasn't been on
    screen in 40 messages is either assembled-then-stripped or sent intact in
    merged mode.

#6555's endpoint already supports batched Noul questions (see the
grouping-by-depth batching in services/generation/agent-activation-questions.ts),
which maps onto both surfaces.

Proposed solution

For Smart order: per-candidate Noul questions — "should
respond to this state?" — compared against a threshold, mirroring the
existing activation-question pattern (including per-model calibration).

The orchestrator rules in the current system prompt are multi-candidate
(usually one speaker, never the same character twice in a row, ~L6450–6465).
Those would stay as a small deterministic rule layer over the per-candidate
verdicts — ≥1 must pass, avoid the last speaker — or a single Choice
question over the candidate set. The existing fail-open fallback (first
available character who isn't the last speaker, ~L6568) already tolerates
endpoint failure, and a 1.5s budget fits inside the current generation
timeout shape.

For card relevance: score each roster card's confidence against the
recent transcript with the same Noul call, and skip assembling cards below
a threshold in the first place — in both group modes — instead of assembling
then stripping.

Alternatives considered

Keeping the chat call for its native multi-candidate reasoning is the
strongest counterargument: it understands the "don't repeat the same
speaker" instructions directly rather than needing a rule layer. The batched
verdicts + rules approach is proposed on cost and latency grounds, not
correctness — on eight roleplay cases a purpose-built model being worse at
the same job (#6555) should be expected to apply here too, so this is opt-in
with the same off-by-default shape as activation questions.

For card relevance specifically, an embedding-similarity pre-filter (like
lorebook vector scoring) was considered; the decision endpoint keeps the
mechanism consistent with activation questions and avoids a second
dependency, though embedding-based scoring may well be the cheaper option
if latency per turn matters more than per-call simplicity.

Additional context

Both surfaces are reachable from code that already exists on staging;
nothing here assumes a new runtime beyond #6555's managed sidecar.

Sequential and Merged modes would keep their current behavior with no calls.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @kevin-ho on GitHub (Sep 23, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/6559 Originally assigned to: @kolacheee on GitHub. ## What problem does this solve? Two prompt-cost hotspots in individual-mode group chats currently pay a regular chat-model round trip for what is essentially a classification job, while #6555 introduces an endpoint built for exactly this shape of decision. 1. **Smart response order** — `selectSmartGroupResponders()` in `packages/server/src/routes/generate.routes.ts` (staging, ~L6416–6566) sends every candidate's summary (`formatSmartGroupCandidates()`, `services/generation/conversation-context-utils.ts`) plus a 5-message transcript to a chat completion and asks for a JSON array of character IDs (~L6530–6547), parsed tolerantly at `parseSmartGroupSelectionIds()` (~L6372). One full generation call per turn to pick a speaker. 2. **Group card scoping** — `scopeIndividualGroupMessagesForTarget()` in `packages/server/src/services/generation/prompt-message-scope.ts` (~L319) strips non-responder profile blocks *after* assembly. The base prompt still assembles every active roster card first, and the stripper depends on recognizable XML/markdown wrappers or exact field-text matches. Nothing scores relevance: a 2000-token card for a character who hasn't been on screen in 40 messages is either assembled-then-stripped or sent intact in merged mode. #6555's endpoint already supports batched Noul questions (see the grouping-by-depth batching in `services/generation/agent-activation-questions.ts`), which maps onto both surfaces. ## Proposed solution **For Smart order:** per-candidate Noul questions — "should <character> respond to this state?" — compared against a threshold, mirroring the existing activation-question pattern (including per-model calibration). The orchestrator rules in the current system prompt are multi-candidate (usually one speaker, never the same character twice in a row, ~L6450–6465). Those would stay as a small deterministic rule layer over the per-candidate verdicts — ≥1 must pass, avoid the last speaker — or a single Choice question over the candidate set. The existing fail-open fallback (first available character who isn't the last speaker, ~L6568) already tolerates endpoint failure, and a 1.5s budget fits inside the current generation timeout shape. **For card relevance:** score each roster card's confidence against the recent transcript with the same Noul call, and skip assembling cards below a threshold in the first place — in both group modes — instead of assembling then stripping. ## Alternatives considered Keeping the chat call for its native multi-candidate reasoning is the strongest counterargument: it understands the "don't repeat the same speaker" instructions directly rather than needing a rule layer. The batched verdicts + rules approach is proposed on cost and latency grounds, not correctness — on eight roleplay cases a purpose-built model being worse at the same job (#6555) should be expected to apply here too, so this is opt-in with the same off-by-default shape as activation questions. For card relevance specifically, an embedding-similarity pre-filter (like lorebook vector scoring) was considered; the decision endpoint keeps the mechanism consistent with activation questions and avoids a second dependency, though embedding-based scoring may well be the cheaper option if latency per turn matters more than per-call simplicity. ## Additional context Both surfaces are reachable from code that already exists on `staging`; nothing here assumes a new runtime beyond #6555's managed sidecar. Sequential and Merged modes would keep their current behavior with no calls. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 06:05:47 +07:00
Author
Owner

@kolacheee commented on GitHub (Sep 23, 2026):

#6572 takes the Smart order half of this: one batched yes/no per candidate against the Decision model, the model's own threshold, a small rule layer (the last speaker yields), and the existing chat-model selector as the fallback whenever the switch is off or the Decision model does not answer.

Card relevance is left out on purpose. The reasons, with where to look:

  1. Individual mode already sends only the responder's card. scopeIndividualGroupMessagesForTarget() in packages/server/src/services/generation/prompt-message-scope.ts removes the other roster cards per target before the request goes out (called where scopedMessagesForGen is built in packages/server/src/routes/generate.routes.ts). Skipping assembly earlier would save server work, not tokens sent to the provider.
  2. In merged mode a wrong "no" drops a card that is needed. Any character can appear in a merged reply. If the model says a present character is not relevant, the narrator loses that character's personality for the turn. Content the reply depends on is the one thing the decision docs say never to gate on a decision, and small models do get statements wrong (Open-Jev 2B missed 1 of 32 even on well-worded ones).
  3. It would break prompt caching. Cards are expanded near the top of the prompt (the character marker in packages/server/src/services/prompt/marker-expander.ts). A card set that changes from turn to turn changes everything after it, so a caching provider re-bills the whole prompt. On those providers it would cost more than it saves.
  4. It adds one statement per roster member per turn, which is billed on a hosted Decision connection.

A card author who wants this for one character can already do it in the card's own text with a decision statement from #6569, for example trimming a long section with {{#if decision:"Kaelen is present in the latest message"}}...{{/if}}. That keeps the choice with the author and the cost visible.

<!-- gh-comment-id:5796345230 --> @kolacheee commented on GitHub (Sep 23, 2026): #6572 takes the Smart order half of this: one batched yes/no per candidate against the Decision model, the model's own threshold, a small rule layer (the last speaker yields), and the existing chat-model selector as the fallback whenever the switch is off or the Decision model does not answer. Card relevance is left out on purpose. The reasons, with where to look: 1. **Individual mode already sends only the responder's card.** `scopeIndividualGroupMessagesForTarget()` in `packages/server/src/services/generation/prompt-message-scope.ts` removes the other roster cards per target before the request goes out (called where `scopedMessagesForGen` is built in `packages/server/src/routes/generate.routes.ts`). Skipping assembly earlier would save server work, not tokens sent to the provider. 2. **In merged mode a wrong "no" drops a card that is needed.** Any character can appear in a merged reply. If the model says a present character is not relevant, the narrator loses that character's personality for the turn. Content the reply depends on is the one thing the decision docs say never to gate on a decision, and small models do get statements wrong (Open-Jev 2B missed 1 of 32 even on well-worded ones). 3. **It would break prompt caching.** Cards are expanded near the top of the prompt (the `character` marker in `packages/server/src/services/prompt/marker-expander.ts`). A card set that changes from turn to turn changes everything after it, so a caching provider re-bills the whole prompt. On those providers it would cost more than it saves. 4. **It adds one statement per roster member per turn**, which is billed on a hosted Decision connection. A card author who wants this for one character can already do it in the card's own text with a decision statement from #6569, for example trimming a long section with `{{#if decision:"Kaelen is present in the latest message"}}...{{/if}}`. That keeps the choice with the author and the cost visible.
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#3675
No description provided.