Back interInterview-ready explanation of BaseMessage and HumanMessage in LangChain, 08 Jan, 2026

Here’s a clear,  explained from core concept → practical usage → mental model.


1️⃣ What is BaseMessage?

🔹 Definition

BaseMessage is the abstract parent class for all message types in LangChain.

It represents one unit of conversation passed to or from an LLM.

🔹 Think of it as:

📦 A generic envelope for a message

It does not represent who sent the message —
it only defines what a message must look like.


🔹 Core Responsibilities of BaseMessage

Every message in LangChain must have:

AttributeMeaning
contentThe actual text or multimodal data
typeWho sent it (human, ai, system, tool)
additional_kwargsExtra metadata (function calls, tool calls, etc.)

🔹 Simplified Structure

BaseMessage(
    content="text or structured data",
    additional_kwargs={}
)

⚠️ You never instantiate BaseMessage directly
It exists to enforce a contract for all message types.


🔹 Why BaseMessage Exists

LangChain needs a standard format so that:

  • Different message types can be stored together

  • Conversation history can be replayed

  • LLMs can receive structured chat input

  • Agents can reason over messages uniformly


2️⃣ What is HumanMessage?

🔹 Definition

HumanMessage is a concrete subclass of BaseMessage.

It represents input coming from the user.


🔹 Think of it as:

🧑 User talking to the AI

Whenever a user types:

“Explain transformers”

LangChain internally wraps it as:

HumanMessage(content="Explain transformers")

🔹 Key Properties

PropertyValue
type"human"
contentUser’s input
additional_kwargsOptional metadata

🔹 Example Usage

from langchain_core.messages import HumanMessage

msg = HumanMessage(content="What is RAG?")

This message can now be:

  • Sent to an LLM

  • Stored in memory

  • Passed through an agent

  • Used in a state graph


3️⃣ Relationship Between Them

BaseMessage
   ├── HumanMessage   (user input)
   ├── AIMessage      (LLM output)
   ├── SystemMessage  (instructions)
   └── ToolMessage    (tool responses)

📌 BaseMessage defines the rules
📌 HumanMessage follows those rules


4️⃣ Real-World Mental Model (Very Important)

Imagine a chat application backend:

  • BaseMessage → 📄 Message schema

  • HumanMessage → 👤 User sends message

  • AIMessage → 🤖 Bot replies

  • SystemMessage → ⚙️ App rules

  • ToolMessage → 🔧 External service response

LangChain uses this model so agents and LLMs can:

  • Reason step-by-step

  • Maintain memory

  • Route messages correctly


5️⃣ Why You Should Care (Agentic / RAG Context)

In Agentic RAG, LangGraph, and Memory systems:

  • Messages are the state

  • State is composed of BaseMessage objects

  • Agents decide actions by reading message history

Example:

state["messages"].append(
    HumanMessage(content="Search latest RBI guidelines")
)

⚠️ If messages were not standardized → agents would break.


6️⃣ Interview Gold Line 🥇

BaseMessage is the abstract contract for all conversational units in LangChain, while HumanMessage is a concrete implementation representing user input within that contract.”


7️⃣ One-Line Summary

BaseMessage defines what a message is; HumanMessage represents a message from the user.