docs/troubleshooting/ollama.md
When using Ollama as a provider with oh-my-openagent agents, you may encounter:
JSON Parse error: Unexpected EOF
This occurs when agents attempt tool calls (e.g., explore agent using mcp_grep_search).
Ollama returns NDJSON (newline-delimited JSON) when stream: true is used in API requests:
{"message":{"tool_calls":[{"function":{"name":"read","arguments":{"filePath":"README.md"}}}]}, "done":false}
{"message":{"content":""}, "done":true}
Claude Code SDK expects a single JSON object, not multiple NDJSON lines, causing the parse error.
Why this happens:
Configure your Ollama provider to use stream: false:
{
"provider": "ollama",
"model": "qwen3-coder",
"stream": false
}
Pros:
Cons:
If you need streaming, avoid agents that use tools:
The proper fix requires Claude Code SDK to:
tool_calls from multiple linesTracking: https://github.com/code-yeongyu/oh-my-openagent/issues/1124 (closed - documented workaround)
Until the SDK is fixed, here's how to implement NDJSON parsing (for SDK maintainers):
async function parseOllamaStreamResponse(response: string): Promise<object> {
const lines = response.split('\n').filter(line => line.trim());
const mergedMessage = { tool_calls: [] };
for (const line of lines) {
try {
const json = JSON.parse(line);
if (json.message?.tool_calls) {
mergedMessage.tool_calls.push(...json.message.tool_calls);
}
if (json.message?.content) {
mergedMessage.content = json.message.content;
}
} catch (e) {
// Skip malformed lines
console.warn('Skipping malformed NDJSON line:', line);
}
}
return mergedMessage;
}
To verify the fix works:
# Test with curl (should work with stream: false)
curl -s http://localhost:11434/api/chat \
-d '{
"model": "qwen3-coder",
"messages": [{"role": "user", "content": "Read file README.md"}],
"stream": false,
"tools": [{"type": "function", "function": {"name": "read", "description": "Read a file", "parameters": {"type": "object", "properties": {"filePath": {"type": "string"}}, "required": ["filePath"]}}}]
}'
If you encounter this issue:
stream: false as a workaround