Home / Function/ _explode_reasoning() — langchain Function Reference

_explode_reasoning() — langchain Function Reference

Architecture documentation for the _explode_reasoning() function in openai.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  e8ab70ec_6b5a_2e63_1d72_8f245fdd3a53["_explode_reasoning()"]
  3f58992c_878c_57d1_7412_5e64743aa7ba["openai.py"]
  e8ab70ec_6b5a_2e63_1d72_8f245fdd3a53 -->|defined in| 3f58992c_878c_57d1_7412_5e64743aa7ba
  24124a46_40a1_1ce3_a730_b36c3f9a0520["_convert_to_v1_from_responses()"]
  24124a46_40a1_1ce3_a730_b36c3f9a0520 -->|calls| e8ab70ec_6b5a_2e63_1d72_8f245fdd3a53
  style e8ab70ec_6b5a_2e63_1d72_8f245fdd3a53 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/messages/block_translators/openai.py lines 610–649

def _explode_reasoning(block: dict[str, Any]) -> Iterator[types.ReasoningContentBlock]:
    if "summary" not in block:
        yield cast("types.ReasoningContentBlock", block)
        return

    known_fields = {"type", "reasoning", "id", "index"}
    unknown_fields = [
        field for field in block if field != "summary" and field not in known_fields
    ]
    if unknown_fields:
        block["extras"] = {}
    for field in unknown_fields:
        block["extras"][field] = block.pop(field)

    if not block["summary"]:
        # [{'id': 'rs_...', 'summary': [], 'type': 'reasoning', 'index': 0}]
        block = {k: v for k, v in block.items() if k != "summary"}
        if "index" in block:
            meaningful_idx = f"{block['index']}_0"
            block["index"] = f"lc_rs_{meaningful_idx.encode().hex()}"
        yield cast("types.ReasoningContentBlock", block)
        return

    # Common part for every exploded line, except 'summary'
    common = {k: v for k, v in block.items() if k in known_fields}

    # Optional keys that must appear only in the first exploded item
    first_only = block.pop("extras", None)

    for idx, part in enumerate(block["summary"]):
        new_block = dict(common)
        new_block["reasoning"] = part.get("text", "")
        if idx == 0 and first_only:
            new_block.update(first_only)
        if "index" in new_block:
            summary_index = part.get("index", 0)
            meaningful_idx = f"{new_block['index']}_{summary_index}"
            new_block["index"] = f"lc_rs_{meaningful_idx.encode().hex()}"

        yield cast("types.ReasoningContentBlock", new_block)

Domain

Subdomains

Frequently Asked Questions

What does _explode_reasoning() do?
_explode_reasoning() is a function in the langchain codebase, defined in libs/core/langchain_core/messages/block_translators/openai.py.
Where is _explode_reasoning() defined?
_explode_reasoning() is defined in libs/core/langchain_core/messages/block_translators/openai.py at line 610.
What calls _explode_reasoning()?
_explode_reasoning() is called by 1 function(s): _convert_to_v1_from_responses.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free