Here’s a clear, explained from core concept → practical usage → mental model.
BaseMessage?BaseMessage is the abstract parent class for all message types in LangChain.
It represents one unit of conversation passed to or from an LLM.
📦 A generic envelope for a message
It does not represent who sent the message —
it only defines what a message must look like.
BaseMessageEvery message in LangChain must have:
| Attribute | Meaning |
|---|---|
content | The actual text or multimodal data |
type | Who sent it (human, ai, system, tool) |
additional_kwargs | Extra metadata (function calls, tool calls, etc.) |
BaseMessage(
content="text or structured data",
additional_kwargs={}
)
⚠️ You never instantiate BaseMessage directly
It exists to enforce a contract for all message types.
BaseMessage ExistsLangChain 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
HumanMessage?HumanMessage is a concrete subclass of BaseMessage.
It represents input coming from the user.
🧑 User talking to the AI
Whenever a user types:
“Explain transformers”
LangChain internally wraps it as:
HumanMessage(content="Explain transformers")
| Property | Value |
|---|---|
type | "human" |
content | User’s input |
additional_kwargs | Optional metadata |
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
BaseMessage
├── HumanMessage (user input)
├── AIMessage (LLM output)
├── SystemMessage (instructions)
└── ToolMessage (tool responses)
📌 BaseMessage defines the rules
📌 HumanMessage follows those rules
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
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.
“
BaseMessageis the abstract contract for all conversational units in LangChain, whileHumanMessageis a concrete implementation representing user input within that contract.”
BaseMessagedefines what a message is;HumanMessagerepresents a message from the user.