[BUG] OllamaModel: a reasoningContent block in history raises TypeError, and streamed thinking is dropped
Human Overview
So I was running ollama and I noticed some issues or things that I could fix so the ollama model currently doesnt know how to handle reasoning from other providers and it doesnt keep reasoning generated by its models when i checked thoroughly i found two bugs one caused crashes and the other caused information loss
Checks
- [x] I have updated to the lastest minor and patch version of Strands
- [x] I have checked the documentation and this is not expected behavior
- [x] I have searched ./issues and there are no duplicates of my issue
SDK Language
Python
Strands Version
main @ 7eb9671 (1.63.1.dev27)
Language Runtime Version
Python 3.12
Operating System
Windows 11
Installation Method
git clone
Steps to Reproduce
- Give an Ollama agent a history that holds a
reasoningContentblock, as one written by a reasoning model before the agent moved to Ollama would. It fails before any request is sent, so Ollama doesn't need to be running:
from strands import Agent
from strands.models.ollama import OllamaModel
history = [
{"role": "user", "content": [{"text": "Is 91 prime?"}]},
{"role": "assistant", "content": [
{"reasoningContent": {"reasoningText": {"text": "91 = 7 x 13", "signature": "sig"}}},
{"text": "No, 91 = 7 x 13."},
]},
]
agent = Agent(model=OllamaModel(host="http://localhost:11434", model_id="qwen3:8b"), messages=history)
agent("And 97?")
- With Ollama 0.40.5 and
qwen3:8b, runAgent(model=OllamaModel(host="http://localhost:11434", model_id="qwen3:8b"))("Is 91 a prime number? Answer yes or no.")and look atresult.message["content"].
Expected Behavior
Reasoning blocks in the history are skipped with the once-per-request skip log, as OpenAIModel does, and a thinking model's streamed message.thinking arrives as reasoningContent, as it does with OpenAIModel and LiteLLMModel.
Actual Behavior
TypeError: content_type=<reasoningContent> | unsupported type, raised by_format_request_message_contents(ollama.py:167).- The thinking is dropped. The same question on the raw
ollamaclient streamed 394 chunks withmessage.thinking(1,162 characters) before an 81-character answer. Through Strands,result.message["content"]holds only atextblock, whileoutputTokens(427) still counts the thinking tokens.
Possible Solution
#1051 (October 2025) already does both: it skips reasoningContent blocks in requests and streams message.thinking as reasoningContent. It hasn't been reviewed and now conflicts after the move to strands-py/. The two parts go together: capturing thinking without the request-side skip would make a thinking model's own next turn raise the TypeError.
@scippacercola, are you still working on #1051? If not, I'm happy to bring it up to date, keeping your commits and logging skipped blocks through the skipped counter (#5319) as openai.py does.
Additional Context
Context
ollama.pyis the only provider instrands-py/src/strands/models/with noreasoningContenthandling.- TypeScript has no Ollama provider, so this is Python only.
- Open PR #5768 also changes
OllamaModel.stream, for #5742. - Found while running the
tests_integ/models/test_model_ollama.pyagent case onqwen3:8binstead ofllama3.3:70b. That case passes.
Related Issues
#1051 (open PR with the fix), #4779 (reasoning capture and replay across providers; the native OllamaModel isn't in its child-issue table)
Are you planning to send a PR for this? If not, I'd be glad to take the TypeError part (skipping reasoningContent in the history, as OpenAIModel does). The streaming part looks like it overlaps #1051.
Sorry for the slow reply. Yes, I'm planning a PR. Since #1051 hasn't had a reply, I'll bring it up to date with main and keep @scippacercola's commits, which covers both the TypeError and the dropped thinking stream. If you've already started on the TypeError part, I'm happy to split it: you take the history fix and I'll do streaming.