[PR #7437] [MERGED] fix(roleplay): let every agent read whispers #7733

Closed
opened 2026-10-24 04:06:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7437
Author: @SpicyMarinara
Created: 10/11/2026
Status: ✅ Merged
Merged: 10/11/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/agents-see-whispers


📝 Commits (10+)

  • b29f589 fix(roleplay): let every agent read whispers
  • abeff2d fix(roleplay): replace a whisper-only placeholder by its position
  • 034cd7d fix(roleplay): give retried agents the reply with its whispers
  • 2f38cd1 fix(roleplay): run post-generation agents on a whisper-only reply
  • a0188fa fix(roleplay): keep whispers from agents for any unfinished room
  • 34054fa fix(roleplay): skip rewrites when a turn has only blank public text
  • fe4b231 fix(roleplay): run rewrite agents only on a reply with public text
  • 52ec7c4 fix(roleplay): keep whispers out of a reply's own tools and place a continuation's own
  • add3d0b docs(roleplay): name a rewritten reply among agent output that can carry a whisper
  • 099d62c fix(roleplay): let Smart speaker selection read whispers

📊 Changes

10 files changed (+929 additions, -80 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/development/multiplayer.md (+1 -1)
📝 docs/roleplay/getting-started.md (+3 -1)
📝 packages/server/src/routes/generate.routes.ts (+124 -33)
📝 packages/server/src/routes/generate/retry-agents-route.ts (+35 -7)
📝 packages/server/src/services/generation/roleplay-commands.ts (+128 -23)
📝 packages/server/src/services/generation/tool-resolution-runtime.ts (+25 -10)
📝 scripts/regressions/agent-activation.regression.ts (+4 -4)
➕ scripts/regressions/agents-see-whispers.regression.ts (+602 -0)
📝 scripts/regressions/roleplay-user-private-generation.regression.ts (+6 -1)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7430

Why this change

  • In Roleplay chats, Echo Chamber and every other agent missed whispers. Agents built their history from each message's visible text, so a whisper never reached them. A message that was only a whisper arrived as a bare [Private whisper], so Echo Chamber knew something was said but not what. Post-generation agents never saw what a character whispered in the reply they were processing, and a reply that was only a whisper skipped them entirely.
  • Decided behaviour: every agent sees whispers, including Lorebook Keeper and Long-Term Memory. Hosted multiplayer rooms are the exception.
  • Maintainer decision (2026-10-11): Smart speaker selection in Roleplay group chats sees whispers too, like every other agent. "A whisper to Bob can make Bob the one who replies."

What changed

  • One helper next to appendRoleplayWhispers in roleplay-commands.ts:
    • roleplayAgentText renders a message as agents read it: its text with each live whisper (not deleted, no error) at its saved place, as [Private whisper to <recipient>: <text>]. The recipient is the character's current name, or the persona's name.
    • A whisper-only message reads as its whispers: they take the place of its [Private whisper] placeholder.
    • roleplayAgentPrompt gives agents their own copy of a prompt and leaves the responder's prompt alone.
    • Whisper placement inside a message is shared with appendRoleplayWhispers (placeRoleplayWhispers), so responders and agents put a whisper in the same spot.
  • Every agent path that carries chat history uses it:
    • agentContext.recentMessages, which feeds every pipeline agent, capability packages, agents' tool calls, knowledge retrieval, Music DJ, Illustrator and the expression agent.
    • Character Activity routing.
    • Smart speaker selection in group chats: the Decision model's smart-order transcript and the chat-model selector's transcript. A whisper-only message reads as its whispers there instead of [Private whisper].
      • The chat-model selector caps each transcript line at 900 characters. A turn's text and each of its whispers now get 900 characters apiece (roleplayAgentText's optional limit), so a long whisper cannot crowd out what was said aloud. A whisper whose place is cut off follows the cut text. A line with no whispers is cut exactly as before.
    • The main prompt preview (_mainPromptPreview), both before and during generation.
    • Long-Term Memory recall.
    • Lorebook Keeper and read-behind history.
    • The new reply for post-generation agents (mainResponse, group response segments and lorebook triggers), taken from the reply's saved activity.
    • On a continue with speaker names in history, the group segment is only the added text. roleplayAgentContinuation gives it only the whispers written with that text, at their places. The message's earlier whispers stay in the agents' history, where they already were.
    • Media command sources, background scene planning, and the auto-retry of failed agents.
    • The retry-agents route: history, Lorebook Keeper and read-behind runs, and the retried reply for non-rewrite agents.
    • With Advanced Memory on, agents now get whisper-only messages in their window, as the preview already did.
  • A reply that is only a whisper now runs post-generation agents.
  • Smart speaker selection only picks a speaker. The chat-model selector's reply is parsed to character IDs, and the Decision model returns one probability per candidate. Only the chosen IDs and names leave the selector (the response_queue event); nothing the selector writes is shown to users or put into a responder's prompt. The regression checks that the responder, who is not the whisper's recipient, still gets neither whisper on that turn. The selector's raw reply is written to the server log only when it holds no valid character ID, as before.
  • A character's own custom tools stay public. The main reply's custom tools act for the character responding, so their {{input}} (the script and webhook hidden context) is the latest user message's public text, as before. A tool that a non-recipient calls never gets someone else's whisper. Agents' own tool calls keep the agents' input, with whispers.
  • Text rewrite agents (Prose Guardian, Continuity, custom rewrites) are given only the public reply to edit; Marinara never puts a whisper into it. Like every agent, they read whispers in their history and in the prompt preview. So a rewrite model could still write a whisper into the visible message, the same trade-off as a lorebook entry. The docs and changelog name a rewritten reply among agent output that can carry a whisper.
    • Rewrites now run only when the reply has public text.
    • This also covers a pre-existing case: a reply with only a media command (or blank lines from several whisper-only replies) used to send rewrite agents an empty reply.
  • No double insertion: agents get the history and the preview as separate copies, each with the whisper once. Agent copies are made from the shared prompt before the responder's own whispers are added. The regression checks both the pre-reply preview and the preview after the reply.
  • Unchanged:
    • What character responders receive: non-recipients never see a whisper, and whisper-only messages are still dropped for them.
    • Advanced Memory records.
    • The responder's Peek Prompt.
  • Rooms keep today's behaviour. Agents get no whispers in a multiplayer room, because every human participant sees agent output. roleplayAgentsSeeWhispers uses currentRoomGeneration() during room generation, which is the existing room signal. For agent runs started outside it, such as retries, any multiplayer metadata other than an ended room counts as a room. That includes guest data, a room with no status, and data that can't be read. This is documented in the code comment and the docs.
  • Privacy trade-off: agent output can now mention a whisper, and that output can reach a character who wasn't the recipient. Examples are a lorebook entry, a tracker note, an Echo Chamber line or a prompt patch. Each whisper is labeled as private so agents know it is a secret. The trade-off is stated in the docs and the changelog.
  • Docs: docs/roleplay/getting-started.md (who reads whispers, and that agent output such as a rewritten reply can carry one) and docs/development/multiplayer.md (room agents never read whispers). Comments that said private state never reaches agents are updated.
  • Changelog entry under [Unreleased].
  • New regression scripts/regressions/agents-see-whispers.regression.ts. It fails on staging and passes with this change. Each guard was also checked by reverting it and watching the regression fail. It covers:
    • The new reply's whispers reaching a post-generation agent, in place, with labels for a character and the persona.
    • A whisper-only reply, and a group turn of two whisper-only replies, reaching post-generation agents with no rewrite.
    • A whisper-only user message reaching a pre-generation (Echo Chamber-like) agent as the whisper itself.
    • History placement, and both previews without double insertion.
    • Non-recipient responders still getting none of the whispers, while the recipient keeps them.
    • Deleted and failed whispers being left out.
    • Placeholder edge cases.
    • Retries, both for a non-rewrite agent and for a rewrite agent's public target.
    • A continued group reply with speaker names in history: the agents' segment holds only the added text and its own whisper, in place. A continuation that added only a whisper reads as that whisper.
    • A non-recipient's own script tool with hidden context: its {{input}} is the public text, and none of that character's requests holds the whisper.
    • Smart speaker selection, both the Decision-model and the chat-model path: the transcript holds a whisper in place with its label and a whisper-only message as its whisper, and the responder still gets neither.
    • A 1,061-character whisper before Alice, what do you think?: the chat-model selector's line keeps the question and cuts the whisper to its own 900 characters. A helper check covers whispers whose places are cut off, in order.
    • A real hosted-room generation through the room runner, including a Smart turn whose selector gets no whisper.
    • The room gate for guest, statusless, malformed and ended room data.
  • scripts/regressions/roleplay-user-private-generation.regression.ts:280, added by #6878, asserted that speaker selection never receives private activity. Updated with the maintainer's approval to the new rule, not deleted: the Smart selector's prompt must hold Public Smart turn. [Private whisper to Bob: SMART_WHISPER_SECRET], and private notes must still stay out of it.
  • scripts/regressions/agent-activation.regression.ts is a source-shape test. Four of its patterns now name agentCompletedResponse instead of completedResponse, because post-processing agents get the completed reply with its whispers. Each pattern is as strict as before.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Commands run by the agent on b66c322, the head (results are not evidence for the boxes above):

  • pnpm check: exit 0.
  • pnpm regression:prompt: passed (3 suites).
  • --filter agents-see-whispers: passed. With the selector's route change reverted, the long-whisper check fails (the line holds only the cut whisper). With the helper change reverted, the helper check fails.
  • --filter roleplay-user-private-generation: passed with the updated assertion.
  • --filter roleplay-: 14/14 passed.
  • --filter smart: 1/1 passed.
  • --filter group: 9/9 passed.
  • --filter decision: 16/16 passed.
  • --filter whisper: 3/3 passed.
  • --filter multiplayer: 13/13 passed.
  • --filter agent: 19/19 passed.
  • --filter retry: 3/3 passed.

Earlier heads also ran advanced-memory (16/16), capability (18/18), illustrator (6/6), tool (9/9), generation-output, and 34 regressions that mention agentContext, recentMessages, echo-chamber, hiddenContext, resolveGenerationTools, mainResponseSegments or continueMessageId, one by one: all passed. This round's only code change is the chat-model selector's per-line cap.

Manual verification notes

  • Manually verify in a Roleplay chat with Whisper on and Echo Chamber enabled:
    • Send a message that is only [whisper: character="<name>" text="..."].
    • Echo Chamber should react to what was whispered.
    • The other characters' replies, and their Peek Prompt, should not contain the whisper.
  • Manually verify that a tracker or Lorebook Keeper run after a reply whose model wrote a whisper shows the whisper in that agent's prompt (debug mode / DEBUG_AGENTS) as [Private whisper to <name>: ...], at its place in the reply.
  • Manually verify that a reply that is only a whisper still runs the post-generation agents and leaves the message text empty.
  • Manually verify that Prose Guardian or Continuity, run on a reply with a whisper, leaves the whisper text out of the visible message with your usual model.
  • Manually verify in a group chat with Speaker names in history on: continue a reply, writing a whisper in the added text. A post-generation agent's prompt (debug mode) should show the added text with that whisper in place, and none of the reply's earlier whispers in the reply block.
  • Manually verify that a custom script or webhook tool with hidden context, called by a character who is not a whisper's recipient, gets the public {{input}} only.
  • Manually verify that Retry agents on a message with a whisper shows the whisper in the retried agent's prompt.
  • Manually verify in a Roleplay group chat in Individual mode with Smart response order: whisper to one character, for example with a message that is only [whisper: character="Bob" text="..."]. Bob should be a likely pick for the next reply, and a non-recipient's Peek Prompt should not contain the whisper.
    • To see what the selector read, turn on Smart order on the Decision model and UI debug mode: the server log's [decision] ... request line should show [Private whisper to Bob: ...].
    • The chat-model selector's prompt is not logged in UI debug mode (it never was). To see it, set DEBUG_AGENTS=true with an Anthropic agents connection; OpenAI-compatible and Google connections don't log it.
    • Manually verify a whisper of more than 900 characters before a question to another character, for example [whisper: character="Bob" text="<a long vision>"] Alice, what do you think?: with the chat-model selector, Alice should still be a likely pick.
  • Manually verify in a hosted multiplayer Roleplay room with a whisper that the room's agents (for example a tracker) and its Smart speaker selection get no whisper.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

Docs changed: docs/roleplay/getting-started.md, docs/development/multiplayer.md, CHANGELOG.md (no docs change this round). Translation follow-up: #7436 (updated for the rewritten-reply wording; this round's wording is in a comment there).

Local CodeRabbit review

Eight runs on the branch before the third round (run 9 is under that round). Fixed:

  • The whisper-only placeholder is now replaced by its position, not by a global string replace.
  • Retried non-rewrite agents get the retried reply with its whispers.
  • A whisper-only reply runs post-generation agents.
  • The room gate now covers any room data that isn't an ended room.
  • Blank lines count as no public text.
  • Rewrite agents need public text.

Rejected, with reasons:

  • "Link a [docs-i18n] follow-up" (repeated): #7436 is open and linked above. The CLI doesn't see the PR body.
  • "Build the agent preview from unscoped history, because character scoping drops whisper-only messages": the agents' copy is made before appendRoleplayWhispers drops anything. The regression shows the preview taken after the reply still holds a whisper-only turn meant for another character. The preview mirrors the main prompt that prompt-patch agents can edit, and the agents' history is unscoped.
  • "Activate agents from whisper-aware text" (repeated): keyword and question activation decide whether an agent runs, and they read the stored public text. agent-activation.regression.ts pins post-processing activation to postActivationMessages with content: completedResponse. Changing that is a separate decision for the maintainer. It is not part of what agents read.

Run 8, on the second-round fixes (add3d0b), raised three findings. All are rejected:

  • "Use whisper-aware text in custom-agent activation": the same activation point as above, pinned by agent-activation.regression.ts.
  • "Link a [docs-i18n] follow-up for docs/roleplay/getting-started.md": #7436 covers that path and now includes this round's wording.
  • "Select the responder's tool input before truncating agent history": the main reply's tool {{input}} always came from the truncated agents' window (agentContext.recentMessages), and an empty value when that window held no user message. responderToolInput keeps that rule and only removes the whispers. The one difference: with Advanced Memory on, a whisper-only message now takes a slot in that window. A public user message can drop out a turn earlier only when several whisper-only messages follow it inside a small window, so the suggested separate lookup is not worth it.

Second review round

Fixed, each with a regression that fails without the fix:

  • High: a non-recipient's own custom tool got the whisper. buildCustomToolHiddenContext took macros.input from agentContext.recentMessages, which now holds whispers. The main reply's tool context now takes responderInput, the latest user message's public text. Agents' tool calls keep the whisper-aware context.
  • A continued group reply piled every whisper at the end of the added text. The segment held only the continuation, but its whispers were placed from the whole message's activity. roleplayAgentContinuation now places only the whispers written with the continuation, at their saved places in the whole message, and cuts off the earlier text.
  • The PR said a rewrite agent can never put a whisper into the visible message. That claim was wrong, as noted above: rewrite agents read whispers and write the visible reply. The behaviour stays, because every agent reads whispers. The PR text, docs and changelog now say a rewritten reply can carry one.

Not changed, with reasons:

  • Smart speaker selection (chat-model selector and Decision-model smart order). Held back here because #6878's assertion forbade it. The maintainer has since decided it reads whispers; see the third round.
  • Agent decision statements. Agent and prompt statements share one per-turn answer cache, keyed by chat, latest message and model, and by statement text (prompt-decisions.ts), as well as the sticky and cooldown timers. An answer worked out from whispers for an agent's statement would be reused for a responder's identical statement on a swipe of the same turn, or held by its timer on later turns. That would hand a non-recipient a yes/no taken from a whisper. Doing it safely means separate cache and timer keys for agent statements, which is a follow-up.
  • Memory Nag's vault scan. The scanner is package code in Pasta-Devs/Marinara-Agents (packages/memory-nag/.../scanner.ts), so its fix belongs there. Its recalls are also put into responder prompts, so storing whispers there would carry them to non-recipients. That needs the maintainer's decision first.
  • The combat encounter GM (/encounter/init, /encounter/action). It is not an agent. It runs on the encounter's own connection (the chat's connection by default) and reads raw stored content, without even the hidden-from-AI filter. It saves its summary as a narrator message every character reads. Giving it whispers would be a separate change to the encounter feature. The Illustrator's animation prompt, which reads raw content, is left as is for the same reason.

Not changed, for review

  • The model-facing whisper instruction in buildRoleplayCommandsReminder still says "No one else will be able to access it, except for the appointed narrator."
  • The UI copy roleplay.commands.whisper.description still says "Hide part of a message from everyone but one character (and the narrator)."
  • Both are about characters, so both are still accurate for characters. Rewording either is left to the maintainer.
  • Private notes shared on a message stay character-only. This PR covers whispers.
  • Decision statements (prompt and agent conditionals) and custom agent keyword activation still read public text. Smart order on the Decision model now reads whispers (third round).

Third round: Smart speaker selection

  • Maintainer decision (2026-10-11): Smart speaker selection sees whispers, like every other agent.
  • generate.routes.ts: the Decision model's smart-order transcript and the chat-model selector's transcript now wrap each message in roleplayAgentText(..., message, agentWhisperNames), before timestamps are stripped, so whispers sit at their places in the text. Hosted rooms still give it none, because agentWhisperNames is null there.
  • Test updated with the maintainer's approval: roleplay-user-private-generation.regression.ts now requires the labelled whisper in the selector prompt and still keeps private notes out (see What changed).
  • agents-see-whispers.regression.ts covers both paths, the responder's privacy on that turn, and a hosted room's Smart turn.
  • CHANGELOG.md and docs/roleplay/getting-started.md name Smart response order among the readers, and the changelog says rooms give it none.

Local CodeRabbit, run 9 (on 099d62c), raised four findings:

  • Fixed in 9521bf4, "Give the whisper privacy warning its own short sentence" in docs/roleplay/getting-started.md and "Shorten the changelog entry without losing the warning": the warning that agent output can carry a whisper is now its own sentence in both. The changelog entry keeps its other sentences, because each names a case users will notice (a just-typed whisper, a reply's whispers, a whisper-only message, Smart order, rooms). No rerun after this Markdown-only change.
  • Rejected, "Activate post-processing agents from agentCompletedResponse": the same activation point rejected in earlier runs. Keyword activation decides whether an agent runs, reads the stored public text, and is pinned by agent-activation.regression.ts (postActivationMessages with content: completedResponse). That is a separate maintainer decision.
  • Rejected, "Build the agent prompt before responder-audience filtering": filterPromptMessagesForCharacterAudience drops only messages the user hid from the responder (hiddenFromAICharacterIds), keeping a stand-in when the hidden message carries a whisper to that responder. It does not drop whisper-only messages meant for others; appendRoleplayWhispers does that, after the agents' copy is made. The regression shows the preview taken after Alice's reply still holds the whisper-only turn meant for Bob. A message hidden from the responder is out of the responder's prompt, and so out of the preview that prompt-patch agents edit, as before; agents still read it in their unscoped history.

Fourth round: review fixes

Two reviewer findings, both fixed:

  • Low: a long whisper crowded a turn's public text out of the chat-model selector's 900-character line. The whisper was inserted before the per-line cap, so [whisper: character="Bob" text="<1,050 characters>"] Alice, what do you think? reached the selector as the cut whisper alone and pushed the pick toward Bob. The turn's text and each whisper now get 900 characters apiece. The Decision model's transcript has no per-message cap and is unchanged. Fixed in b66c322, with a regression that fails without it.
  • Low: the manual check asked to see the chat-model selector's prompt in debug mode, but that prompt is never logged there. The selector's chatComplete call passes no debugMode, and only some providers log a request body under DEBUG_AGENTS. The manual check now points to the Decision model's logged request, and to DEBUG_AGENTS with an Anthropic connection for the chat-model selector. The logging gap predates this PR and is left as is.

Local CodeRabbit, run 10 (on b66c322): no findings.

UI evidence (if applicable)

Not applicable: no UI change.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Roleplay agents can read whispers in message order, labeled with their intended recipient. This includes newly added whispers, whispers in replies they process, and messages containing only a whisper.
    • In group chats, Smart response order can use whisper content when selecting who responds. Agents can also use whispers during roleplay responses and related processing; rewrite agents continue to receive only public reply text.
  • Privacy
    • Characters still receive only whispers intended for them. Agents and Smart response order do not receive whispers during hosted multiplayer room generation.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7437 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/11/2026 **Status:** ✅ Merged **Merged:** 10/11/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/agents-see-whispers` --- ### 📝 Commits (10+) - [`b29f589`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b29f589d3adb34ba429ba61ffd1f89187c0d50fa) fix(roleplay): let every agent read whispers - [`abeff2d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/abeff2dc92ff4156826a626ce6eefa54ba0bc185) fix(roleplay): replace a whisper-only placeholder by its position - [`034cd7d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/034cd7d5bc276403d97e6d55d7b58b0bbbf638fe) fix(roleplay): give retried agents the reply with its whispers - [`2f38cd1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2f38cd13078d27dc5c386cd1be94c1d5b7d67cca) fix(roleplay): run post-generation agents on a whisper-only reply - [`a0188fa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a0188fa244bf5858a65b75d4a3dbb272b6c1ec3c) fix(roleplay): keep whispers from agents for any unfinished room - [`34054fa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/34054fa801a3aa50bba5026f73f4f7435b7393fb) fix(roleplay): skip rewrites when a turn has only blank public text - [`fe4b231`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fe4b2318eb5695161d8157024b1e53079ff1a507) fix(roleplay): run rewrite agents only on a reply with public text - [`52ec7c4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/52ec7c4a591cf3dd25b6fea956a7adf36378a2ba) fix(roleplay): keep whispers out of a reply's own tools and place a continuation's own - [`add3d0b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/add3d0bae921a8089a9a544f1201afbb2ba44b8c) docs(roleplay): name a rewritten reply among agent output that can carry a whisper - [`099d62c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/099d62c48089249542d14f28698d8c99bd985240) fix(roleplay): let Smart speaker selection read whispers ### 📊 Changes **10 files changed** (+929 additions, -80 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/development/multiplayer.md` (+1 -1) 📝 `docs/roleplay/getting-started.md` (+3 -1) 📝 `packages/server/src/routes/generate.routes.ts` (+124 -33) 📝 `packages/server/src/routes/generate/retry-agents-route.ts` (+35 -7) 📝 `packages/server/src/services/generation/roleplay-commands.ts` (+128 -23) 📝 `packages/server/src/services/generation/tool-resolution-runtime.ts` (+25 -10) 📝 `scripts/regressions/agent-activation.regression.ts` (+4 -4) ➕ `scripts/regressions/agents-see-whispers.regression.ts` (+602 -0) 📝 `scripts/regressions/roleplay-user-private-generation.regression.ts` (+6 -1) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7430 ## Why this change - In Roleplay chats, Echo Chamber and every other agent missed whispers. Agents built their history from each message's visible text, so a whisper never reached them. A message that was only a whisper arrived as a bare `[Private whisper]`, so Echo Chamber knew something was said but not what. Post-generation agents never saw what a character whispered in the reply they were processing, and a reply that was only a whisper skipped them entirely. - Decided behaviour: every agent sees whispers, including Lorebook Keeper and Long-Term Memory. Hosted multiplayer rooms are the exception. - Maintainer decision (2026-10-11): Smart speaker selection in Roleplay group chats sees whispers too, like every other agent. "A whisper to Bob can make Bob the one who replies." ## What changed - **One helper** next to `appendRoleplayWhispers` in `roleplay-commands.ts`: - `roleplayAgentText` renders a message as agents read it: its text with each live whisper (not deleted, no error) at its saved place, as `[Private whisper to <recipient>: <text>]`. The recipient is the character's current name, or the persona's name. - A whisper-only message reads as its whispers: they take the place of its `[Private whisper]` placeholder. - `roleplayAgentPrompt` gives agents their own copy of a prompt and leaves the responder's prompt alone. - Whisper placement inside a message is shared with `appendRoleplayWhispers` (`placeRoleplayWhispers`), so responders and agents put a whisper in the same spot. - **Every agent path that carries chat history** uses it: - `agentContext.recentMessages`, which feeds every pipeline agent, capability packages, agents' tool calls, knowledge retrieval, Music DJ, Illustrator and the expression agent. - Character Activity routing. - Smart speaker selection in group chats: the Decision model's smart-order transcript and the chat-model selector's transcript. A whisper-only message reads as its whispers there instead of `[Private whisper]`. - The chat-model selector caps each transcript line at 900 characters. A turn's text and each of its whispers now get 900 characters apiece (`roleplayAgentText`'s optional `limit`), so a long whisper cannot crowd out what was said aloud. A whisper whose place is cut off follows the cut text. A line with no whispers is cut exactly as before. - The main prompt preview (`_mainPromptPreview`), both before and during generation. - Long-Term Memory recall. - Lorebook Keeper and read-behind history. - The new reply for post-generation agents (`mainResponse`, group response segments and lorebook triggers), taken from the reply's saved activity. - On a continue with speaker names in history, the group segment is only the added text. `roleplayAgentContinuation` gives it only the whispers written with that text, at their places. The message's earlier whispers stay in the agents' history, where they already were. - Media command sources, background scene planning, and the auto-retry of failed agents. - The retry-agents route: history, Lorebook Keeper and read-behind runs, and the retried reply for non-rewrite agents. - With Advanced Memory on, agents now get whisper-only messages in their window, as the preview already did. - **A reply that is only a whisper** now runs post-generation agents. - **Smart speaker selection only picks a speaker.** The chat-model selector's reply is parsed to character IDs, and the Decision model returns one probability per candidate. Only the chosen IDs and names leave the selector (the `response_queue` event); nothing the selector writes is shown to users or put into a responder's prompt. The regression checks that the responder, who is not the whisper's recipient, still gets neither whisper on that turn. The selector's raw reply is written to the server log only when it holds no valid character ID, as before. - **A character's own custom tools stay public.** The main reply's custom tools act for the character responding, so their `{{input}}` (the script and webhook hidden context) is the latest user message's public text, as before. A tool that a non-recipient calls never gets someone else's whisper. Agents' own tool calls keep the agents' input, with whispers. - **Text rewrite agents** (Prose Guardian, Continuity, custom rewrites) are given only the public reply to edit; Marinara never puts a whisper into it. Like every agent, they read whispers in their history and in the prompt preview. So a rewrite model could still write a whisper into the visible message, the same trade-off as a lorebook entry. The docs and changelog name a rewritten reply among agent output that can carry a whisper. - Rewrites now run only when the reply has public text. - This also covers a pre-existing case: a reply with only a media command (or blank lines from several whisper-only replies) used to send rewrite agents an empty reply. - **No double insertion:** agents get the history and the preview as separate copies, each with the whisper once. Agent copies are made from the shared prompt before the responder's own whispers are added. The regression checks both the pre-reply preview and the preview after the reply. - **Unchanged:** - What character responders receive: non-recipients never see a whisper, and whisper-only messages are still dropped for them. - Advanced Memory records. - The responder's Peek Prompt. - **Rooms keep today's behaviour.** Agents get no whispers in a multiplayer room, because every human participant sees agent output. `roleplayAgentsSeeWhispers` uses `currentRoomGeneration()` during room generation, which is the existing room signal. For agent runs started outside it, such as retries, any `multiplayer` metadata other than an ended room counts as a room. That includes guest data, a room with no status, and data that can't be read. This is documented in the code comment and the docs. - **Privacy trade-off:** agent output can now mention a whisper, and that output can reach a character who wasn't the recipient. Examples are a lorebook entry, a tracker note, an Echo Chamber line or a prompt patch. Each whisper is labeled as private so agents know it is a secret. The trade-off is stated in the docs and the changelog. - Docs: `docs/roleplay/getting-started.md` (who reads whispers, and that agent output such as a rewritten reply can carry one) and `docs/development/multiplayer.md` (room agents never read whispers). Comments that said private state never reaches agents are updated. - Changelog entry under `[Unreleased]`. - New regression `scripts/regressions/agents-see-whispers.regression.ts`. It fails on staging and passes with this change. Each guard was also checked by reverting it and watching the regression fail. It covers: - The new reply's whispers reaching a post-generation agent, in place, with labels for a character and the persona. - A whisper-only reply, and a group turn of two whisper-only replies, reaching post-generation agents with no rewrite. - A whisper-only user message reaching a pre-generation (Echo Chamber-like) agent as the whisper itself. - History placement, and both previews without double insertion. - Non-recipient responders still getting none of the whispers, while the recipient keeps them. - Deleted and failed whispers being left out. - Placeholder edge cases. - Retries, both for a non-rewrite agent and for a rewrite agent's public target. - A continued group reply with speaker names in history: the agents' segment holds only the added text and its own whisper, in place. A continuation that added only a whisper reads as that whisper. - A non-recipient's own script tool with hidden context: its `{{input}}` is the public text, and none of that character's requests holds the whisper. - Smart speaker selection, both the Decision-model and the chat-model path: the transcript holds a whisper in place with its label and a whisper-only message as its whisper, and the responder still gets neither. - A 1,061-character whisper before `Alice, what do you think?`: the chat-model selector's line keeps the question and cuts the whisper to its own 900 characters. A helper check covers whispers whose places are cut off, in order. - A real hosted-room generation through the room runner, including a Smart turn whose selector gets no whisper. - The room gate for guest, statusless, malformed and ended room data. - `scripts/regressions/roleplay-user-private-generation.regression.ts:280`, added by #6878, asserted that speaker selection never receives private activity. **Updated with the maintainer's approval** to the new rule, not deleted: the Smart selector's prompt must hold `Public Smart turn. [Private whisper to Bob: SMART_WHISPER_SECRET]`, and private notes must still stay out of it. - `scripts/regressions/agent-activation.regression.ts` is a source-shape test. Four of its patterns now name `agentCompletedResponse` instead of `completedResponse`, because post-processing agents get the completed reply with its whispers. Each pattern is as strict as before. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Commands run by the agent on `b66c322`, the head (results are not evidence for the boxes above): - `pnpm check`: exit 0. - `pnpm regression:prompt`: passed (3 suites). - `--filter agents-see-whispers`: passed. With the selector's route change reverted, the long-whisper check fails (the line holds only the cut whisper). With the helper change reverted, the helper check fails. - `--filter roleplay-user-private-generation`: passed with the updated assertion. - `--filter roleplay-`: 14/14 passed. - `--filter smart`: 1/1 passed. - `--filter group`: 9/9 passed. - `--filter decision`: 16/16 passed. - `--filter whisper`: 3/3 passed. - `--filter multiplayer`: 13/13 passed. - `--filter agent`: 19/19 passed. - `--filter retry`: 3/3 passed. Earlier heads also ran `advanced-memory` (16/16), `capability` (18/18), `illustrator` (6/6), `tool` (9/9), `generation-output`, and 34 regressions that mention `agentContext`, `recentMessages`, `echo-chamber`, `hiddenContext`, `resolveGenerationTools`, `mainResponseSegments` or `continueMessageId`, one by one: all passed. This round's only code change is the chat-model selector's per-line cap. ### Manual verification notes - Manually verify in a Roleplay chat with **Whisper** on and Echo Chamber enabled: - Send a message that is only `[whisper: character="<name>" text="..."]`. - Echo Chamber should react to what was whispered. - The other characters' replies, and their Peek Prompt, should not contain the whisper. - Manually verify that a tracker or Lorebook Keeper run after a reply whose model wrote a whisper shows the whisper in that agent's prompt (debug mode / `DEBUG_AGENTS`) as `[Private whisper to <name>: ...]`, at its place in the reply. - Manually verify that a reply that is only a whisper still runs the post-generation agents and leaves the message text empty. - Manually verify that Prose Guardian or Continuity, run on a reply with a whisper, leaves the whisper text out of the visible message with your usual model. - Manually verify in a group chat with **Speaker names in history** on: continue a reply, writing a whisper in the added text. A post-generation agent's prompt (debug mode) should show the added text with that whisper in place, and none of the reply's earlier whispers in the reply block. - Manually verify that a custom script or webhook tool with hidden context, called by a character who is not a whisper's recipient, gets the public `{{input}}` only. - Manually verify that **Retry agents** on a message with a whisper shows the whisper in the retried agent's prompt. - Manually verify in a Roleplay group chat in **Individual** mode with **Smart** response order: whisper to one character, for example with a message that is only `[whisper: character="Bob" text="..."]`. Bob should be a likely pick for the next reply, and a non-recipient's Peek Prompt should not contain the whisper. - To see what the selector read, turn on Smart order on the Decision model and UI debug mode: the server log's `[decision] ... request` line should show `[Private whisper to Bob: ...]`. - The chat-model selector's prompt is not logged in UI debug mode (it never was). To see it, set `DEBUG_AGENTS=true` with an Anthropic agents connection; OpenAI-compatible and Google connections don't log it. - Manually verify a whisper of more than 900 characters before a question to another character, for example `[whisper: character="Bob" text="<a long vision>"] Alice, what do you think?`: with the chat-model selector, Alice should still be a likely pick. - Manually verify in a hosted multiplayer Roleplay room with a whisper that the room's agents (for example a tracker) and its Smart speaker selection get no whisper. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) Docs changed: `docs/roleplay/getting-started.md`, `docs/development/multiplayer.md`, `CHANGELOG.md` (no docs change this round). Translation follow-up: #7436 (updated for the rewritten-reply wording; this round's wording is in a comment there). ## Local CodeRabbit review Eight runs on the branch before the third round (run 9 is under that round). Fixed: - The whisper-only placeholder is now replaced by its position, not by a global string replace. - Retried non-rewrite agents get the retried reply with its whispers. - A whisper-only reply runs post-generation agents. - The room gate now covers any room data that isn't an ended room. - Blank lines count as no public text. - Rewrite agents need public text. Rejected, with reasons: - **"Link a `[docs-i18n]` follow-up" (repeated):** #7436 is open and linked above. The CLI doesn't see the PR body. - **"Build the agent preview from unscoped history, because character scoping drops whisper-only messages":** the agents' copy is made before `appendRoleplayWhispers` drops anything. The regression shows the preview taken after the reply still holds a whisper-only turn meant for another character. The preview mirrors the main prompt that prompt-patch agents can edit, and the agents' history is unscoped. - **"Activate agents from whisper-aware text" (repeated):** keyword and question activation decide *whether* an agent runs, and they read the stored public text. `agent-activation.regression.ts` pins post-processing activation to `postActivationMessages` with `content: completedResponse`. Changing that is a separate decision for the maintainer. It is not part of what agents read. Run 8, on the second-round fixes (`add3d0b`), raised three findings. All are rejected: - **"Use whisper-aware text in custom-agent activation":** the same activation point as above, pinned by `agent-activation.regression.ts`. - **"Link a `[docs-i18n]` follow-up for `docs/roleplay/getting-started.md`":** #7436 covers that path and now includes this round's wording. - **"Select the responder's tool input before truncating agent history":** the main reply's tool `{{input}}` always came from the truncated agents' window (`agentContext.recentMessages`), and an empty value when that window held no user message. `responderToolInput` keeps that rule and only removes the whispers. The one difference: with Advanced Memory on, a whisper-only message now takes a slot in that window. A public user message can drop out a turn earlier only when several whisper-only messages follow it inside a small window, so the suggested separate lookup is not worth it. ## Second review round Fixed, each with a regression that fails without the fix: - **High: a non-recipient's own custom tool got the whisper.** `buildCustomToolHiddenContext` took `macros.input` from `agentContext.recentMessages`, which now holds whispers. The main reply's tool context now takes `responderInput`, the latest user message's public text. Agents' tool calls keep the whisper-aware context. - **A continued group reply piled every whisper at the end of the added text.** The segment held only the continuation, but its whispers were placed from the whole message's activity. `roleplayAgentContinuation` now places only the whispers written with the continuation, at their saved places in the whole message, and cuts off the earlier text. - **The PR said a rewrite agent can never put a whisper into the visible message.** That claim was wrong, as noted above: rewrite agents read whispers and write the visible reply. The behaviour stays, because every agent reads whispers. The PR text, docs and changelog now say a rewritten reply can carry one. Not changed, with reasons: - **Smart speaker selection (chat-model selector and Decision-model smart order).** Held back here because #6878's assertion forbade it. The maintainer has since decided it reads whispers; see the third round. - **Agent decision statements.** Agent and prompt statements share one per-turn answer cache, keyed by chat, latest message and model, and by statement text (`prompt-decisions.ts`), as well as the sticky and cooldown timers. An answer worked out from whispers for an agent's statement would be reused for a responder's identical statement on a swipe of the same turn, or held by its timer on later turns. That would hand a non-recipient a yes/no taken from a whisper. Doing it safely means separate cache and timer keys for agent statements, which is a follow-up. - **Memory Nag's vault scan.** The scanner is package code in Pasta-Devs/Marinara-Agents (`packages/memory-nag/.../scanner.ts`), so its fix belongs there. Its recalls are also put into responder prompts, so storing whispers there would carry them to non-recipients. That needs the maintainer's decision first. - **The combat encounter GM (`/encounter/init`, `/encounter/action`).** It is not an agent. It runs on the encounter's own connection (the chat's connection by default) and reads raw stored content, without even the hidden-from-AI filter. It saves its summary as a narrator message every character reads. Giving it whispers would be a separate change to the encounter feature. The Illustrator's animation prompt, which reads raw content, is left as is for the same reason. ## Not changed, for review - The model-facing whisper instruction in `buildRoleplayCommandsReminder` still says "No one else will be able to access it, except for the appointed narrator." - The UI copy `roleplay.commands.whisper.description` still says "Hide part of a message from everyone but one character (and the narrator)." - Both are about characters, so both are still accurate for characters. Rewording either is left to the maintainer. - Private notes shared on a message stay character-only. This PR covers whispers. - Decision statements (prompt and agent conditionals) and custom agent keyword activation still read public text. Smart order on the Decision model now reads whispers (third round). ## Third round: Smart speaker selection - Maintainer decision (2026-10-11): Smart speaker selection sees whispers, like every other agent. - `generate.routes.ts`: the Decision model's smart-order transcript and the chat-model selector's transcript now wrap each message in `roleplayAgentText(..., message, agentWhisperNames)`, before timestamps are stripped, so whispers sit at their places in the text. Hosted rooms still give it none, because `agentWhisperNames` is null there. - Test updated with the maintainer's approval: `roleplay-user-private-generation.regression.ts` now requires the labelled whisper in the selector prompt and still keeps private notes out (see What changed). - `agents-see-whispers.regression.ts` covers both paths, the responder's privacy on that turn, and a hosted room's Smart turn. - `CHANGELOG.md` and `docs/roleplay/getting-started.md` name Smart response order among the readers, and the changelog says rooms give it none. Local CodeRabbit, run 9 (on `099d62c`), raised four findings: - Fixed in `9521bf4`, **"Give the whisper privacy warning its own short sentence"** in `docs/roleplay/getting-started.md` and **"Shorten the changelog entry without losing the warning"**: the warning that agent output can carry a whisper is now its own sentence in both. The changelog entry keeps its other sentences, because each names a case users will notice (a just-typed whisper, a reply's whispers, a whisper-only message, Smart order, rooms). No rerun after this Markdown-only change. - Rejected, **"Activate post-processing agents from `agentCompletedResponse`"**: the same activation point rejected in earlier runs. Keyword activation decides whether an agent runs, reads the stored public text, and is pinned by `agent-activation.regression.ts` (`postActivationMessages` with `content: completedResponse`). That is a separate maintainer decision. - Rejected, **"Build the agent prompt before responder-audience filtering"**: `filterPromptMessagesForCharacterAudience` drops only messages the user hid from the responder (`hiddenFromAICharacterIds`), keeping a stand-in when the hidden message carries a whisper to that responder. It does not drop whisper-only messages meant for others; `appendRoleplayWhispers` does that, after the agents' copy is made. The regression shows the preview taken after Alice's reply still holds the whisper-only turn meant for Bob. A message hidden from the responder is out of the responder's prompt, and so out of the preview that prompt-patch agents edit, as before; agents still read it in their unscoped history. ## Fourth round: review fixes Two reviewer findings, both fixed: - **Low: a long whisper crowded a turn's public text out of the chat-model selector's 900-character line.** The whisper was inserted before the per-line cap, so `[whisper: character="Bob" text="<1,050 characters>"] Alice, what do you think?` reached the selector as the cut whisper alone and pushed the pick toward Bob. The turn's text and each whisper now get 900 characters apiece. The Decision model's transcript has no per-message cap and is unchanged. Fixed in `b66c322`, with a regression that fails without it. - **Low: the manual check asked to see the chat-model selector's prompt in debug mode, but that prompt is never logged there.** The selector's `chatComplete` call passes no `debugMode`, and only some providers log a request body under `DEBUG_AGENTS`. The manual check now points to the Decision model's logged request, and to `DEBUG_AGENTS` with an Anthropic connection for the chat-model selector. The logging gap predates this PR and is left as is. Local CodeRabbit, run 10 (on `b66c322`): no findings. ## UI evidence (if applicable) Not applicable: no UI change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Roleplay agents can read whispers in message order, labeled with their intended recipient. This includes newly added whispers, whispers in replies they process, and messages containing only a whisper. * In group chats, Smart response order can use whisper content when selecting who responds. Agents can also use whispers during roleplay responses and related processing; rewrite agents continue to receive only public reply text. * **Privacy** * Characters still receive only whispers intended for them. Agents and Smart response order do not receive whispers during hosted multiplayer room generation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:06:58 +07:00
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#7733
No description provided.