fix(transports): promote Ollama reasoning field to content when content is empty - #46489
Open
liuhao1024 wants to merge 1 commit into
Open
fix(transports): promote Ollama reasoning field to content when content is empty#46489liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
…nt is empty Ollama reasoning models (deepseek-r1, qwen3.5, etc.) return content="" with the actual output in a separate ``reasoning`` field. The transport only read ``content``, so the agent loop treated every response as empty and retried 3 times before giving up. Two changes: 1. Add model_extra fallback for ``reasoning`` (symmetric with existing ``reasoning_content`` fallback for DeepSeek/Moonshot). 2. When content is empty/blank but reasoning has text, promote reasoning to content so the agent loop receives a usable response.
tonydwb
approved these changes
Jun 15, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Fix promotes Ollama reasoning field to content when content is empty. Clean fix for an edge case. No security concerns.
Reviewed by Hermes Agent
teknium1
reviewed
Jul 14, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for tracing the non-streaming reasoning shape and adding focused coverage.
Problems
agent/transports/chat_completions.py:707promotes any blank-contentchat_completionsresponse withreasoninginto visible content. Current main instead treats structured reasoning with no visible content as a thinking-only turn and continues generation (agent/conversation_loop.py:5011-5040). The shared message builder intentionally keeps reasoning separate because putting it in content leaks it to delivery, transcript, replay, compression, and titles (agent/chat_completion_helpers.py:1082-1092).
Suggested changes
- Retain the
model_extra["reasoning"]extraction, but preserve it as reasoning so the existing continuation path can handle it. If Ollama has a distinct contract where the field is final answer text, make that behavior provider-scoped and cover it with an end-to-end test.
Automated hermes-sweeper review.
| # Ollama reasoning models return content="" with the actual output in | ||
| # the ``reasoning`` field. Promote reasoning to content so the agent | ||
| # loop does not treat it as an empty response and retry 3 times. | ||
| if not (isinstance(content, str) and content.strip()) and isinstance(reasoning, str) and reasoning.strip(): |
Contributor
There was a problem hiding this comment.
This executes for every OpenAI-compatible chat-completions provider, not just Ollama. Promoting reasoning here bypasses main's thinking-only continuation (agent/conversation_loop.py:5011) and makes hidden reasoning final visible content; please keep this as structured reasoning unless an explicitly scoped Ollama contract proves it is answer text.
This was referenced Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Promotes Ollama's
reasoningfield tocontentwhen the model returns an emptycontentstring. This fixes Ollama reasoning models (deepseek-r1, qwen3.5, etc.) returning blank responses — the agent loop previously retried 3 times and gave up because it only readcontent, while Ollama puts the actual output in a separatereasoningfield.Related Issue
Fixes #46131
Type of Change
Changes Made
agent/transports/chat_completions.py: Addedmodel_extrafallback for thereasoningfield (symmetric with existingreasoning_contentfallback for DeepSeek/Moonshot). Added reasoning-to-content promotion when content is empty/blank but reasoning has text.tests/agent/transports/test_chat_completions.py: Added 3 tests — Ollama reasoning promotion, model_extra fallback, and non-override guard.How to Test
pytest tests/agent/transports/test_chat_completions.py -xvs -k "ollama_reasoning or non_empty_content_not_overridden"— all 3 new tests should passpytest tests/agent/transports/test_chat_completions.py -x— all 84 tests should pass (zero regression)deepseek-r1), send a chat message via Hermes — the response should now display correctly instead of appearing blankChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
agent/transports/chat_completions.py::normalize_response(callers: 2, flows: 3)agent/transports/types.py::NormalizedResponse.reasoning(callers: 2)refusal→contentpromotion (lines 684-699),reasoning_content→provider_datapreservation (lines 654-662)