Skip to content

FEAT: keep reasoning text from Chat Completions responses - #4267

Open
CHERIF ANES ABD EL MALEK (anascherif) wants to merge 3 commits into
microsoft:mainfrom
anascherif:feat/chat-completions-reasoning-content
Open

CHERIF ANES ABD EL MALEK (anascherif) wants to merge 3 commits into
microsoft:mainfrom
anascherif:feat/chat-completions-reasoning-content

Conversation

@anascherif

Copy link
Copy Markdown

Description

Keeps the reasoning text that reasoning models return over Chat Completions, which OpenAIChatTarget and LiteLLMChatTarget dropped until now. Closes #4266.

  • extract_reasoning_content reads the message field providers use for it: reasoning_content (DeepSeek, LiteLLM, xAI, Qwen, older vLLM) or reasoning (OpenRouter, Ollama, newer vLLM). Only non-empty strings count.
  • capture_reasoning_content stores it in the first response piece's prompt_metadata["reasoning_content"]. It is called from capture_usage_and_finish_reason, so both targets record it on the success, token-limit truncation and content-filter paths without target-specific code.
  • Like finish_reason, the key is cleared from every piece first, so a value inherited from request metadata can't survive on a response that has no reasoning.
  • The text lives in metadata (as partial_content does), so it is never sent back to the model as history and no history builder or capability changes.

Before / after for a DeepSeek-style response cut off at the token limit while still reasoning (content=None, finish_reason="length", reasoning_content="Let me think about this step by step"):

stored response piece
before empty piece, finish_reason: length and token counts; reasoning text lost
after same, plus prompt_metadata["reasoning_content"] = "Let me think about this step by step"

The alternative of storing a reasoning piece like OpenAIResponseTarget is discussed in the issue; I'm happy to switch if you prefer it.

Reasoning models served over Chat Completions return their chain of
thought in a message field next to the answer: reasoning_content
(DeepSeek, LiteLLM, xAI, Qwen) or reasoning (OpenRouter, Ollama, vLLM).
The shared parser read neither, so OpenAIChatTarget and
LiteLLMChatTarget dropped it.

Store it in the response's prompt_metadata["reasoning_content"],
captured with token usage and finish_reason so the success, truncation
and content-filter paths record it alike. The key is cleared first so a
value inherited from request metadata cannot survive. The text is kept
for review and scoring and is never replayed as history.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 15:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review completed. No blocking concerns remain. This review records source coverage; merging is handled separately.

This branch has not been deployed

No deployments
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.

FEAT: keep reasoning text (reasoning_content) from Chat Completions targets

3 participants