hermes - ✅(Solved) Fix Ollama Cloud: HTTP 400 role alternation error when using tools [1 pull requests, 1 comments, 2 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#23024Fetched 2026-05-11 03:31:41
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×4commented ×1cross-referenced ×1

Error Message

  1. → HTTP 400 error
  • Show a clear error/warning to the user instead of a raw HTTP 400

Root Cause

Ollama Cloud's API does not support tool role messages in conversation history. It only accepts strict user/assistant alternation. When Hermes makes a tool call, it appends tool role messages which Ollama Cloud then rejects on the next turn.

Fix Action

Fixed

PR fix notes

PR #23054: fix(ollama-cloud): collapse tool-role messages for strict user/assistant alternation

Description (problem / solution / changelog)

Problem

When using Ollama Cloud as the provider, any session involving tool calls fails with HTTP 400:

"Conversation roles must alternate user/assistant/user/assistant..."

Ollama Cloud's API only accepts strict user/assistant alternation — it does not support tool-role messages. When Hermes makes a tool call, the resulting tool-role messages in the conversation history cause this error on every subsequent turn, making tool-using sessions completely unusable on Ollama Cloud.

Fix

Override prepare_messages() on the OllamaCloudProfile to transform the conversation before sending:

  1. Strip tool_calls from assistant messages — the model won't generate them since Ollama Cloud doesn't support native tool calling.
  2. Convert tool-role messages to user-role — embed the tool output as readable text: [Tool result from `tool_name`]: output.
  3. Merge consecutive user messages — when multiple tool results are converted, they're merged into a single user message to avoid consecutive same-role messages.

This keeps the conversation within the strict alternation constraint that Ollama Cloud enforces, while preserving tool output as context for the model.

Before vs After

ScenarioBeforeAfter
Tool call on Ollama CloudHTTP 400 on every turnWorks — tool output embedded in user messages
Clean conversation (no tools)WorksWorks — passthrough, no changes
Multimodal tool resultN/A (error before reaching this)Text parts extracted, images stripped

Tests

4 new tests in tests/providers/test_provider_profiles.py::TestOllamaCloudProfile:

  • test_prepare_messages_strips_tool_calls_from_assistant — verifies tool_calls field removed
  • test_prepare_messages_merges_consecutive_user_messages — verifies multi-tool results merged
  • test_prepare_messages_passes_through_clean_conversation — verifies no-op on clean messages
  • test_prepare_messages_handles_multimodal_tool_result — verifies text extraction from multimodal

All tests pass.


Fixes #23024

Changed files

  • plugins/model-providers/ollama-cloud/__init__.py (modified, +86/-2)
  • tests/providers/test_provider_profiles.py (modified, +96/-0)
RAW_BUFFERClick to expand / collapse

Bug Description

When using Ollama Cloud as the provider, any session that involves tool calls fails with HTTP 400: "Conversation roles must alternate user/assistant/user/assistant..."

Ollama markets Hermes Agent compatibility to its cloud users via email, so this is a user-facing blocker.

Steps to Reproduce

  1. Set OLLAMA_API_KEY and enable ollama-cloud provider
  2. Use /model to switch to an Ollama Cloud model (e.g. gemma3:12b)
  3. Ask anything that triggers a tool call (web search, terminal, etc.)
  4. → HTTP 400 error

Root Cause

Ollama Cloud's API does not support tool role messages in conversation history. It only accepts strict user/assistant alternation. When Hermes makes a tool call, it appends tool role messages which Ollama Cloud then rejects on the next turn.

Expected Behavior

Hermes should detect that ollama-cloud doesn't support tool messages and either:

  • Strip/collapse tool messages before sending (convert to plain text embedded in assistant messages)
  • Disable tool calling entirely when ollama-cloud is the active provider
  • Show a clear error/warning to the user instead of a raw HTTP 400

Environment

  • Provider: ollama-cloud
  • Models tested: gemma3:12b
  • Platform: Telegram gateway

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 - ✅(Solved) Fix Ollama Cloud: HTTP 400 role alternation error when using tools [1 pull requests, 1 comments, 2 participants]