Skip to content

Fix: Surface Ollama reasoning ("thinking") content in ChatMessageContent#13887

Closed
PrathamAditya wants to merge 12 commits intomicrosoft:mainfrom
PrathamAditya:Bug_13860
Closed

Fix: Surface Ollama reasoning ("thinking") content in ChatMessageContent#13887
PrathamAditya wants to merge 12 commits intomicrosoft:mainfrom
PrathamAditya:Bug_13860

Conversation

@PrathamAditya
Copy link
Copy Markdown
Contributor

Summary

Ollama responses can include a thinking (reasoning) field, but this information is currently not exposed through ChatMessageContent in Semantic Kernel.

This PR adds support to surface reasoning content by extracting it from the underlying RawRepresentation.

Changes

  • Added a unit test demonstrating that reasoning (thinking) content is currently not propagated.
  • Implemented a minimal fix to extract thinking from RawRepresentation and include it in ChatMessageContent.Items as TextContent.

Behavior

Before:

  • Only final response (content) is available.

After:

  • Reasoning (thinking) is included alongside final response.

Design Notes

  • The fix uses RawRepresentation to avoid introducing a dependency on Ollama-specific types in SemanticKernel.Abstractions.
  • This is intentionally a minimal and non-breaking change.

Limitations / Future Work

This highlights a broader gap in the current abstraction:

  • The Microsoft.Extensions.AI model does not currently support reasoning/thinking as a first-class concept.
  • Modern LLMs (Ollama, OpenAI reasoning models, etc.) are increasingly returning structured reasoning.

Potential improvements:

  • Introduce a dedicated ReasoningContent type
  • Or expose reasoning via standardized metadata

Happy to align with maintainers on preferred direction.

Testing

  • Added unit test:
    GetChatMessageContent_ShouldIncludeThinking_WhenPresentInResponseAsync
  • Test fails without fix and passes with fix.

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.

3 participants