Skip to content

Restructure system prompt per OpenAI best practices#219

Open
bajman wants to merge 2 commits intodev-chat:masterfrom
bajman:refactor/restructure-system-prompt
Open

Restructure system prompt per OpenAI best practices#219
bajman wants to merge 2 commits intodev-chat:masterfrom
bajman:refactor/restructure-system-prompt

Conversation

@bajman
Copy link
Copy Markdown

@bajman bajman commented Mar 29, 2026

Summary

  • Reorganized MOONBEAM_SYSTEM_INSTRUCTIONS into semantically separated XML sections (<task>, <identity>, <constraints>, <voice>, <tone>, <personality>, <memory_behavior>, <response_strategy>, <examples>, <verification>) following OpenAI's GPT-5+ prompting guidance
  • Moved critical constraints to the top of the prompt (primacy effect) and added a <verification> checklist at the end (recency effect)
  • Reframed hard rules with positive framing where possible
  • Integrated MEMORY_USAGE_INSTRUCTION into the main prompt as <memory_behavior> instead of appending it at the end at runtime
  • Memory data now inserted before <verification> so the self-check is always the last thing the model sees
  • Categorized example responses by the behavior they demonstrate

No personality, voice, or behavioral content was changed — this is a structural reorganization only.

Test plan

  • Backend build passes clean
  • All 594 backend tests pass
  • Manual verification: @moonbeam in a test channel and confirm persona/tone/voice are consistent with current behavior

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Reorganizes Moonbeam’s system prompt into structured XML-like sections and adjusts how memory context is injected so the verification checklist remains the last section of the assembled instructions.

Changes:

  • Restructured MOONBEAM_SYSTEM_INSTRUCTIONS into tagged sections and added a trailing <verification> checklist.
  • Changed memory formatting to emit a <memory_context> block instead of prepending MEMORY_USAGE_INSTRUCTION.
  • Updated prompt assembly to insert memory context before <verification> when present (with a fallback append behavior).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
packages/backend/src/ai/ai.service.ts Updates memory context formatting and insertion logic to place memories before <verification>.
packages/backend/src/ai/ai.constants.ts Rewrites Moonbeam system instructions into tagged sections; deprecates MEMORY_USAGE_INSTRUCTION.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

sfreeman422
sfreeman422 previously approved these changes Mar 29, 2026
@sfreeman422 sfreeman422 dismissed their stale review March 29, 2026 02:23

Copilot has interesting feedback

- Restore memory-usage guidance in <memory_context> block so non-Moonbeam
  prompts (e.g. GENERAL_TEXT_INSTRUCTIONS) still receive it
- Use lastIndexOf for <verification> tag insertion to handle edge cases
- Add unit tests for both appendMemoryContext branches
- Remove dead MEMORY_USAGE_INSTRUCTION export

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
.join('\n');

return `${MEMORY_USAGE_INSTRUCTION}\n\nthings you remember about the people in this conversation:\n${lines}`;
const guidance = [
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have this in the <memory-behavior> block, why do we need this?

if (insertionPoint !== -1) {
return `${baseInstructions.slice(0, insertionPoint)}${memoryContext}\n\n${baseInstructions.slice(insertionPoint)}`;
}
// Fallback for non-standard instructions (e.g. custom prompts, GENERAL_TEXT_INSTRUCTIONS)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we want this - memories should only be present on contextual prompts (prompt-with-history, participate) - when a user uses /text for example, we do not really care about memories, we just want Moonbeam to answer the question.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants