Troubleshooting Message Ordering Conflict Errors When Connecting Open-Source LLMs to Agent Frameworks
This guide shows how to troubleshoot the "Message ordering conflict" error when an agent framework connects to an open-source large language model through a provider configuration. It covers prerequisites, protocol adaptation, a minimal reproduction, message structures in reasoning mode, safe session cache cleanup, and a final checklist.
1. Scope and Prerequisites
This guide is for developers who use a general-purpose agent framework and connect a third-party or self-hosted open-source model through a provider configuration. In this article, the framework name is written as <agent-framework> and the version number as vX.Y.Z. Replace these with the framework name and version you use. Configuration fields, log formats, and command names vary widely between frameworks. The examples illustrate the troubleshooting approach and should not be run as written.
Before you start troubleshooting, confirm the following:
- The framework name and version. Run
<agent-framework> --versionto check. - The provider type, the interface address (base_url), and the model identifier (model id).
- Whether reasoning mode is enabled (the reasoning parameter or a similar switch), and where that switch takes effect.
- When the error first appeared, and whether you changed the provider or model parameters before it appeared.
2. Current Use of Open-Source Models in Agents
Over the past one to two years, open-source models have improved noticeably in code generation, multi-step reasoning, and long-context processing. More agent projects now use them as their core model.
Teams usually choose open-source models for three reasons.
First, deployment cost is manageable. A company can run its own inference service or rent cloud compute and pay for actual usage. The actual cost depends on model size, concurrency, and compute prices, so teams should estimate it against their own workloads rather than apply someone else’s figures.
Second, data stays in-house. Teams with strict compliance requirements can deploy the model on a private network and use it with an internal knowledge base, which reduces data sent to external parties.
Third, the model is easier to adapt to a specific business. Teams can fine-tune the open weights to fit a particular instruction format.
Usage ranking boards on some platforms show how popular a model is, but each platform counts usage differently. This article does not cite specific rankings. Choose a model based on the results of your own task evaluations.
3. Provider Configuration and Protocol Adaptation
Agent frameworks usually include an adaptation layer that converts the interfaces of different vendors into the framework’s internal message format. Many frameworks use the OpenAI format or the Anthropic format as their baseline. When you connect an open-source model, a common approach is to choose a compatible protocol type and point base_url to a model gateway.
When the adaptation layer fails, the problem may occur at one of these points:
- The provider type is wrong. For example, a service that only supports the OpenAI interface was configured as a native Anthropic type.
- The provider name is not in the framework’s built-in mapping table, so the framework handles the response with a default or generic branch.
- A gateway rewrites the request, for example by merging consecutive messages or moving the system message.
Check the framework documentation and the actual logs to confirm which of these applies. Until you have evidence, do not assume any specific point is the cause.
4. Minimal Reproduction of the “Message ordering conflict” Error
The error message usually looks like this:
Message ordering conflict - please try again. If this persists, use /new to start a fresh session.
This error means the framework found that the role order or message structure did not match what it expected while validating the message sequence. It does not necessarily mean the model itself is at fault. The following steps help you locate the problem:
- Record the framework version and the complete provider configuration. Remove sensitive information such as api_key.
- Create a clean test configuration that contains only one provider and one model.
- Turn off reasoning mode, send a simple message, and confirm that basic conversation works.
- Turn on reasoning mode, send the same message, and check whether the error appears.
- Turn on the framework’s debug logging. Save the payload of this request and the response body returned by the model.
- Compare the role order and field structure in the two logs.
If step 3 works and step 4 reproduces the error, the problem is related to the response structure in reasoning mode. In that case, focus on the field comparison in Section 5.
Possible causes include, but are not limited to, incorrect protocol mapping, reasoning-related fields being parsed incorrectly, and a stale session cache that does not match the new configuration. The logs’ actual fields determine which cause applies.
5. Message Structure Reference for Reasoning Mode
When reasoning mode is on, the model’s response messages may contain extra fields. Vendors name and place these fields differently. The table below lists several common cases. Check each vendor’s official documentation for the exact behavior.
| Field or structure | Common location | Purpose | What to check |
|---|---|---|---|
| content | Body of an assistant message | The reply shown to the user | Whether it is empty or truncated |
| reasoning_content | Assistant messages from some vendors | Chain-of-thought content | Whether it is parsed as body text or as a separate message |
| tool_calls | Assistant message | Tool call request | Whether a matching tool message follows it |
| thinking block | content array from some vendors | Extended thinking content | Whether it is returned unchanged in tool-calling scenarios, as the vendor requires |
| role | All messages | Message role | Whether two consecutive messages share the same role, and whether the system message is in the correct position |
Some APIs require that chain-of-thought fields not be sent back in later turns of a multi-turn request. Other APIs require that thinking blocks be returned unchanged when tools are called. These two requirements conflict. If the framework applies one rule to every vendor, it can break the message order. Confirm the target vendor’s rule first, then check whether the framework follows it.
6. Clearing the Session Cache Safely and Restarting the Service
After you change a provider or model parameter, the framework may still keep session state created with the old configuration. If the old session is incompatible with the new configuration, the error can keep appearing. Back up your data before you clear the session, so you do not delete anything you still need.
- Confirm the session directory path. Each framework stores sessions in a different location. Check the framework documentation or its configuration file:
SESSION_DIR="<agent-framework session directory>"ls -la "$SESSION_DIR"
- Back up first, then clear. The backup directory name includes a timestamp so you can roll back if needed:
BACKUP="$HOME/agent-session-backup-$(date +%Y%m%d%H%M%S)"mkdir -p "$BACKUP"cp -a "$SESSION_DIR"/. "$BACKUP"/
- After you confirm the backup is complete, move the original directory aside instead of deleting it:
mv "$SESSION_DIR" "${SESSION_DIR}.old.$(date +%s)"
Before you run this step, confirm that the framework recreates the session directory on startup. If it does not, create an empty directory manually first. Otherwise, the service may fail to start.
- Restart the gateway service so the new configuration takes effect:
<agent-framework> gateway restart
- Start a new session with
/new, then send a test message.
If your framework provides a built-in command to clear sessions, use that command instead of changing files directly.
7. Configuration Example
The following example only shows the field structure. Replace the field names and values with the official syntax from the framework documentation:
providers:- name: my-open-modeltype: openai-compatible # Choose the mapping type that matches the framework documentationbase_url: https://<your-gateway>/v1api_key: ${MODEL_API_KEY} # Read from an environment variable, not written into the config filemodel: <model-id>reasoning: true # Check the parameter name and location against the framework documentationoptions:temperature: 0.7
When you write the configuration, keep these points in mind:
- The provider name is only an identifier. Do not use a value that conflicts with a built-in framework name.
- Always read api_key from an environment variable or a secrets manager. Do not write it into code, configuration files, or logs.
- After you change the reasoning switch, also clear the session and restart the service as described in Section 6.
8. Troubleshooting Checklist
Check each item in the table below and mark it off when it passes.
| Check item | Pass criteria | Action |
|---|---|---|
| Framework version | Matches the documented requirement | Upgrade or downgrade to a verified version |
| Provider type | Matches the protocol used by the model gateway | Change the mapping type as described in the framework documentation |
| base_url and model | Returns a normal response when called with curl | Verify the gateway address and model identifier |
| Basic conversation | Works with reasoning mode off | Fix basic connectivity first |
| Reasoning mode logs | Field parsing matches the reference in Section 5 | Adjust the parsing adapter or turn off the related option |
| Session cache | Backed up and moved aside | Repeat the steps in Section 6 |
| Consecutive same-role messages | Not present in the logs | Check whether the gateway merges or rewrites messages |
| Tool call messages | A tool message immediately follows its tool_calls | Check whether multi-turn requests drop intermediate messages |
9. Risks and Precautions
- Always back up before you clear a session. Session files may contain unfinished task state or user data.
- Do not change configurations directly in production. Reproduce the issue in a test environment and confirm the fix before you release it.
- Logs may contain prompts, user input, and API keys. Redact logs before you share them.
- Different models handle chain-of-thought fields differently. When you switch to a new model, repeat the full reproduction process.
- The troubleshooting approach in this guide is based on general message structure patterns. It does not describe how any specific framework works internally. When you run into a problem, use the official framework documentation and source code as the authority.
10. Summary
A “Message ordering conflict” error usually means the framework found message order or structure that did not match its validation expectations. To troubleshoot, follow this sequence: reproduce the issue, read the logs, compare the fields, back up and clear the session, then work through the checklist. Base each step on actual evidence rather than changing the configuration from experience.
Protocol details differ widely across open-source models, and framework adaptation support varies too. When you run into a problem, first reproduce it with a minimal configuration, then decide how far your changes should reach. This approach usually finds the root cause faster and avoids new problems caused by making too many changes at once.
