Home / File/ _compat.py — langchain Source File

_compat.py — langchain Source File

Architecture documentation for _compat.py, a python file in the langchain codebase. 4 imports, 0 dependents.

File python LangChainCore LanguageModelBase 4 imports 6 functions

Entity Profile

Dependency Diagram

graph LR
  92333051_7f77_b57b_d874_abb7bac2bbe0["_compat.py"]
  9d14ea65_8b2e_6721_a947_acc89905651f["json"]
  92333051_7f77_b57b_d874_abb7bac2bbe0 --> 9d14ea65_8b2e_6721_a947_acc89905651f
  2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"]
  92333051_7f77_b57b_d874_abb7bac2bbe0 --> 2bf6d401_816d_d011_3b05_a6114f55ff58
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  92333051_7f77_b57b_d874_abb7bac2bbe0 --> feec1ec4_6917_867b_d228_b134d0ff8099
  9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"]
  92333051_7f77_b57b_d874_abb7bac2bbe0 --> 9444498b_8066_55c7_b3a2_1d90c4162a32
  style 92333051_7f77_b57b_d874_abb7bac2bbe0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Converts between AIMessage output formats, governed by `output_version`.

`output_version` is an attribute on ChatOpenAI.

Supported values are `None`, `'v0'`, and `'responses/v1'`.

`'v0'` corresponds to the format as of `ChatOpenAI` v0.3. For the Responses API, it
stores reasoning and tool outputs in `AIMessage.additional_kwargs`:

```python
AIMessage(
    content=[
        {"type": "text", "text": "Hello, world!", "annotations": [{"type": "foo"}]}
    ],
    additional_kwargs={
        "reasoning": {
            "type": "reasoning",
            "id": "rs_123",
            "summary": [{"type": "summary_text", "text": "Reasoning summary"}],
        },
        "tool_outputs": [
            {
                "type": "web_search_call",
                "id": "websearch_123",
                "status": "completed",
            }
        ],
        "refusal": "I cannot assist with that.",
    },
    response_metadata={"id": "resp_123"},
    id="msg_123",
)
```

`'responses/v1'` is only applicable to the Responses API. It retains information
about response item sequencing and accommodates multiple reasoning items by
representing these items in the content sequence:

```python
AIMessage(
    content=[
        {
            "type": "reasoning",
            "summary": [{"type": "summary_text", "text": "Reasoning summary"}],
            "id": "rs_123",
        },
        {
            "type": "text",
            "text": "Hello, world!",
            "annotations": [{"type": "foo"}],
            "id": "msg_123",
        },
        {"type": "refusal", "refusal": "I cannot assist with that."},
        {"type": "web_search_call", "id": "websearch_123", "status": "completed"},
    ],
    response_metadata={"id": "resp_123"},
    id="resp_123",
)
```

// ... (395 more lines)

Domain

Subdomains

Dependencies

  • collections.abc
  • json
  • langchain_core.messages
  • typing

Frequently Asked Questions

What does _compat.py do?
_compat.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, LanguageModelBase subdomain.
What functions are defined in _compat.py?
_compat.py defines 6 function(s): _consolidate_calls, _convert_annotation_from_v1, _convert_from_v1_to_chat_completions, _convert_from_v1_to_responses, _convert_to_v03_ai_message, _implode_reasoning_blocks.
What does _compat.py depend on?
_compat.py imports 4 module(s): collections.abc, json, langchain_core.messages, typing.
Where is _compat.py in the architecture?
_compat.py is located at libs/partners/openai/langchain_openai/chat_models/_compat.py (domain: LangChainCore, subdomain: LanguageModelBase, directory: libs/partners/openai/langchain_openai/chat_models).

Analyze Your Own Codebase

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

Try Supermodel Free