[PR #884] [MERGED] Fix built-in agent prompt sections and KR roleplay leakage #4819

Closed
opened 2026-10-22 04:10:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/884
Author: @Promansis
Created: 5/15/2026
Status: ✅ Merged
Merged: 5/15/2026
Merged by: @Promansis

Base: staging ← Head: fix/851-854-agent-prompt-sections


📝 Commits (2)

📊 Changes

6 files changed (+258 additions, -14 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+62 -12)
📝 packages/server/src/services/agents/agent-executor.ts (+71 -0)
📝 packages/server/test/agent-executor-expression.test.ts (+32 -0)
📝 packages/server/test/lorebook-processing.test.ts (+65 -0)
📝 packages/server/test/runtime-agent-section-cleanup.test.ts (+26 -1)
📝 packages/shared/src/constants/agent-prompts.ts (+2 -1)

📄 Description

Linked issue

Closes #851
Closes #854

Why this change

  • Built-in pre-generation agent outputs such as Prose Guardian could miss their explicit prompt preset section and fall back to generic bottom-of-prompt injection.
  • Knowledge Retrieval could receive recent RP chat as normal conversation turns, which made smaller/local models continue the scene in-character instead of summarizing source material.

What changed

  • Generalized runtime prompt-section replacement from Knowledge Retrieval/Router to any active built-in pre-generation context-injection agent.
  • Kept KR/Router fallback behavior so they still append when no explicit preset section handles their output.
  • Added a Knowledge Retrieval-specific agent prompt message shape that wraps recent chat as <conversation_messages> in a final user message instead of sending it as continuation-ready chat turns.
  • Strengthened the default Knowledge Retrieval prompt to explicitly avoid roleplay and treat conversation messages as analysis context.
  • Added focused server coverage for generic runtime agent sections and Knowledge Retrieval prompt shape.

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

Manual verification notes

  • Automated validation run by Codex: pnpm --filter @marinara-engine/server exec tsx --import ./test/setup-env.ts --test test/lorebook-processing.test.ts test/runtime-agent-section-cleanup.test.ts test/agent-executor-expression.test.ts; passed.
  • Automated validation run by Codex: pnpm check; passed after running pnpm install to hydrate the local missing @dnd-kit/core package from the existing lockfile.
  • Not run: live RP prompt preset manual verification with Prose Guardian/Knowledge Retrieval and a real model.
  • Not run: Docker/Podman container verification.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

No docs or release metadata changes expected; this is a narrow server prompt assembly and agent prompt-shaping fix.

UI evidence (if applicable)

N/A. Server prompt assembly and agent prompt behavior only; no UI surface changed.


🔄 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/884 **Author:** [@Promansis](https://github.com/Promansis) **Created:** 5/15/2026 **Status:** ✅ Merged **Merged:** 5/15/2026 **Merged by:** [@Promansis](https://github.com/Promansis) **Base:** `staging` ← **Head:** `fix/851-854-agent-prompt-sections` --- ### 📝 Commits (2) - [`66d8dd5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/66d8dd50a810bf2549dda3a6e28a9521a1586255) Fix agent prompt sections for #851 and #854 - [`e726a83`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e726a8346bdec5cc59fecc0970620a9dd5c6f7b0) fix #851 preserve section agent injection cache ### 📊 Changes **6 files changed** (+258 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+62 -12) 📝 `packages/server/src/services/agents/agent-executor.ts` (+71 -0) 📝 `packages/server/test/agent-executor-expression.test.ts` (+32 -0) 📝 `packages/server/test/lorebook-processing.test.ts` (+65 -0) 📝 `packages/server/test/runtime-agent-section-cleanup.test.ts` (+26 -1) 📝 `packages/shared/src/constants/agent-prompts.ts` (+2 -1) </details> ### 📄 Description ## Linked issue Closes #851 Closes #854 ## Why this change - Built-in pre-generation agent outputs such as Prose Guardian could miss their explicit prompt preset section and fall back to generic bottom-of-prompt injection. - Knowledge Retrieval could receive recent RP chat as normal conversation turns, which made smaller/local models continue the scene in-character instead of summarizing source material. ## What changed - Generalized runtime prompt-section replacement from Knowledge Retrieval/Router to any active built-in pre-generation context-injection agent. - Kept KR/Router fallback behavior so they still append when no explicit preset section handles their output. - Added a Knowledge Retrieval-specific agent prompt message shape that wraps recent chat as `<conversation_messages>` in a final user message instead of sending it as continuation-ready chat turns. - Strengthened the default Knowledge Retrieval prompt to explicitly avoid roleplay and treat conversation messages as analysis context. - Added focused server coverage for generic runtime agent sections and Knowledge Retrieval prompt shape. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Automated validation run by Codex: `pnpm --filter @marinara-engine/server exec tsx --import ./test/setup-env.ts --test test/lorebook-processing.test.ts test/runtime-agent-section-cleanup.test.ts test/agent-executor-expression.test.ts`; passed. - Automated validation run by Codex: `pnpm check`; passed after running `pnpm install` to hydrate the local missing `@dnd-kit/core` package from the existing lockfile. - Not run: live RP prompt preset manual verification with Prose Guardian/Knowledge Retrieval and a real model. - Not run: Docker/Podman container verification. ## Docs and release impact - [x] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [x] Version/release files updated (only if this PR includes a version bump) No docs or release metadata changes expected; this is a narrow server prompt assembly and agent prompt-shaping fix. ## UI evidence (if applicable) N/A. Server prompt assembly and agent prompt behavior only; no UI surface changed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:10:55 +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#4819
No description provided.