Home / Class/ InMemoryHistory Class — langchain Architecture

InMemoryHistory Class — langchain Architecture

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

Entity Profile

Dependency Diagram

graph TD
  d4e61c23_faa5_2771_2540_20b9381f6d0d["InMemoryHistory"]
  bafcb99b_bf29_77cc_2ba1_06c40c54e908["BaseChatMessageHistory"]
  d4e61c23_faa5_2771_2540_20b9381f6d0d -->|extends| bafcb99b_bf29_77cc_2ba1_06c40c54e908
  8ff41f3c_f250_f8de_8094_4f24860a10e0["test_runnable_events_v1.py"]
  d4e61c23_faa5_2771_2540_20b9381f6d0d -->|defined in| 8ff41f3c_f250_f8de_8094_4f24860a10e0
  e513bf9b_8331_0da8_3ae8_4496cbe89bb8["add_message()"]
  d4e61c23_faa5_2771_2540_20b9381f6d0d -->|method| e513bf9b_8331_0da8_3ae8_4496cbe89bb8
  59618b17_1870_c6b7_c31d_2f0d1c32f83a["clear()"]
  d4e61c23_faa5_2771_2540_20b9381f6d0d -->|method| 59618b17_1870_c6b7_c31d_2f0d1c32f83a

Relationship Graph

Source Code

libs/core/tests/unit_tests/runnables/test_runnable_events_v1.py lines 1958–1973

    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_v1.py.
Where is InMemoryHistory defined?
InMemoryHistory is defined in libs/core/tests/unit_tests/runnables/test_runnable_events_v1.py at line 1958.
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