Skip to content

fix(llm): support 'reasoning' field from Ollama in streaming responses#843

Open
abdelhadi703 wants to merge 1 commit intoQwenLM:mainfrom
abdelhadi703:fix/ollama-streaming-reasoning
Open

fix(llm): support 'reasoning' field from Ollama in streaming responses#843
abdelhadi703 wants to merge 1 commit intoQwenLM:mainfrom
abdelhadi703:fix/ollama-streaming-reasoning

Conversation

@abdelhadi703
Copy link
Copy Markdown

Summary

Fix streaming responses from Ollama where thinking content is silently lost.

Problem: Ollama sends delta.reasoning for Qwen3 models with thinking content, but the streaming code only checked for delta.reasoning_content (used by vLLM/Qwen API).

Fix: Use getattr() to check both field names — reasoning_content (vLLM/Qwen) and reasoning (Ollama) — in both streaming modes (delta yield and full accumulation).

Changes

  • qwen_agent/llm/oai.py: Updated _chat_stream() to handle both field names

Test

Verified that both reasoning_content (vLLM) and reasoning (Ollama) are now correctly captured.


Contribution by abdelhadisalmaoui0909@outlook.fr

Ollama sends 'delta.reasoning' for Qwen3 models with thinking
content, but the streaming code only checked for
'delta.reasoning_content' (used by vLLM/Qwen). This caused
thinking content to be silently dropped during streaming.

Use getattr() to check both field names, supporting both
'reasoning_content' (vLLM/Qwen) and 'reasoning' (Ollama) in
both delta_stream and full accumulation modes.

Fixes QwenLM#789
@abdelhadi703 abdelhadi703 force-pushed the fix/ollama-streaming-reasoning branch from 077986e to d8218b7 Compare March 25, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant