Skip to content

fix: merge system messages for llama.cpp compatibility#10

Open
winmutt wants to merge 1 commit intojoshuadavidthomas:mainfrom
winmutt:fix/llama-cpp-system-message
Open

fix: merge system messages for llama.cpp compatibility#10
winmutt wants to merge 1 commit intojoshuadavidthomas:mainfrom
winmutt:fix/llama-cpp-system-message

Conversation

@winmutt
Copy link
Copy Markdown

@winmutt winmutt commented Apr 7, 2026

Problem

Using the opencode-agent-memory plugin with Qwen 3.5 via llama.cpp results in:

Error: Jinja Exception: System message must be at the beginning.

Root Cause

The experimental.chat.system.transform hook adds memory blocks and journal instructions to system messages without merging pre-existing system messages. When the provider already has multiple system messages, the plugin leaves them as multiple messages, which violates llama.cpp Jinja template requirements.

Solution

Merge all system messages (memory blocks, provider content, journal instructions) into a single system message at index 0.

Testing

Added unit tests in src/plugin.test.ts to verify:

  • Multiple system messages are merged into one
  • Empty system arrays are handled
  • Memory blocks are prepended before provider content

- Merge memory blocks, provider system content, and journal instructions
  into a single system message at index 0
- Fixes 'System message must be at the beginning' error with Qwen 3.5
  when using llama.cpp/Jinja templates
- Add unit tests for system message transformation
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.

1 participant