Home / File/ history.py — langchain Source File

history.py — langchain Source File

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

File python LangChainCore Runnables 16 imports 2 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  937cdd40_d89c_5be8_355f_bff74b5220b9["history.py"]
  589b2e2f_c593_ed0a_7906_df4ca371d542["inspect"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> 589b2e2f_c593_ed0a_7906_df4ca371d542
  2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> 2bf6d401_816d_d011_3b05_a6114f55ff58
  8322cf04_5861_9d4a_4ee9_a22829f66390["types"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> 8322cf04_5861_9d4a_4ee9_a22829f66390
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> feec1ec4_6917_867b_d228_b134d0ff8099
  dd5e7909_a646_84f1_497b_cae69735550e["pydantic"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> dd5e7909_a646_84f1_497b_cae69735550e
  f85fae70_1011_eaec_151c_4083140ae9e5["typing_extensions"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> f85fae70_1011_eaec_151c_4083140ae9e5
  b70220ee_230d_1b24_69ea_cc9490f5f3c0["langchain_core.chat_history"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> b70220ee_230d_1b24_69ea_cc9490f5f3c0
  679bd51a_077f_a2c5_f968_44da37489a0d["langchain_core.load.load"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> 679bd51a_077f_a2c5_f968_44da37489a0d
  9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> 9444498b_8066_55c7_b3a2_1d90c4162a32
  15b6f2ac_8a3b_5719_0e4d_4652995195ed["langchain_core.runnables.base"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> 15b6f2ac_8a3b_5719_0e4d_4652995195ed
  f6ac5788_e423_ce13_2122_3f47573d9d08["langchain_core.runnables.passthrough"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> f6ac5788_e423_ce13_2122_3f47573d9d08
  b4920617_3c91_2457_3f8c_84ba49f64322["langchain_core.runnables.utils"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> b4920617_3c91_2457_3f8c_84ba49f64322
  314b1cc1_bd2e_bf43_4c2f_8c292c35f3e7["langchain_core.utils.pydantic"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> 314b1cc1_bd2e_bf43_4c2f_8c292c35f3e7
  242b5354_4ca1_727c_dd7a_12de2b570803["langchain_core.language_models.base"]
  937cdd40_d89c_5be8_355f_bff74b5220b9 --> 242b5354_4ca1_727c_dd7a_12de2b570803
  style 937cdd40_d89c_5be8_355f_bff74b5220b9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""`Runnable` that manages chat message history for another `Runnable`."""

from __future__ import annotations

import inspect
from collections.abc import Callable, Sequence
from types import GenericAlias
from typing import (
    TYPE_CHECKING,
    Any,
)

from pydantic import BaseModel
from typing_extensions import override

from langchain_core.chat_history import BaseChatMessageHistory
from langchain_core.load.load import load
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
from langchain_core.runnables.base import Runnable, RunnableBindingBase, RunnableLambda
from langchain_core.runnables.passthrough import RunnablePassthrough
from langchain_core.runnables.utils import (
    ConfigurableFieldSpec,
    Output,
    get_unique_config_specs,
)
from langchain_core.utils.pydantic import create_model_v2

if TYPE_CHECKING:
    from langchain_core.language_models.base import LanguageModelLike
    from langchain_core.runnables.config import RunnableConfig
    from langchain_core.tracers.schemas import Run


MessagesOrDictWithMessages = Sequence["BaseMessage"] | dict[str, Any]
GetSessionHistoryCallable = Callable[..., BaseChatMessageHistory]


class RunnableWithMessageHistory(RunnableBindingBase):  # type: ignore[no-redef]
    """`Runnable` that manages chat message history for another `Runnable`.

    A chat message history is a sequence of messages that represent a conversation.

    `RunnableWithMessageHistory` wraps another `Runnable` and manages the chat message
    history for it; it is responsible for reading and updating the chat message
    history.

    The formats supported for the inputs and outputs of the wrapped `Runnable`
    are described below.

    `RunnableWithMessageHistory` must always be called with a config that contains
    the appropriate parameters for the chat message history factory.

    By default, the `Runnable` is expected to take a single configuration parameter
    called `session_id` which is a string. This parameter is used to create a new
    or look up an existing chat message history that matches the given `session_id`.

    In this case, the invocation would look like this:

    `with_history.invoke(..., config={"configurable": {"session_id": "bar"}})`
    ; e.g., `{"configurable": {"session_id": "<SESSION_ID>"}}`.
// ... (563 more lines)

Domain

Subdomains

Dependencies

  • collections.abc
  • inspect
  • langchain_core.chat_history
  • langchain_core.language_models.base
  • langchain_core.load.load
  • langchain_core.messages
  • langchain_core.runnables.base
  • langchain_core.runnables.config
  • langchain_core.runnables.passthrough
  • langchain_core.runnables.utils
  • langchain_core.tracers.schemas
  • langchain_core.utils.pydantic
  • pydantic
  • types
  • typing
  • typing_extensions

Frequently Asked Questions

What does history.py do?
history.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, Runnables subdomain.
What functions are defined in history.py?
history.py defines 2 function(s): _get_parameter_names, langchain_core.
What does history.py depend on?
history.py imports 16 module(s): collections.abc, inspect, langchain_core.chat_history, langchain_core.language_models.base, langchain_core.load.load, langchain_core.messages, langchain_core.runnables.base, langchain_core.runnables.config, and 8 more.
Where is history.py in the architecture?
history.py is located at libs/core/langchain_core/runnables/history.py (domain: LangChainCore, subdomain: Runnables, directory: libs/core/langchain_core/runnables).

Analyze Your Own Codebase

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

Try Supermodel Free