mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #7223] [MERGED] fix(agents): run the include macro in agent prompts #7631
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#7631
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7223
Author: @SpicyMarinara
Created: 10/7/2026
Status: ✅ Merged
Merged: 10/7/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/include-macro-agent-prompts-7212📝 Commits (5)
3bf7431fix(agents): run the include macro in agent promptse31434bfix(agents): fill includes in a retried agent's author's note338f59eMerge remote-tracking branch 'origin/staging' into fix/include-macro-agent-prompts-7212bd81980Merge origin/staging into fix/include-macro-agent-prompts-721250088bcMerge origin/staging into fix/include-macro-agent-prompts-7212📊 Changes
8 files changed (+129 additions, -12 deletions)
View changed files
📝
CHANGELOG.md(+1 -0)📝
packages/server/src/routes/generate.routes.ts(+12 -1)📝
packages/server/src/routes/generate/retry-agents-route.ts(+4 -1)📝
packages/server/src/services/agents/agent-executor.ts(+1 -0)📝
packages/server/src/services/prompt/index.ts(+1 -0)📝
packages/server/src/services/prompt/macro-context.ts(+16 -8)📝
packages/shared/src/types/agent.ts(+3 -1)📝
scripts/regressions/lorebook-include-macro.regression.ts(+91 -1)📄 Description
Linked issue
Closes #7212
Thanks to @usagirei for the report, including the agent debug log that showed
{{include::Time}}going to the provider unchanged while{{random...}}on the next line was filled in.Why this change
{{include::ENTRY}}and{{include::BOOK::ENTRY}}(#6912) work in presets, cards, entries and author's notes, anddocs/prompts/macros.mdlists agent prompt templates as a place where macros work. In agent prompts, though, the include macro reached the model unchanged. Agent prompts are resolved with their own macro context (buildAgentPromptMacroContext), and that context never received the lorebook source the include macro reads. The chat prompt also loads that source only when one of its texts uses the macro, and agent prompt templates were never part of that check.The reporter wants one shared agent (for example a world tracker) to pick up chat-specific instructions from a lorebook entry with the same name in each chat, without making a separate agent per chat.
What changed
AgentContextgets an optionallorebookIncludesfield, andbuildAgentPromptMacroContextpasses it into the macro context. Agent prompts now go through the sameexpandLorebookIncludesstep as the chat prompt. Nothing is copied or reimplemented, so the rules are the same: a name is looked up in the lorebooks this chat uses (its own, its characters' and persona's, and global ones),BOOK::ENTRYand IDs reach any lorebook, disabled entries can be included, and an include that leads back to itself becomes empty.macroSources(next to the agent settings, which already carry alternate prompt templates), so the include source is loaded when an agent prompt uses the macro. The agent context reusespromptMacroContext.lorebookIncludes.buildPromptMacroContextmoved intoloadLorebookIncludesFor, which both the chat prompt and the character activity path use.scripts/regressions/lorebook-include-macro.regression.tsnow runs a real turn with a pre-generation agent, a character activity agent and a post-processing agent, then retries the post-processing agent. Each prompt must contain the included text for both the short form (chat lorebook, disabled entry) and theBOOK::ENTRYform (a disabled lorebook the chat doesn't use). A short form naming an entry in a lorebook the chat doesn't use must come out empty, and no request may still contain a raw{{include::. A last retry checks the author's note case with an agent whose own prompt has no include. It fails onstagingand passes here. I also removed each route change one at a time, and the matching assertion failed each time.Side effect:
{{lorebooksize::ID}}in an agent prompt used to read0unless the chat prompt also used it. On the main and retry routes it now gives the real count, because the counts use the same source check. I checked this with a throwaway run, not a kept assertion. Character activity agents still get0for it because their context never had counts. That's out of scope here.Also not changed here, because no macro is filled in there today, not just this one: the author's note that character activity agents read, and the Illustrator template that Game mode copies into its image prompt writer.
Agent-package boundary: this is Engine-owned macro and context handling. Package-owned agents run through the same Engine executor and get the fix with no package change.
AgentContext.lorebookIncludesis optional and only the Engine reads it, so vendored shared snapshots in Marinara-Agents don't need it.Contexts without the include source behave as before. If an agent prompt doesn't use the macro, nothing is loaded. If loading fails, a warning is logged and the macro stays as written, the same as in the chat prompt. Professor Mari doesn't render agent prompt templates, so it isn't affected.
Validation
pnpm checkpasses locallyCONTRIBUTING.mdCommands run by the agents:
pnpm check(exit 0 on both commits),node ./scripts/run-regressions.mjs --filter scripts/regressions/lorebook-include-macro.regression.ts(fails onstaging, passes here),pnpm regression:prompt, and these regressions, all passing:agent-activation-questions,agent-activation,agent-connection-parameters,agent-context-generation,agent-previous-output,agent-progress,agent-retry-batching,agent-runtime,agent-scene-check,capability-agent-runtime,character-activity-agent,generate-agent-abort,manual-agent-retry-resolution,decision-conditionals,capability-prompt-preview,illustrator-*,advanced-memory-post-generation,chat-variable-historyand others that build a prompt macro context. Local CodeRabbit (coderabbit review --agent --committed) found nothing on the first commit (3bf74311b). For the second commit (e31434bf6) the local run was rate limited, so only the GitHub review covers it.Also checked with throwaway runs (not kept): two post-processing agents batched into one request both get their includes; an alternate prompt template chosen for the chat gets them too;
{{user}},{{char}}and{{#if}}in an agent prompt come out the same as before; an entry that includes itself stops; and a short form can't reach a lorebook that belongs to another chat.BOOK::ENTRYcan, which is how the macro already works in chat prompts (#6912). In a shared room, lorebook listing is already limited to the room's lorebooks, so includes are too.Manual verification notes
Timeto a lorebook that the chat uses, put{{include::Time}}in a custom agent's prompt, enable the agent for the chat, and send a message. The[agent-debug] ... provider requestlog should show the entry text instead of the macro.{{include::<another lorebook's name>::<entry name>}}in the same prompt for a lorebook that isn't added to the chat, and confirm its text appears in the agent request.{{include::Time}}in its prompt, and check that Retry Agents on the last message sends the included text too.{{include::Time}}in the chat's author's note (and nowhere in the agent's prompt), then use Retry Agents on a built-in agent such as World State. Its provider request in the debug log should show the entry text inside the author's notes.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)CHANGELOG.mdhas a new[Unreleased]entry. Docs underdocs/don't change:docs/prompts/macros.mdalready lists agent prompt templates as a place where macros work, and this PR makes that true for the include macro. No translations are affected.UI evidence (if applicable)
Not applicable. This is a server-side prompt change.
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.