langchain - ✅(Solved) Fix 🐞 [langchain-openai] Bug: reasoning_content not extracted from DeepSeek streaming responses [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#35516Fetched 2026-04-08 00:25:53
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
closed ×1cross-referenced ×1labeled ×1referenced ×1

LangChain's ChatOpenAI doesn't extract reasoning_content from DeepSeek's streaming responses. The reasoning_content field is used by DeepSeek models (like deepseek-reasoner) to stream their thinking process.

Root Cause

LangChain's ChatOpenAI doesn't extract reasoning_content from DeepSeek's streaming responses. The reasoning_content field is used by DeepSeek models (like deepseek-reasoner) to stream their thinking process.

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain.
  • This is related to langchain-openai package.
  • I posted a self-contained, minimal, reproducible example.

PR fix notes

PR #35520: fix(openai): extract reasoning_content from DeepSeek streaming responses

Description (problem / solution / changelog)

Summary

Extract reasoning_content from delta in _convert_delta_to_message_chunk to make DeepSeek's thinking process available in additional_kwargs.

Changes

  • Added extraction of reasoning_content from delta in libs/partners/openai/langchain_openai/chat_models/base.py

Testing

Verified the fix works with DeepSeek deepseek-reasoner model.

Related Issue

Fixes #35516

Changed files

  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +3/-0)

Code Example

import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "deepseek-reasoner",
  apiKey: process.env.DEEPSEEK_API_KEY,
  baseURL: "https://api.deepseek.com"
});

const stream = await llm.stream("What is 2+2?");

for await (const chunk of stream) {
  // chunk.additional_kwargs.reasoning_content is always undefined
  console.log("reasoning:", chunk.additional_kwargs?.reasoning_content);
}

---

// Extract reasoning_content (DeepSeek specific)
if (delta.reasoning_content) {
  additional_kwargs.reasoning_content = delta.reasoning_content;
}
RAW_BUFFERClick to expand / collapse

Checkboxes

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain.
  • This is related to langchain-openai package.
  • I posted a self-contained, minimal, reproducible example.

Package

  • langchain-openai

Related Issues

  • #35006
  • #34938

Reproduction Steps

import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "deepseek-reasoner",
  apiKey: process.env.DEEPSEEK_API_KEY,
  baseURL: "https://api.deepseek.com"
});

const stream = await llm.stream("What is 2+2?");

for await (const chunk of stream) {
  // chunk.additional_kwargs.reasoning_content is always undefined
  console.log("reasoning:", chunk.additional_kwargs?.reasoning_content);
}

Expected: reasoning_content should contain the model's thinking process. Actual: reasoning_content is always undefined.

Description

LangChain's ChatOpenAI doesn't extract reasoning_content from DeepSeek's streaming responses. The reasoning_content field is used by DeepSeek models (like deepseek-reasoner) to stream their thinking process.

Suggested Fix

In libs/langchain-openai/src/chat_models/completions.ts, function convertCompletionsDeltaToBaseMessageChunk, add:

// Extract reasoning_content (DeepSeek specific)
if (delta.reasoning_content) {
  additional_kwargs.reasoning_content = delta.reasoning_content;
}

System Info

  • langchain-openai: ^0.1.0
  • Node.js: 18+
  • DeepSeek API

PR

Fix submitted: #35520

extent analysis

Fix Plan

Step 1: Update convertCompletionsDeltaToBaseMessageChunk function

In the file libs/langchain-openai/src/chat_models/completions.ts, add the following code snippet:

// Extract reasoning_content (DeepSeek specific)
if (delta.reasoning_content) {
  additional_kwargs.reasoning_content = delta.reasoning_content;
}

This code should be added to the convertCompletionsDeltaToBaseMessageChunk function.

Step 2: Update langchain-openai package

Update the langchain-openai package to the latest version. This can be done by running the following command:

npm install langchain-openai@latest

or

yarn add langchain-openai@latest

Step 3: Verify the fix

Run the reproduction steps again and verify that the reasoning_content field is no longer undefined.

import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "deepseek-reasoner",
  apiKey: process.env.DEEPSEEK_API_KEY,
  baseURL: "https://api.deepseek.com"
});

const stream = await llm.stream("What is 2+2?");

for await (const chunk of stream) {
  console.log("reasoning:", chunk.additional_kwargs?.reasoning_content);
}

If the reasoning_content field is now populated, the fix is successful.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING