hermes - 💡(How to fix) Fix Mistral models fail with 'Unexpected role user after role tool' in multi-turn tool conversations [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#20154Fetched 2026-05-06 06:38:22
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×4

Error Message

When using Mistral models (e.g. mistralai/mistral-small-4-119b-2603) via NIM or any OpenAI-compatible endpoint, conversations break after tool use. The error is:

Code Example

HTTP 400: Unexpected role 'user' after role 'tool'
RAW_BUFFERClick to expand / collapse

When using Mistral models (e.g. mistralai/mistral-small-4-119b-2603) via NIM or any OpenAI-compatible endpoint, conversations break after tool use. The error is:

HTTP 400: Unexpected role 'user' after role 'tool'

Mistral's chat format requires an assistant message between tool results and the next user message. Other providers (OpenAI, Anthropic, NVIDIA Nemotron) are lenient about this ordering, but Mistral strictly enforces it.

Suggested fix: Insert a synthetic empty assistant message (or merge tool results into the preceding assistant turn) before appending the next user message when the model is a Mistral variant.

Reproduction:

  1. Set model to mistralai/mistral-small-4-119b-2603 (provider: NIM or any OpenAI-compatible)
  2. Send a message that triggers a tool call (e.g. search_files)
  3. After tool results return and the assistant responds, send a follow-up user message
  4. Gateway returns HTTP 400

Environment:

  • Hermes Agent v0.12.0 (latest main as of 2026-05-05)
  • Provider: NIM (https://integrate.api.nvidia.com/v1)
  • Model: mistralai/mistral-small-4-119b-2603
  • Platform: macOS, Telegram

extent analysis

TL;DR

Insert a synthetic empty assistant message before appending the next user message when using Mistral models to resolve the HTTP 400 error.

Guidance

  • Verify that the issue occurs only with Mistral models and not with other providers like OpenAI or Anthropic.
  • Check the conversation flow to ensure that an assistant message is sent after tool results and before the next user message.
  • Implement the suggested fix by inserting a synthetic empty assistant message or merging tool results into the preceding assistant turn.
  • Test the fix by reproducing the issue using the provided reproduction steps and verifying that the HTTP 400 error is resolved.

Example

# Example of inserting a synthetic empty assistant message
def send_user_message(message):
    # ... (existing code)
    if using_mistral_model:
        send_assistant_message("")  # Send an empty assistant message
    send_user_message(message)

Notes

This fix may not apply to other models or providers that do not strictly enforce the conversation format. Additionally, the implementation details of inserting a synthetic empty assistant message may vary depending on the specific use case and codebase.

Recommendation

Apply the workaround by inserting a synthetic empty assistant message, as it is a targeted fix for the specific issue with Mistral models.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - 💡(How to fix) Fix Mistral models fail with 'Unexpected role user after role tool' in multi-turn tool conversations [1 participants]