1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
38 small wins to finish your pathNext lesson →
Messages: how a model reads and writes
Messages are the objects a chat model reads and writes. The four you use most are HumanMessage, AIMessage, SystemMessage and ToolMessage.
Last updated: 27 Sep, 2026 · LangChain 1.4
A conversation is a list of messages. Each one has a type (its role) and content. The model is given the list and returns the next message.
The message-type imports
from langchain.messages import HumanMessage, AIMessage, SystemMessage, ToolMessageA conversation as a list
Start by importing the two message types you need and building a conversation. A conversation is a plain Python list of message objects.
from langchain.messages import SystemMessage, HumanMessage
conversation = [
SystemMessage("You are a support assistant."), # your instructions to the model
HumanMessage("I was charged twice."), # the user's turn
]Reading role and content
Walk the list and print each one. type(m).__name__ is the message's class name, which is its role, and m.content is its text.
for m in conversation:
print(type(m).__name__, "->", m.content) # role, then textPrinting the conversation
The two snippets together:
from langchain.messages import SystemMessage, HumanMessage
conversation = [
SystemMessage("You are a support assistant."),
HumanMessage("I was charged twice."),
]
for m in conversation:
print(type(m).__name__, "->", m.content)What each message carries
- Each message is an object with a role (its class) and
content. - A
SystemMessagesets instructions; aHumanMessageis the user's turn; the model replies with anAIMessage. - A
ToolMessagecarries a tool's result back to the model and must settool_call_idto match the call it answers.
The four message types
| Type | Who it is from | Key fields |
|---|---|---|
SystemMessage | You, as instructions | content |
HumanMessage | The user | content |
AIMessage | The model | content, tool_calls |
ToolMessage | A tool's result | content, tool_call_id |
Where messages appear
- Every model call takes a list of messages and returns one.
- The conversation your agent remembers is a list of these objects.
Watch out. In LangChain v1 the import is
from langchain.messages import .... Older code uses from langchain_core.messages import ..., which still works.Related
- Previous: Subgraphs: a graph inside a graph
- Next: MessagesState and add_messages
- Reference: Messages
Try it yourself
- Add an
AIMessage("How can I help?")to the list and print it. - Give a
HumanMessageanameand print it.
This is what real progress feels like.