[PR #479] [MERGED] Optimize expression agent prompts and normalize context sizes #4634

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/479
Author: @Xelvanis
Created: 5/6/2026
Status: ✅ Merged
Merged: 5/6/2026
Merged by: @Xelvanis

Base: main ← Head: fix/expression-engine-context-bloat


📝 Commits (1)

  • c535930 Optimize expression agent prompts and normalize context sizes

📊 Changes

4 files changed (+298 additions, -39 deletions)

View changed files

📝 packages/server/src/routes/generate.routes.ts (+4 -2)
📝 packages/server/src/routes/generate/retry-agents-route.ts (+2 -2)
📝 packages/server/src/services/agents/agent-executor.ts (+157 -35)
➕ packages/server/test/agent-executor-expression.test.ts (+135 -0)

📄 Description

Expression agents now use a compact dedicated message builder that omits lore, character cards, persona descriptions, and summaries. They are also run outside the batch pipeline to avoid inflating batch context. Context sizes are clamped to 1–200 via a shared normalizeAgentContextSize helper.

Linked issue

Closes #436

Why this change

  • Fixes Expression Engine prompts growing with oversized saved agent context settings, which can make tiny scenes consume nearly the full model context window.

What changed

  • Added server-side normalization so agent context size is treated as a bounded message count.
  • Built a compact Expression Engine prompt that includes only sprite options, minimal recent context, and the latest assistant response.
  • Runs Expression Engine separately from larger batched agent prompts so it does not inherit unrelated lore or tracker context.
  • Added focused server tests for runaway context size, compact expression prompts, and mixed batch behavior.

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

  • pnpm --filter @marinara-engine/server test
  • pnpm check
  • Exchanged messages in chat with Expression Engine enabled, verifying agents all still work normally.

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)

UI evidence (if applicable)

Summary by CodeRabbit

  • New Features

    • Expression agents now support rendering available sprites in their execution context
  • Bug Fixes

    • Enhanced agent context size validation to prevent invalid or out-of-bounds values
  • Tests

    • Added test suite covering expression agent workflows and context normalization

🔄 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/479 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 5/6/2026 **Status:** ✅ Merged **Merged:** 5/6/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `main` ← **Head:** `fix/expression-engine-context-bloat` --- ### 📝 Commits (1) - [`c535930`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c5359308af00ab095a3e8d554b56a94c6657bc09) Optimize expression agent prompts and normalize context sizes ### 📊 Changes **4 files changed** (+298 additions, -39 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/generate.routes.ts` (+4 -2) 📝 `packages/server/src/routes/generate/retry-agents-route.ts` (+2 -2) 📝 `packages/server/src/services/agents/agent-executor.ts` (+157 -35) ➕ `packages/server/test/agent-executor-expression.test.ts` (+135 -0) </details> ### 📄 Description Expression agents now use a compact dedicated message builder that omits lore, character cards, persona descriptions, and summaries. They are also run outside the batch pipeline to avoid inflating batch context. Context sizes are clamped to 1–200 via a shared normalizeAgentContextSize helper. ## Linked issue <!-- Every PR should reference a feature request or issue report. If there isn't one yet, open one first to gather opinions: --> <!-- https://github.com/Pasta-Devs/Marinara-Engine/issues/new/choose --> Closes #436 ## Why this change - Fixes Expression Engine prompts growing with oversized saved agent context settings, which can make tiny scenes consume nearly the full model context window. ## What changed - Added server-side normalization so agent context size is treated as a bounded message count. - Built a compact Expression Engine prompt that includes only sprite options, minimal recent context, and the latest assistant response. - Runs Expression Engine separately from larger batched agent prompts so it does not inherit unrelated lore or tracker context. - Added focused server tests for runaway context size, compact expression prompts, and mixed batch behavior. ## Validation - [X] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [X] Ran the app, clicked through the changes manually - [ ] 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 - `pnpm --filter @marinara-engine/server test` - `pnpm check` - [X] Exchanged messages in chat with Expression Engine enabled, verifying agents all still work normally. ## Docs and release impact - [X] 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) ## UI evidence (if applicable) <!-- Add before/after screenshots or recordings for UI changes --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Expression agents now support rendering available sprites in their execution context * **Bug Fixes** * Enhanced agent context size validation to prevent invalid or out-of-bounds values * **Tests** * Added test suite covering expression agent workflows and context normalization <!-- 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-22 04:09:21 +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#4634
No description provided.