Skip to content

feat(memory): support inline json prompt injection#18652

Open
TylerBarnes wants to merge 2 commits into
refactor/processor-agent-contextfrom
feat/inline-json-injection
Open

feat(memory): support inline json prompt injection#18652
TylerBarnes wants to merge 2 commits into
refactor/processor-agent-contextfrom
feat/inline-json-injection

Conversation

@TylerBarnes

@TylerBarnes TylerBarnes commented Jun 29, 2026

Copy link
Copy Markdown
Member

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.

await agent.generate('Extract the task details', {
  structuredOutput: {
    schema: taskSchema,
    jsonPromptInjection: 'inline',
  },
});

Behavior by mode:

jsonPromptInjection: true      // inject into system prompt
jsonPromptInjection: 'system'  // inject into system prompt
jsonPromptInjection: 'inline'  // inject into latest user message

If there is no user message, inline mode adds a user message containing the JSON instructions. Native responseFormat is still skipped whenever prompt injection is enabled.

The structured-output fallback helpers preserve explicit 'inline' / 'system' settings when retrying, instead of coercing every retry to true.

Test plan

Stack

TylerBarnes and others added 2 commits June 29, 2026 15:58
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-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0ede67b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@mastra/core Minor
mastracode Patch
@mastra/mcp-docs-server Patch
@internal/playground Patch
@mastra/client-js Patch
@mastra/opencode Patch
@mastra/longmemeval Patch
mastra Patch
@mastra/deployer-cloud Minor
@mastra/react Patch
@mastra/playground-ui Patch
@mastra/server Minor
@mastra/deployer Minor
create-mastra Patch
@mastra/express Patch
@mastra/fastify Patch
@mastra/hono Patch
@mastra/koa Patch
@mastra/nestjs Patch
@mastra/next Patch
@mastra/tanstack-start Patch
@mastra/temporal Patch

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

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0953345e-01cc-4833-9259-fbf982ed5e06

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/inline-json-injection

Comment @coderabbitai help to get the list of available commands.

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mastra-docs-1.x Ready Ready Preview, Comment Jun 29, 2026 11:17pm
mastra-playground-ui Ready Ready Preview, Comment Jun 29, 2026 11:17pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
mastra-studio-preview Ignored Ignored Jun 29, 2026 11:17pm

Request Review

@dane-ai-mastra

dane-ai-mastra Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

PR triage

Linked issue check skipped for core contributor @TylerBarnes.


PR complexity score

Factor Value Score impact
Files changed 9 +18
Lines changed 259 +15
Author merged PRs 564 -20
Test files changed Yes -10
Final score 3

Applied label: complexity: low


Changed test gate

Changed tests failed against the base branch as expected.

Label: tests: green ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

complexity: low Low-complexity PR tests: green ✅ Changed tests failed against base as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant