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

Messages are the objects a chat model reads and writes. The four you use most are HumanMessage, AIMessage, SystemMessage and ToolMessage.

Last updated: 29 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.

Text prompts and a list of messages · from the Complete Agentic AI Course In 10 Hours · 70:17 to 75:13

The LangChain section of the video separates two kinds of input. A plain string, such as model.invoke("what is langchain"), is a text prompt: fine for one request with no history. A list of message objects is a message prompt, which can tell the model how to behave and carry a conversation. The video's first list has a system message, "You are a poetry expert", and a human message asking for a poem on artificial intelligence; the poem comes back as an AI message. The video loads groq:qwen/qwen3-32b, since retired, so the code below uses the course model, loaded with init_chat_model, which Chat models covers:

python
from langchain.chat_models import init_chat_model
from langchain.messages import SystemMessage, HumanMessage, AIMessage

model = init_chat_model("groq:openai/gpt-oss-120b")   # the model from the setup lesson

messages = [
    SystemMessage("You are a poetry expert"),
    HumanMessage("Write a poem on artificial intelligence"),
]
response = model.invoke(messages)
print(response.content)

A graph passes the same kind of list from node to node. The support conversation below is built from the same classes and printed one message at a time.

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

This is what real progress feels like.