_implode_reasoning_blocks() — langchain Function Reference
Architecture documentation for the _implode_reasoning_blocks() function in _compat.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD f305586f_ba7b_c515_2b74_74a615fa9242["_implode_reasoning_blocks()"] 92333051_7f77_b57b_d874_abb7bac2bbe0["_compat.py"] f305586f_ba7b_c515_2b74_74a615fa9242 -->|defined in| 92333051_7f77_b57b_d874_abb7bac2bbe0 debfdf1e_2d5b_2867_c955_09be2be39501["_convert_from_v1_to_responses()"] debfdf1e_2d5b_2867_c955_09be2be39501 -->|calls| f305586f_ba7b_c515_2b74_74a615fa9242 style f305586f_ba7b_c515_2b74_74a615fa9242 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/openai/langchain_openai/chat_models/_compat.py lines 211–259
def _implode_reasoning_blocks(blocks: list[dict[str, Any]]) -> Iterable[dict[str, Any]]:
i = 0
n = len(blocks)
while i < n:
block = blocks[i]
# Skip non-reasoning blocks or blocks already in Responses format
if block.get("type") != "reasoning" or "summary" in block:
yield dict(block)
i += 1
continue
elif "reasoning" not in block and "summary" not in block:
# {"type": "reasoning", "id": "rs_..."}
oai_format = {**block, "summary": []}
if "extras" in oai_format:
oai_format.update(oai_format.pop("extras"))
oai_format["type"] = oai_format.pop("type", "reasoning")
if "encrypted_content" in oai_format:
oai_format["encrypted_content"] = oai_format.pop("encrypted_content")
yield oai_format
i += 1
continue
else:
pass
summary: list[dict[str, str]] = [
{"type": "summary_text", "text": block.get("reasoning", "")}
]
# 'common' is every field except the exploded 'reasoning'
common = {k: v for k, v in block.items() if k != "reasoning"}
if "extras" in common:
common.update(common.pop("extras"))
i += 1
while i < n:
next_ = blocks[i]
if next_.get("type") == "reasoning" and "reasoning" in next_:
summary.append(
{"type": "summary_text", "text": next_.get("reasoning", "")}
)
i += 1
else:
break
merged = dict(common)
merged["summary"] = summary
merged["type"] = merged.pop("type", "reasoning")
yield merged
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _implode_reasoning_blocks() do?
_implode_reasoning_blocks() is a function in the langchain codebase, defined in libs/partners/openai/langchain_openai/chat_models/_compat.py.
Where is _implode_reasoning_blocks() defined?
_implode_reasoning_blocks() is defined in libs/partners/openai/langchain_openai/chat_models/_compat.py at line 211.
What calls _implode_reasoning_blocks()?
_implode_reasoning_blocks() is called by 1 function(s): _convert_from_v1_to_responses.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free