langchain - ✅(Solved) Fix feat(openai): Support reasoning content extraction from OpenAI provider responses [1 pull requests, 1 comments, 2 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#36880Fetched 2026-04-20 11:59:00
View on GitHub
Comments
1
Participants
2
Timeline
9
Reactions
1
Author
Participants
Timeline (top)
labeled ×3closed ×1commented ×1cross-referenced ×1

Error Message

Error Message and Stack Trace (if applicable)

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 (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Other Dependencies

aiohttp: 3.13.3 dataclasses-json: 0.6.7 httpx: 0.28.1 httpx-sse: 0.4.3 jsonpatch: 1.33 langgraph: 1.0.9 mcp: 1.26.0 numpy: 2.4.2 openai: 2.30.0 openrouter: 0.8.0 opentelemetry-api: 1.40.0 opentelemetry-exporter-otlp-proto-http: 1.40.0 opentelemetry-sdk: 1.40.0 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 pydantic-settings: 2.13.1 PyYAML: 6.0.3 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 SQLAlchemy: 2.0.46 sqlalchemy: 2.0.46 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 wrapt: 1.17.3 xxhash: 3.6.0 zstandard: 0.25.0

PR fix notes

PR #36881: feat(openai): add reasoning content extraction to message conversion

Description (problem / solution / changelog)

Fixes #36880

Add support for extracting and preserving reasoning content from OpenAI provider responses in message conversion utilities, enabling display of model reasoning in user interfaces.

Changed files

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

Code Example

from langchain_openai import ChatOpenAI

# Initialize a reasoning-capable model
llm = ChatOpenAI(base_url="URL",model="o1-mini", api_key="KEY")

# Invoke the model
response = llm.invoke("Explain how photosynthesis works in simple terms.")

# Current behavior: reasoning content is dropped during conversion
print("Final answer:", response.content)
print("Additional kwargs:", response.additional_kwargs)
# Output: additional_kwargs does NOT contain the model's reasoning process

---
RAW_BUFFERClick to expand / collapse

Submission checklist

  • 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 (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

from langchain_openai import ChatOpenAI

# Initialize a reasoning-capable model
llm = ChatOpenAI(base_url="URL",model="o1-mini", api_key="KEY")

# Invoke the model
response = llm.invoke("Explain how photosynthesis works in simple terms.")

# Current behavior: reasoning content is dropped during conversion
print("Final answer:", response.content)
print("Additional kwargs:", response.additional_kwargs)
# Output: additional_kwargs does NOT contain the model's reasoning process

Error Message and Stack Trace (if applicable)

Description

The problem

Currently, when models from the OpenAI provider return reasoning content, this content is not retrieved or stored during message conversion. This prevents users from displaying the logical analysis process of the model in their applications.

Current Behavior

The reasoning field from OpenAI API responses is ignored during:

  • _convert_dict_to_message_dict conversion
  • _convert_delta_to_message_chunk conversion

Expected Behavior

Reasoning content should be:

  1. Extracted from responses when present
  2. Stored in message's additional_kwargs under the key reasoning_content
  3. Available for downstream processing and UI display

Proposed Solution

Modify the message conversion utilities in libs/partners/openai/langchain_openai/chat_models/base.py to:

  • Extract the reasoning field from response dictionaries
  • Store it in additional_kwargs['reasoning_content'] when present
  • Handle both complete messages and streaming chunks

Usage example

Users who create chat interfaces or debugging tools want to display the reasoning process of the model separately from the final answer, similar to how the "Reasoning." sections are displayed in the native OpenAI interface.

System Info

System Information

OS: Linux OS Version: #107-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 13 19:51:50 UTC 2026 Python Version: 3.12.3 (main, Mar 3 2026, 12:15:18) [GCC 13.3.0]

Package Information

langchain_core: 1.2.23 langchain: 1.2.10 langchain_community: 0.4.1 langsmith: 0.7.6 langchain_classic: 1.0.1 langchain_mcp_adapters: 0.2.1 langchain_openai: 1.1.12 langchain_openrouter: 0.2.1 langchain_text_splitters: 1.1.1 langgraph_sdk: 0.3.8

Optional packages not installed

deepagents deepagents-cli

Other Dependencies

aiohttp: 3.13.3 dataclasses-json: 0.6.7 httpx: 0.28.1 httpx-sse: 0.4.3 jsonpatch: 1.33 langgraph: 1.0.9 mcp: 1.26.0 numpy: 2.4.2 openai: 2.30.0 openrouter: 0.8.0 opentelemetry-api: 1.40.0 opentelemetry-exporter-otlp-proto-http: 1.40.0 opentelemetry-sdk: 1.40.0 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 pydantic-settings: 2.13.1 PyYAML: 6.0.3 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 SQLAlchemy: 2.0.46 sqlalchemy: 2.0.46 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 wrapt: 1.17.3 xxhash: 3.6.0 zstandard: 0.25.0

extent analysis

TL;DR

Modify the message conversion utilities in libs/partners/openai/langchain_openai/chat_models/base.py to extract and store the reasoning field from OpenAI API responses.

Guidance

  • Identify the _convert_dict_to_message_dict and _convert_delta_to_message_chunk functions in base.py and update them to extract the reasoning field from response dictionaries.
  • Store the extracted reasoning field in additional_kwargs under the key reasoning_content when present.
  • Ensure the updated functions handle both complete messages and streaming chunks correctly.
  • Verify the changes by checking the additional_kwargs of the response object for the presence of reasoning_content.

Example

def _convert_dict_to_message_dict(self, response_dict):
    # ...
    if 'reasoning' in response_dict:
        additional_kwargs['reasoning_content'] = response_dict['reasoning']
    # ...

Notes

The proposed solution requires modifying the langchain_openai package. Users may need to wait for an official update or apply the changes manually.

Recommendation

Apply the proposed workaround by modifying the base.py file to extract and store the reasoning field, as this will allow users to access the model's reasoning process in their applications.

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