Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
3.4 KiB
3.4 KiB
Ollama Troubleshooting
Streaming Issue: JSON Parse Error
Problem
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).
Root Cause
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:
- Ollama API: Returns streaming responses as NDJSON by design
- Claude Code SDK: Doesn't properly handle NDJSON responses for tool calls
- oh-my-openagent: Passes through the SDK's behavior (can't fix at this layer)
Solutions
Option 1: Disable Streaming (Recommended)
Configure your Ollama provider to use stream: false:
{
"provider": "ollama",
"model": "qwen3-coder",
"stream": false
}
Pros:
- Works immediately
- No code changes needed
- Simple configuration
Cons:
- Slightly slower response time (no streaming)
- Less interactive feedback
Option 2: Use Non-Tool Agents Only
If you need streaming, avoid agents that use tools:
- Safe: Simple text generation, non-tool tasks
- Problematic: Any agent with tool calls (explore, librarian, etc.)
Option 3: Wait for SDK Fix
The proper fix requires Claude Code SDK to:
- Detect NDJSON responses
- Parse each line separately
- Merge
tool_callsfrom multiple lines - Return a single merged response
Tracking: https://github.com/code-yeongyu/oh-my-openagent/issues/1124
Workaround Implementation
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;
}
Testing
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"]}}}]
}'
Related Issues
- oh-my-openagent: https://github.com/code-yeongyu/oh-my-openagent/issues/1124
- Ollama API Docs: https://github.com/ollama/ollama/blob/main/docs/api.md
Getting Help
If you encounter this issue:
- Check your Ollama provider configuration
- Set
stream: falseas a workaround - Report any additional errors to the issue tracker
- Provide your configuration (without secrets) for debugging