[GH-ISSUE #5957] Let a Game chat run tool calls on a different connection than its narration #3299

Closed
opened 2026-10-21 06:01:46 +07:00 by bsakaguchi · 2 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Ask: let a Game chat run its tool calls on a different connection than its narration — e.g. narrate on a Claude subscription connection while roll_dice and friends execute against a Gemini API connection.

First, a correction to the premise this started from: Professor Mari does not have this. Verified across both trees with explicit negative searches — mariModel, toolsConnection, utilityConnection, auxConnection, secondaryConnection, connectionIdOverride all return zero matches. Mari holds exactly one connection id (marinara:home-professor-mari-connection-id, HomeProfessorMariChat.tsx:134), her follow-up generation pass loops back into the same while with the same resolved provider (generate.routes.ts:10736-10791, which never touches conn), and her workspace agent builds one provider for an entire multi-round tool run (workspace-agent.service.ts:2631, the only createProviderForConnection call in the file). Her bracket commands aren't LLM calls at all — they're local database work.

But the shape absolutely does ship, twice, which is probably the real memory:

  • A per-purpose connection for a tool-call pass already exists — for custom emoji/sticker selection. CustomEmojiSelectionPrefs.toolConnectionId, documented as "Connection used for the tool-call selection mode" (shared/src/schemas/custom-emoji.schema.ts:36-43), consumed at routes/generate/conversation-custom-assets.ts:290-301. "Chat on one connection, tool call on another" is a shipped behavior — just for emoji, not Mari and not the GM.
  • Game Mode already has a purpose-scoped connection override — gameVideoConnectionId (shared/src/types/chat.ts:593), resolved by exactly the layered pattern this feature would want (game.routes.ts:1696-1709): per-chat metadata → setup-wizard default → purpose-scoped global default. And connections.storage.ts already defines default/fallback pairs for four purposes (agents, image, video, audio). A gameGmToolConnectionId plus getDefaultForGmTools/getFallbackForGmTools would drop straight into that family.

So the settings plumbing is a known pattern. The hard part is the tool loop. Today the connection, provider, model and every generation parameter are resolved once, before any round runs (generate.routes.ts:3290 via resolveGenerationProviderRuntime), and every round — including the final follow-up — closes over that same provider and conn. Three provider-locked side channels break if a different provider handles a round mid-turn:

  1. Gemini thought signatures. Reasoning state is replayed through providerMetadata.geminiParts (google.provider.ts:793-816, consumed at :480-483). No other provider's formatter reads it, so a round handled elsewhere drops the signature, and handing back to Gemini can't manufacture one — with the in-code warning that Gemini 3 rejects a replayed call whose signature moved (google.provider.ts:703-704).
  2. OpenAI encrypted reasoning items. These ride a closure variable, not the message array (generate.routes.ts:1223, written back at :6515-6520), and only the Responses-API path reads them. Switching away silently drops reasoning continuity.
  3. Anthropic prompt caching. enableCaching / cachingAtDepth are read off the single connection on every call; cache economics depend on the array's shape staying stable, and there's no per-round hook to re-resolve any of it for a second connection.

So this is a structural change to the loop, not a config flag — if it's done as a mid-turn provider switch.

Two designs, and the cheaper one is already precedented:

  • Side call (recommended to evaluate first). The tool work runs as a self-contained call on the tool connection, and its result comes back as context — never replayed into the narrating provider's history as a tool_use chain. This is exactly how emoji tool-call selection works, how the smart-group-responder selector works (generate.routes.ts:5860-5915, which builds a whole separate provider mid-request), and how knowledge-router works. None of the three side channels above are touched, because nothing crosses providers. The cost: the narrating model no longer decides in-band to call the tool — something else has to decide, or the GM has to signal its intent in text.
  • Mid-turn provider switch. What the ask literally describes, and what the three items above stand in the way of. Plain text and simple tool_use/functionCall turns would survive a swap; reasoning continuity would not.

Worth deciding which problem we're solving, because there may be a third answer. If the motivation is "subscription users can't use GM tools at all", the Engine already has a provider-agnostic channel that needs no tools API: the GM verb bracket tags (#5798) and server-rolled skill checks (#5923) are parsed out of narration text, which is why they already work on subscription connections. Extending that channel may serve those users better than routing tools to a second connection. If the motivation is instead "let power users put tool work on a cheaper or faster model", then the connection override is the right feature and the side-call shape is the way in.

Related: #5955 (GM lorebook search) would inherit whichever answer lands here.

Originally created by @kolacheee on GitHub (Sep 8, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5957 Originally assigned to: @SpicyMarinara on GitHub. **Ask:** let a Game chat run its tool calls on a different connection than its narration — e.g. narrate on a Claude subscription connection while `roll_dice` and friends execute against a Gemini API connection. **First, a correction to the premise this started from: Professor Mari does *not* have this.** Verified across both trees with explicit negative searches — `mariModel`, `toolsConnection`, `utilityConnection`, `auxConnection`, `secondaryConnection`, `connectionIdOverride` all return zero matches. Mari holds exactly one connection id (`marinara:home-professor-mari-connection-id`, `HomeProfessorMariChat.tsx:134`), her follow-up generation pass loops back into the same `while` with the same resolved provider (`generate.routes.ts:10736-10791`, which never touches `conn`), and her workspace agent builds one provider for an entire multi-round tool run (`workspace-agent.service.ts:2631`, the only `createProviderForConnection` call in the file). Her bracket commands aren't LLM calls at all — they're local database work. **But the shape absolutely does ship, twice, which is probably the real memory:** - **A per-purpose connection for a tool-call pass already exists** — for custom emoji/sticker selection. `CustomEmojiSelectionPrefs.toolConnectionId`, documented as *"Connection used for the tool-call selection mode"* (`shared/src/schemas/custom-emoji.schema.ts:36-43`), consumed at `routes/generate/conversation-custom-assets.ts:290-301`. "Chat on one connection, tool call on another" is a shipped behavior — just for emoji, not Mari and not the GM. - **Game Mode already has a purpose-scoped connection override** — `gameVideoConnectionId` (`shared/src/types/chat.ts:593`), resolved by exactly the layered pattern this feature would want (`game.routes.ts:1696-1709`): per-chat metadata → setup-wizard default → purpose-scoped global default. And `connections.storage.ts` already defines default/fallback pairs for four purposes (agents, image, video, audio). A `gameGmToolConnectionId` plus `getDefaultForGmTools`/`getFallbackForGmTools` would drop straight into that family. **So the settings plumbing is a known pattern. The hard part is the tool loop.** Today the connection, provider, model and every generation parameter are resolved **once**, before any round runs (`generate.routes.ts:3290` via `resolveGenerationProviderRuntime`), and every round — including the final follow-up — closes over that same `provider` and `conn`. Three provider-locked side channels break if a different provider handles a round mid-turn: 1. **Gemini thought signatures.** Reasoning state is replayed through `providerMetadata.geminiParts` (`google.provider.ts:793-816`, consumed at `:480-483`). No other provider's formatter reads it, so a round handled elsewhere drops the signature, and handing back to Gemini can't manufacture one — with the in-code warning that Gemini 3 *rejects* a replayed call whose signature moved (`google.provider.ts:703-704`). 2. **OpenAI encrypted reasoning items.** These ride a closure variable, not the message array (`generate.routes.ts:1223`, written back at `:6515-6520`), and only the Responses-API path reads them. Switching away silently drops reasoning continuity. 3. **Anthropic prompt caching.** `enableCaching` / `cachingAtDepth` are read off the single connection on every call; cache economics depend on the array's shape staying stable, and there's no per-round hook to re-resolve any of it for a second connection. So this is a structural change to the loop, not a config flag — *if* it's done as a mid-turn provider switch. **Two designs, and the cheaper one is already precedented:** - **Side call (recommended to evaluate first).** The tool work runs as a *self-contained* call on the tool connection, and its result comes back as context — never replayed into the narrating provider's history as a `tool_use` chain. This is exactly how emoji tool-call selection works, how the smart-group-responder selector works (`generate.routes.ts:5860-5915`, which builds a whole separate provider mid-request), and how `knowledge-router` works. None of the three side channels above are touched, because nothing crosses providers. The cost: the narrating model no longer decides in-band to call the tool — something else has to decide, or the GM has to signal its intent in text. - **Mid-turn provider switch.** What the ask literally describes, and what the three items above stand in the way of. Plain text and simple tool_use/functionCall turns would survive a swap; reasoning continuity would not. **Worth deciding which problem we're solving, because there may be a third answer.** If the motivation is *"subscription users can't use GM tools at all"*, the Engine already has a provider-agnostic channel that needs no tools API: the GM verb bracket tags (#5798) and server-rolled skill checks (#5923) are parsed out of narration text, which is why they already work on subscription connections. Extending that channel may serve those users better than routing tools to a second connection. If the motivation is instead *"let power users put tool work on a cheaper or faster model"*, then the connection override is the right feature and the side-call shape is the way in. Related: #5955 (GM lorebook search) would inherit whichever answer lands here.
bsakaguchi 2026-10-21 06:01:46 +07:00
  • closed this issue
  • added the
    in-pr
    label
Author
Owner

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

Correction to this issue's motivation, after verification — the subscription-user rationale doesn't hold, and should be struck.

This was filed partly so users on Claude/Grok subscription connections could get tool-driven behavior (real dice) by routing tool calls to a second connection. Checked against the code: that cannot work under any design, because there is never a tool call to route. Both subscription providers inherit chatComplete from BaseLLMProvider, which returns a hardcoded toolCalls: [] (base-provider.ts:783/:805) and never reads options.tools. The tool loop enters (the method exists), then breaks unconditionally on round 0. Any router keyed on result.toolCalls fires zero times. The narrating model on those connections cannot emit a call, so there is nothing for a second connection to execute.

The three candidate shapes, tested:

  • A second cheap model inspects the narration and decides. The custom-emoji precedent is weaker than it looked: selectCustomAssetNamesByToolCall reads result.content, inspects the user's message, and runs as a pre-pass that edits the system prompt before the narrating model runs. It can't produce in-turn reaction, because the narration is already streamed before any post-pass could run — getting the GM to react would mean re-invoking the expensive narrating provider, which erases the saving. And for dice specifically, a narration that already invented "you rolled a 14" gives the judge nothing honest to work from.
  • The model signals in text and the server executes. Meets the bar for everyone, needs no second connection and no extra tokens — and it is already shipped twice (#5923, #5798). This is where the subscription-user benefit actually comes from, and #5959 widens it to arbitrary dice.
  • A second model writes the whole turn when tools are needed. Fails outright: no machinery exists, connection-fallback-provider.ts:331 actively refuses to fall back when a subscription turn produced usable content, and it would replace the voice the user is paying for on exactly the turns that matter most.

So the honest scope for this issue is cost control on a working tool loop — let users put tool work on a cheaper or faster model where the tool loop already runs. That's a real want and worth building. It just helps API/tool-capable users, and does nothing for subscription users; their path is the text-tag channel.

Two things follow for whoever picks this up:

  1. Retarget the title/rationale at cost control, or close this in favor of that framing.
  2. The maintainer's bar for it is explicit: "provided it doesn't break anything or has a noticeably worse feel." The mid-turn provider-switch design does not clear that bar — the three provider-locked channels above (Gemini thought signatures, OpenAI encrypted reasoning items, Anthropic cache depth) all degrade silently. The side-call shape clears it, at the cost of the narrating model no longer deciding in-band.
<!-- gh-comment-id:5585017958 --> @kolacheee commented on GitHub (Sep 8, 2026): **Correction to this issue's motivation, after verification — the subscription-user rationale doesn't hold, and should be struck.** This was filed partly so users on Claude/Grok subscription connections could get tool-driven behavior (real dice) by routing tool calls to a second connection. Checked against the code: **that cannot work under any design, because there is never a tool call to route.** Both subscription providers inherit `chatComplete` from `BaseLLMProvider`, which returns a hardcoded `toolCalls: []` (`base-provider.ts:783`/`:805`) and never reads `options.tools`. The tool loop enters (the method exists), then breaks unconditionally on round 0. Any router keyed on `result.toolCalls` fires zero times. The narrating model on those connections cannot emit a call, so there is nothing for a second connection to execute. The three candidate shapes, tested: - **A second cheap model inspects the narration and decides.** The custom-emoji precedent is weaker than it looked: `selectCustomAssetNamesByToolCall` reads `result.content`, inspects the *user's* message, and runs as a **pre-pass** that edits the system prompt before the narrating model runs. It can't produce in-turn reaction, because the narration is already streamed before any post-pass could run — getting the GM to react would mean re-invoking the expensive narrating provider, which erases the saving. And for dice specifically, a narration that already invented "you rolled a 14" gives the judge nothing honest to work from. - **The model signals in text and the server executes.** Meets the bar for everyone, needs no second connection and no extra tokens — and it is already shipped twice (#5923, #5798). This is where the subscription-user benefit actually comes from, and #5959 widens it to arbitrary dice. - **A second model writes the whole turn when tools are needed.** Fails outright: no machinery exists, `connection-fallback-provider.ts:331` actively refuses to fall back when a subscription turn produced usable content, and it would replace the voice the user is paying for on exactly the turns that matter most. **So the honest scope for this issue is cost control on a working tool loop** — let users put tool work on a cheaper or faster model where the tool loop already runs. That's a real want and worth building. It just helps API/tool-capable users, and does nothing for subscription users; their path is the text-tag channel. Two things follow for whoever picks this up: 1. Retarget the title/rationale at cost control, or close this in favor of that framing. 2. The maintainer's bar for it is explicit: *"provided it doesn't break anything or has a noticeably worse feel."* The mid-turn provider-switch design does not clear that bar — the three provider-locked channels above (Gemini thought signatures, OpenAI encrypted reasoning items, Anthropic cache depth) all degrade silently. The side-call shape clears it, at the cost of the narrating model no longer deciding in-band.
Author
Owner

@SpicyMarinara commented on GitHub (Sep 9, 2026):

@SpicyMarinara owns this sweep implementation in draft #5982. The separate connection will run an isolated tool-planning pass before narration, returning actual tool results as text so provider-specific reasoning histories never cross connections.

<!-- gh-comment-id:5594005876 --> @SpicyMarinara commented on GitHub (Sep 9, 2026): @SpicyMarinara owns this sweep implementation in draft #5982. The separate connection will run an isolated tool-planning pass before narration, returning actual tool results as text so provider-specific reasoning histories never cross connections.
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#3299
No description provided.