LangGraphLangGraph 1.2 · Python 3.10+
0%
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

python
from langchain.messages import HumanMessage, AIMessage, SystemMessage, ToolMessage

A 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.

python
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.

python
for m in conversation:
    print(type(m).__name__, "->", m.content)   # role, then text

Printing the conversation

The two snippets together:

Example
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 SystemMessage sets instructions; a HumanMessage is the user's turn; the model replies with an AIMessage.
  • A ToolMessage carries a tool's result back to the model and must set tool_call_id to match the call it answers.

The four message types

TypeWho it is fromKey fields
SystemMessageYou, as instructionscontent
HumanMessageThe usercontent
AIMessageThe modelcontent, tool_calls
ToolMessageA tool's resultcontent, 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.
Try it yourself
  • Add an AIMessage("How can I help?") to the list and print it.
  • Give a HumanMessage a name and print it.

This is what real progress feels like.