Skip to content

feat: add reasoning_content support for thinking models#119

Open
cloorc wants to merge 2 commits into
lazy-hq:mainfrom
LeafAI:main
Open

feat: add reasoning_content support for thinking models#119
cloorc wants to merge 2 commits into
lazy-hq:mainfrom
LeafAI:main

Conversation

@cloorc

@cloorc cloorc commented Jun 5, 2026

Copy link
Copy Markdown
  • Add reasoning_content field to ChatMessage for DeepSeek R1 / OpenAI o1
  • Capture reasoning_content from API response in both streaming and non-streaming
  • Add LanguageModelOptions::reasoning_content() method
  • Merge consecutive Reasoning+Text assistant messages to avoid empty-content API errors when echoing reasoning_content back to the API

Description

A clear and concise description of the changes.

Related Issue

Closes #[issue_number]

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • I have read the Contributing Guidelines.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • Any dependent changes have been merged and published in downstream modules.

@cloorc cloorc marked this pull request as draft June 5, 2026 00:17
- Add reasoning_content field to ChatMessage
- Emit Reasoning as separate Message::Assistant at SDK level
- Merge Reasoning into subsequent Text/ToolCall ChatMessage in conversions
- Echo reasoning_content in requests to satisfy thinking models (DeepSeek R1)
- Do NOT merge consecutive ToolCall messages — preserve original LLM turn grouping

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Cloorc <wittcnezh@foxmail.com>
@cloorc cloorc marked this pull request as ready for review June 5, 2026 03:57
Providers that support `stream_options.include_usage` (OpenAI, agnes) emit
token usage in a trailing chunk whose choices carry no `finish_reason`. The
stream consumer stops once a text-completion `Done` is emitted, so that
trailing chunk was never read and its usage silently dropped (0/0 tokens).

Defer the text-completion `Done` until usage arrives in a trailing chunk,
the stream signals `[DONE]`, or the connection closes. Flush without usage
on stream end so the assistant message is still recorded when no usage
chunk is sent.

Signed-off-by: Cloorc <wittcnezh@foxmail.com>
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