openclaw - ๐Ÿ’ก(How to fix) Fix Ollama Cloud provider fails in agent/Gateway path with non-alternating conversation roles [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
openclaw/openclaw#71697โ€ขFetched 2026-04-26 05:09:40
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Ollama Cloud works directly with the configured OLLAMA_API_KEY, but using the same ollama provider as an OpenClaw agent/Gateway model fails because the request sent through OpenClaw's agent path is rejected by Ollama Cloud with a non-alternating conversation roles error.

This is related to, but distinct from, #66505. The direct cloud provider path exists and can reach Ollama Cloud; the remaining problem appears to be the agent/Gateway conversation replay/adapter path.

Error Message

Ollama Cloud works directly with the configured OLLAMA_API_KEY, but using the same ollama provider as an OpenClaw agent/Gateway model fails because the request sent through OpenClaw's agent path is rejected by Ollama Cloud with a non-alternating conversation roles error. errorPreview: 400 {"error":"Conversation roles must alternate user/assistant/user/assistant/... (ref: db7e8576-df9a-4d97-9654-514c298f2a43)"}

Root Cause

#66505 was closed as implemented because cloud-only Ollama is now supported. That part works. However, in practice the provider is not usable as an OpenClaw agent model in this setup because the integrated Gateway/agent path sends a conversation format that Ollama Cloud rejects.

This makes the direct Ollama Cloud provider look configured and available, while actual agent turns may be handled by fallback models instead.

Code Example

{
  "models": {
    "mode": "merge",
    "providers": {
      "ollama": {
        "baseUrl": "https://ollama.com",
        "api": "ollama",
        "apiKey": "OLLAMA_API_KEY",
        "models": [
          {
            "id": "gemma3:4b",
            "name": "gemma3:4b",
            "input": ["text"],
            "contextWindow": 128000,
            "maxTokens": 32000
          }
        ]
      }
    }
  },
  "plugins": {
    "entries": {
      "ollama": { "enabled": true }
    }
  }
}

---

curl -sS --max-time 90 \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer ${OLLAMA_API_KEY}" \
  https://ollama.com/api/chat \
  -d '{
    "model": "gemma3:4b",
    "messages": [
      { "role": "user", "content": "Responde exactamente: OK_CURL_OLLAMA" }
    ],
    "stream": false
  }'

---

HTTP_STATUS: 200
model: gemma3:4b
done: true
done_reason: stop
content: OK_CURL_OLLAMA

---

model_fallback_decision
requestedProvider: ollama
requestedModel: gemma3:4b
candidateProvider: ollama
candidateModel: gemma3:4b
reason: format
status: 400
errorPreview: 400 {"error":"Conversation roles must alternate user/assistant/user/assistant/... (ref: db7e8576-df9a-4d97-9654-514c298f2a43)"}
nextCandidateProvider: xiaomi
nextCandidateModel: mimo-v2-pro

---

Conversation roles must alternate user/assistant/user/assistant/...
RAW_BUFFERClick to expand / collapse

Summary

Ollama Cloud works directly with the configured OLLAMA_API_KEY, but using the same ollama provider as an OpenClaw agent/Gateway model fails because the request sent through OpenClaw's agent path is rejected by Ollama Cloud with a non-alternating conversation roles error.

This is related to, but distinct from, #66505. The direct cloud provider path exists and can reach Ollama Cloud; the remaining problem appears to be the agent/Gateway conversation replay/adapter path.

Environment

  • OpenClaw: 2026.4.23 (a979721)
  • Platform: Linux arm64
  • Provider config: models.providers.ollama
  • Ollama mode: cloud-only
  • Base URL: https://ollama.com
  • API adapter: api: "ollama"
  • Credential source: OLLAMA_API_KEY env var
  • Test model: ollama/gemma3:4b

Configured provider shape, with secrets omitted:

{
  "models": {
    "mode": "merge",
    "providers": {
      "ollama": {
        "baseUrl": "https://ollama.com",
        "api": "ollama",
        "apiKey": "OLLAMA_API_KEY",
        "models": [
          {
            "id": "gemma3:4b",
            "name": "gemma3:4b",
            "input": ["text"],
            "contextWindow": 128000,
            "maxTokens": 32000
          }
        ]
      }
    }
  },
  "plugins": {
    "entries": {
      "ollama": { "enabled": true }
    }
  }
}

Direct Ollama Cloud API test succeeds

Using the same OLLAMA_API_KEY, this direct call succeeds:

curl -sS --max-time 90 \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer ${OLLAMA_API_KEY}" \
  https://ollama.com/api/chat \
  -d '{
    "model": "gemma3:4b",
    "messages": [
      { "role": "user", "content": "Responde exactamente: OK_CURL_OLLAMA" }
    ],
    "stream": false
  }'

Observed result:

HTTP_STATUS: 200
model: gemma3:4b
done: true
done_reason: stop
content: OK_CURL_OLLAMA

So the API key, model, endpoint, and Ollama Cloud availability are all valid.

OpenClaw agent/Gateway path fails

After selecting/using ollama/gemma3:4b through the OpenClaw agent/Gateway path, OpenClaw reaches the Ollama provider but the candidate fails and falls back to another provider.

Relevant gateway log excerpt:

model_fallback_decision
requestedProvider: ollama
requestedModel: gemma3:4b
candidateProvider: ollama
candidateModel: gemma3:4b
reason: format
status: 400
errorPreview: 400 {"error":"Conversation roles must alternate user/assistant/user/assistant/... (ref: db7e8576-df9a-4d97-9654-514c298f2a43)"}
nextCandidateProvider: xiaomi
nextCandidateModel: mimo-v2-pro

Then the fallback model succeeds, which can make the user-facing response look successful even though Ollama was not the model that answered.

Expected behavior

When ollama/gemma3:4b is selected as the model, OpenClaw should normalize or replay the Gateway/agent message history into a sequence accepted by Ollama's native /api/chat API, or otherwise strip/merge unsupported/non-alternating roles before sending the request.

Actual behavior

The request sent through OpenClaw's agent/Gateway path is rejected by Ollama Cloud with:

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

OpenClaw then silently falls back to another configured model.

Why this matters

#66505 was closed as implemented because cloud-only Ollama is now supported. That part works. However, in practice the provider is not usable as an OpenClaw agent model in this setup because the integrated Gateway/agent path sends a conversation format that Ollama Cloud rejects.

This makes the direct Ollama Cloud provider look configured and available, while actual agent turns may be handled by fallback models instead.

extent analysis

TL;DR

The most likely fix is to modify the OpenClaw agent/Gateway path to normalize or replay the message history into a sequence accepted by Ollama's native /api/chat API, ensuring conversation roles alternate between user and assistant.

Guidance

  • Verify that the OLLAMA_API_KEY is correctly configured and passed to the OpenClaw agent/Gateway path.
  • Check the OpenClaw agent/Gateway path implementation to ensure it properly handles conversation role alternation, potentially by stripping or merging unsupported roles.
  • Review the Ollama Cloud API documentation to confirm the expected format for conversation roles and messages.
  • Consider adding logging or debugging statements to the OpenClaw agent/Gateway path to inspect the request being sent to Ollama Cloud and identify any formatting issues.

Example

No code example is provided due to the complexity of the issue and the need for specific implementation details.

Notes

The solution may require modifications to the OpenClaw agent/Gateway path implementation, which could involve significant development and testing efforts. Additionally, the exact changes required will depend on the specific implementation details of the OpenClaw agent/Gateway path and the Ollama Cloud API.

Recommendation

Apply a workaround to modify the OpenClaw agent/Gateway path to handle conversation role alternation, as the root cause appears to be related to the formatting of the request sent to Ollama Cloud.

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โ€ฆ

FAQ

Expected behavior

When ollama/gemma3:4b is selected as the model, OpenClaw should normalize or replay the Gateway/agent message history into a sequence accepted by Ollama's native /api/chat API, or otherwise strip/merge unsupported/non-alternating roles before sending the request.

Still need to ship something?

ร—6

Another batch ranked right after the header list โ€” different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ๐Ÿ’ก(How to fix) Fix Ollama Cloud provider fails in agent/Gateway path with non-alternating conversation roles [1 participants]