AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

AzureChatOpenAI Reasoning Summary Not Extracted From Responses API Reasoning Content

When using the OpenAI Responses API with Azure, the reasoning item may contain reasoning text in the `content` field while `summary` is an empty list. LangChain-OpenAI directly copies these fields into the AIMessage reasoning block, leaving `summary` empty and causing downstream consumers (e.g. LangGraph checkpoint/history views) to miss reasoning summaries even though reasoning usage indicates non-trivial output.

mediumConfidence 85%LangchainChainsAgents

Origin Analysis

The internal function `_construct_lc_result_from_responses_api` in langchain-openai does not provide a fallback when a `ResponseReasoningItem` has an empty `summary` but non-empty `content`. It constructs the reasoning block by directly mapping `item.summary` and `item.content`, so provider-specific shapes where reasoning text resides only in `content` are surfaced unchanged.
1. Use langchain-openai with `output_version="responses/v1"` and Azure provider. 2. Trigger a response that produces a reasoning item with `summary=[]` and `content=[{"type": "reasoning_text", "text": "..."}]`. 3. Inspect the generated AIMessage reasoning block. Expected: `summary` contains `summary_text` entries. Actual: `summary` remains an empty list while `content` contains the raw `reasoning_text` items. The provided minimal Python script replicates this with a synthetic `Response` object.

Fixing Code Block

from langchain_openai.chat_models.base import _construct_lc_result_from_responses_api as _original_construct_lc_result_from_responses_api def _patched_construct_lc_result_from_responses_api(response): result = _original_construct_lc_result_from_responses_api(response) for generation in result.generations: message = generation.message if not message or not isinstance(message.content, list): continue for block in message.content: if not isinstance(block, dict) or block.get("type") != "reasoning": continue if not block.get("summary"): summary = [] for item in block.get("content", []): if isinstance(item, dict) and item.get("type") == "reasoning_text": summary.append({"type": "summary_text", "text": item.get("text")}) if summary: block["summary"] = summary return result _construct_lc_result_from_responses_api = _patched_construct_lc_result_from_responses_api
This monkey patch wraps the original internal function and post-processes the returned `ChatResult`. For every reasoning content block that has an empty `summary`, it looks through the provider-specific `content` list for items of type `reasoning_text` and creates corresponding `summary_text` entries. This directly addresses the Azure shape without altering other blocks or removing the original `content` field, keeping the change minimal and backward-compatible.

Edge Case Audit

The patch relies on internal function names and the assumption that `message.content` is a list of dictionaries, which may change in future LangChain versions. It modifies a global symbol; if other code also patches the same function, conflicts are possible. Because the original `content` is preserved, consumers that display both `summary` and `content` may show duplicate reasoning text. The patch is process-global and not thread-safe if it is dynamically applied or reverted at runtime. Rollback: remove the patch and restart the process.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state