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
| Type | Role | Key Fields | When to Use |
|---|---|---|---|
| HumanMessage | user | content | User input |
| AIMessage | assistant | content, tool_calls, usage_metadata | Model responses, tool call requests |
| SystemMessage | system | content | Set persona, rules, context |
| ToolMessage | tool | content, tool_call_id | Return tool execution results |
| AIMessageChunk | assistant | content (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
"You are a helpful weather assistant."
"What's the weather in Tokyo?"
tool_calls: [get_weather(city="Tokyo")]
model decides to call a tool
"25°C, sunny. tool_call_id: call_abc"
tool result tied to tool_call_id
"Tokyo is 25°C and sunny today!"
final response to user
"To" | "kyo" | " is" | " 25°C" | "…"
same response, streamed token by token
SystemMessage → HumanMessage → AIMessage (tool call) → ToolMessage → AIMessage (response)
Messages are the universal currency of LangChain. Every LLM interaction is a list of messages in, message out.