I encountered an issue when using LLMTornado with certain LLM models that require the SystemMessage to be placed as the first message in the conversation. The current implementation of SetupConversation adds the system message after appending user input, which violates this requirement and causes API errors.
Specifically, when using the model Jackrong/Qwen3.5-9B-Claude-4.6-Opus-Reasoning-Distilled-v2-GGUF (a fine-tuned Qwen3.5 model), the API returns an error because the system message appears after the user message in the messages array.
Root Cause
In the SetupConversation method, the execution order is:
- Load existing conversation history (
AddMessagesToConversation)
- Append user input (
AppendUserInput)
- Add system message (
AddSystemMessage)
This results in a messages array where system messages may not be at index 0. For models that strictly enforce the system → user → assistant ordering convention, this causes the API request to be rejected.
Affected Code
private static Conversation SetupConversation(TornadoAgent agent, List<ChatMessagePart>? input = null, List<ChatMessage>? messages = null, string? responseId = null, CancellationToken cancellationToken = default)
{
Conversation chat = agent.Client.Chat.CreateConversation(agent.Options);
chat.RequestParameters.CancellationToken = cancellationToken;
chat = AddMessagesToConversation(chat, messages);
if (input?.Count > 0)
{
chat.AppendUserInput(input);
}
if (!string.IsNullOrEmpty(responseId))
{
chat.RequestParameters.ResponseRequestParameters!.PreviousResponseId = responseId;
}
// System message added at the end
chat.AddSystemMessage(agent.Instructions);
return chat;
}
Expected Behavior
The system message should be the first message in the conversation. For new conversations, the order should be: SystemMessage → UserMessage. For existing conversations, the system message should remain at the beginning of the message array.
Current Behavior
System message is appended after the user input, resulting in an invalid message order for models that enforce the system-first convention.
Steps to Reproduce
- Use LLMTornado version
v3.8.42 or later.
- Configure a
TornadoAgent with a model that requires system message first (e.g., Qwen-based models).
- Call the agent with any user input.
- Observe API error indicating invalid message order.
Environment
Workaround (for users)
For users currently blocked by this issue, a temporary workaround is to ensure that the conversation messages array already contains the system message before calling SetupConversation, by passing it through the messages parameter, and setting agent.Instructions to null or empty to avoid duplicate system messages.
I encountered an issue when using LLMTornado with certain LLM models that require the
SystemMessageto be placed as the first message in the conversation. The current implementation ofSetupConversationadds the system message after appending user input, which violates this requirement and causes API errors.Specifically, when using the model
Jackrong/Qwen3.5-9B-Claude-4.6-Opus-Reasoning-Distilled-v2-GGUF(a fine-tuned Qwen3.5 model), the API returns an error because the system message appears after the user message in the messages array.Root Cause
In the
SetupConversationmethod, the execution order is:AddMessagesToConversation)AppendUserInput)AddSystemMessage)This results in a messages array where system messages may not be at index 0. For models that strictly enforce the
system → user → assistantordering convention, this causes the API request to be rejected.Affected Code
Expected Behavior
The system message should be the first message in the conversation. For new conversations, the order should be:
SystemMessage→UserMessage. For existing conversations, the system message should remain at the beginning of the message array.Current Behavior
System message is appended after the user input, resulting in an invalid message order for models that enforce the system-first convention.
Steps to Reproduce
v3.8.42or later.TornadoAgentwith a model that requires system message first (e.g., Qwen-based models).Environment
Jackrong/Qwen3.5-9B-Claude-4.6-Opus-Reasoning-Distilled-v2-GGUFWorkaround (for users)
For users currently blocked by this issue, a temporary workaround is to ensure that the conversation messages array already contains the system message before calling
SetupConversation, by passing it through themessagesparameter, and settingagent.Instructionstonullor empty to avoid duplicate system messages.