Restructure system prompt per OpenAI best practices#219
Restructure system prompt per OpenAI best practices#219bajman wants to merge 2 commits intodev-chat:masterfrom
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
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_INSTRUCTIONSinto tagged sections and added a trailing<verification>checklist. - Changed memory formatting to emit a
<memory_context>block instead of prependingMEMORY_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.
- 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 = [ |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
Summary
MOONBEAM_SYSTEM_INSTRUCTIONSinto semantically separated XML sections (<task>,<identity>,<constraints>,<voice>,<tone>,<personality>,<memory_behavior>,<response_strategy>,<examples>,<verification>) following OpenAI's GPT-5+ prompting guidance<verification>checklist at the end (recency effect)MEMORY_USAGE_INSTRUCTIONinto the main prompt as<memory_behavior>instead of appending it at the end at runtime<verification>so the self-check is always the last thing the model seesNo personality, voice, or behavioral content was changed — this is a structural reorganization only.
Test plan
🤖 Generated with Claude Code