Home / Class/ InMemoryHistory Class — langchain Architecture

InMemoryHistory Class — langchain Architecture

Architecture documentation for the InMemoryHistory class in test_runnable_events_v2.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  7b02161f_a331_62af_61a1_d9e628a3f41e["InMemoryHistory"]
  bafcb99b_bf29_77cc_2ba1_06c40c54e908["BaseChatMessageHistory"]
  7b02161f_a331_62af_61a1_d9e628a3f41e -->|extends| bafcb99b_bf29_77cc_2ba1_06c40c54e908
  33c02978_2077_5819_7048_bc2a81e80625["test_runnable_events_v2.py"]
  7b02161f_a331_62af_61a1_d9e628a3f41e -->|defined in| 33c02978_2077_5819_7048_bc2a81e80625
  a35a2b06_d230_78c7_e382_a3e274acf675["add_message()"]
  7b02161f_a331_62af_61a1_d9e628a3f41e -->|method| a35a2b06_d230_78c7_e382_a3e274acf675
  c5bb3014_45c4_cc75_d40b_0453d8678a92["clear()"]
  7b02161f_a331_62af_61a1_d9e628a3f41e -->|method| c5bb3014_45c4_cc75_d40b_0453d8678a92

Relationship Graph

Source Code

libs/core/tests/unit_tests/runnables/test_runnable_events_v2.py lines 1906–1921

    class InMemoryHistory(BaseChatMessageHistory, BaseModel):
        """In memory implementation of chat message history."""

        # Attention: for the tests use an Any type to work-around a pydantic issue
        # where it re-instantiates a list, so mutating the list doesn't end up mutating
        # the content in the store!

        # Using Any type here rather than list[BaseMessage] due to pydantic issue!
        messages: Any

        def add_message(self, message: BaseMessage) -> None:
            """Add a self-created message to the store."""
            self.messages.append(message)

        def clear(self) -> None:
            self.messages = []

Frequently Asked Questions

What is the InMemoryHistory class?
InMemoryHistory is a class in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable_events_v2.py.
Where is InMemoryHistory defined?
InMemoryHistory is defined in libs/core/tests/unit_tests/runnables/test_runnable_events_v2.py at line 1906.
What does InMemoryHistory extend?
InMemoryHistory extends BaseChatMessageHistory.

Analyze Your Own Codebase

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

Try Supermodel Free