Skip to content

[Bug]: Ollama responses have empty content array after multiple tool results (tokens generated but not captured) #9900

@whimmel

Description

@whimmel

Summary

When using Ollama via OpenAI-compatible API (api: "openai-completions"), responses after multiple tool call/result cycles return with content: [] (empty array) despite generating output tokens. The model IS responding (token count shows 53 output tokens), but the content is not being captured.

Steps to Reproduce

  1. Configure Ollama provider with explicit model:"ollama": {
    "baseUrl": "http://ollama-host:11434/v1",
    "apiKey": "ollama-local",
    "api": "openai-completions",
    "models": [{
    "id": "qwen2.5:7b-instruct",
    "contextWindow": 32768,
    "maxTokens": 8192
    }]
    }
  2. Spawn a subagent task that requires tool use
  3. Have the tool return an error
  4. Model makes another tool call (retry)
  5. Tool returns error again
  6. Model's final response has content: [] but output: 53 tokens
    Expected Behavior

The 53 generated tokens should appear in the content array as a text block.

Actual Behavior
{
"role": "assistant",
"content": [],
"usage": {
"input": 3343,
"output": 53
},
"stopReason": "stop"
}
Verification

Raw Ollama API works correctly — tested the exact same conversation via curl with streaming enabled, and content is returned properly. The bug is in the response parsing layer.

This works fine:

curl http://ollama-host:11434/v1/chat/completions
-d '{"model":"qwen2.5:7b-instruct","messages":[...same history...],"tools":[...],"stream":true}'

Returns proper content deltas

Environment

• OpenClaw version: 2026.1.24-3
• Provider: Ollama (qwen2.5:7b-instruct)
• API mode: openai-completions
• OS: Ubuntu 24.04 (arm64)
Suspected Location
@mariozechner/pi-ai/dist/providers/openai-completions.js — streaming content deltas may not be captured correctly after tool result messages in certain scenarios.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingstaleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions