Source code for langchain.memory.chat_message_histories.in_memory
from typing import List
from langchain.pydantic_v1 import BaseModel, Field
from langchain.schema import (
    BaseChatMessageHistory,
)
from langchain.schema.messages import BaseMessage
[docs]class ChatMessageHistory(BaseChatMessageHistory, BaseModel):
    """In memory implementation of chat message history.
    Stores messages in an in memory list.
    """
    messages: List[BaseMessage] = Field(default_factory=list)
[docs]    def add_message(self, message: BaseMessage) -> None:
        """Add a self-created message to the store"""
        self.messages.append(message)
[docs]    def clear(self) -> None:
        self.messages = []