LangChain/Core Concepts
Beginner7 min

Message Types

HumanMessage, AIMessage, SystemMessage, ToolMessage — the building blocks of every LangChain conversation.

Quick Reference

  • HumanMessage = user input, AIMessage = model response
  • SystemMessage sets the persona and instructions
  • ToolMessage carries tool call results back to the model
  • Messages are the universal currency in LangChain — chains, agents, and memory all use them

The 5 Message Types

TypeRoleKey FieldsWhen to Use
HumanMessageusercontentUser input
AIMessageassistantcontent, tool_calls, usage_metadataModel responses, tool call requests
SystemMessagesystemcontentSet persona, rules, context
ToolMessagetoolcontent, tool_call_idReturn tool execution results
AIMessageChunkassistantcontent (partial)Streaming responses (token by token)

Here's how all five types appear in a real scenario — a user asking about the weather, the model calling a tool, and responding:

Scenario: user asks about the weather → agent calls a tool → responds

SystemMessagerole: system

"You are a helpful weather assistant."

HumanMessagerole: user

"What's the weather in Tokyo?"

AIMessagerole: assistant

tool_calls: [get_weather(city="Tokyo")]

model decides to call a tool

ToolMessagerole: tool

"25°C, sunny. tool_call_id: call_abc"

tool result tied to tool_call_id

AIMessagerole: assistant

"Tokyo is 25°C and sunny today!"

final response to user

or via .stream()
AIMessageChunkrole: assistant

"To" | "kyo" | " is" | " 25°C" | "…"

same response, streamed token by token

SystemMessage → HumanMessage → AIMessage (tool call) → ToolMessage → AIMessage (response)

Universal currency

Messages are the universal currency of LangChain. Every LLM interaction is a list of messages in, message out.