feat(memory): support inline json prompt injection#18652
Conversation
Widens the jsonPromptInjection type from boolean to boolean | 'system' | 'inline'. The 'inline' mode injects JSON schema instructions into the latest user message instead of the system prompt, preserving prompt cache for providers with prefix-based caching. Adds feature flag 'json-prompt-injection:inline' for runtime capability detection. Co-Authored-By: Mastra Code (crof/glm-5.2) <noreply@mastra.ai>
Co-Authored-By: Mastra Code (crof/glm-5.2) <noreply@mastra.ai>
🦋 Changeset detectedLatest commit: 0ede67b The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
PR triageLinked issue check skipped for core contributor @TylerBarnes. PR complexity score
Applied label: Changed test gateChanged tests failed against the base branch as expected. Label: |
Summary
Adds a new
structuredOutput.jsonPromptInjection: 'inline'mode.Before this PR, JSON prompt injection put the structured-output schema instructions in the system prompt (
true/'system'). That works, but it changes the system prompt for each schema and can defeat provider prompt caching.This PR adds an inline mode that appends the JSON instructions to the latest user message instead, keeping the leading system prompt stable and more cache-friendly.
Behavior by mode:
If there is no user message, inline mode adds a user message containing the JSON instructions. Native
responseFormatis still skipped whenever prompt injection is enabled.The structured-output fallback helpers preserve explicit
'inline'/'system'settings when retrying, instead of coercing every retry totrue.Test plan
Stack