fix(agent): keep system messages first - #39372
Conversation
|
Please review this as soon as possible, as this issue is significantly affecting usability. |
|
Thanks for flagging the impact. The current checks are passing, and this is awaiting maintainer review. |
|
|
Thanks for the initial fix direction! I believe sorting alone doesn't fully resolve #39275: this change can still emit multiple consecutive system messages (history system prompts + runtime instructions are both serialized as SystemPromptMessage), and the Qwen3.5/3.6 chat template guard that produces the 400 rejects any system message that is not exactly the first one — including a second adjacent one (see vllm-project/vllm#41114). Since the provider plugin and SDK pass prompt_messages through 1:1 without merging, the caller must merge everything into a single leading system message. I've opened #39704 with that approach and regression tests for the multi-system case — happy to fold it into this PR instead if you prefer. |
|
Updated this PR to merge all system content into one leading message while preserving non-system message order. Added coverage for runtime instructions and system prompts accumulated across history. Tested: uv run --project dify-agent --python 3.12 --extra server pytest dify-agent/tests/local/dify_agent/adapters/llm/test_model.py -q |
Summary
Testing
Notes
uv run --project . --extra server basedpyright --level error src examples testscurrently reports existing errors outside the touched LLM adapter files.