LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-corechat_history
    Moduleā—Since v0.1

    chat_history

    Chat message history stores a history of the message interactions in a chat.

    Functions

    function
    get_buffer_string
    function
    run_in_executor

    Classes

    class
    AIMessage
    class
    BaseMessage
    class
    HumanMessage
    class
    BaseChatMessageHistory
    class
    InMemoryChatMessageHistory
    View source on GitHub

    Convert a sequence of messages to strings and concatenate them into one string.

    Run a function in an executor.

    Message from an AI.

    An AIMessage is returned from a chat model as a response to a prompt.

    This message represents the output of the model and consists of both the raw output as returned by the model and standardized fields (e.g., tool calls, usage metadata) added by the LangChain framework.

    Base abstract message class.

    Messages are the inputs and outputs of a chat model.

    Examples include HumanMessage, AIMessage, and SystemMessage.

    Message from the user.

    A HumanMessage is a message that is passed in from a user to the model.

    Abstract base class for storing chat message history.

    Implementations guidelines:

    Implementations are expected to over-ride all or some of the following methods:

    • add_messages: sync variant for bulk addition of messages
    • aadd_messages: async variant for bulk addition of messages
    • messages: sync variant for getting messages
    • aget_messages: async variant for getting messages
    • clear: sync variant for clearing messages
    • aclear: async variant for clearing messages

    add_messages contains a default implementation that calls add_message for each message in the sequence. This is provided for backwards compatibility with existing implementations which only had add_message.

    Async variants all have default implementations that call the sync variants. Implementers can choose to override the async implementations to provide truly async implementations.

    Usage guidelines:

    When used for updating history, users should favor usage of add_messages over add_message or other variants like add_user_message and add_ai_message to avoid unnecessary round-trips to the underlying persistence layer.

    In memory implementation of chat message history.

    Stores messages in a memory list.