LangChain messages: SystemMessage, HumanMessage, AIMessage and ToolMessage carry role, content and metadata
Answer: Build a list of message objects (SystemMessage, HumanMessage, AIMessage, ToolMessage) and pass it to model.invoke(messages), which returns an AIMessage. Messages are the fundamental unit of context for models in LangChain and carry a role, content and optional metadata.
Example
from langchain.chat_models import init_chat_model
from langchain.messages import SystemMessage, HumanMessage, AIMessage, ToolMessage
model = init_chat_model("gpt-5-nano")
messages = [
SystemMessage("You are a poetry expert"),
HumanMessage("Write a haiku about spring"),
]
response = model.invoke(messages) # AIMessage
ai = AIMessage(content=[], tool_calls=[{"name": "get_weather",
"args": {"location": "San Francisco"}, "id": "call_123"}])
result = ToolMessage(content="Sunny, 72F", tool_call_id="call_123")
Message types
| Type | Role | |---|---| | SystemMessage | an initial set of instructions that primes the model's behavior: tone, role, guidelines | | HumanMessage | user input and interactions with the model | | AIMessage | responses generated by the model, including text content, tool calls, and metadata | | ToolMessage | passes the results of a single tool execution back to the model |
Three input formats
- A plain string, for a single, standalone request with no conversation history.
- A list of message objects, for multi-turn conversations, multimodal content, or system instructions.
- Dictionaries in OpenAI chat completions format, such as
{"role": "user", "content": "..."}.
AIMessage fields
tool_calls: the tool calls made by the model; empty if no tools are called.id: a unique identifier, generated by LangChain or returned by the provider.usage_metadata: can contain token counts when available.content_blocks: the standardized content blocks of the message.
A ToolMessage's tool_call_id must match the call ID from the AIMessage. LangChain's standard message type works across all model providers.
See also
Claims
- id: C1 claim: Messages are the fundamental unit of context for models. source: S2 evidence: "Messages are the fundamental unit of context for models in LangChain."
- id: C2 claim: Tool messages pass the result of a single tool execution back. source: S2 evidence: "pass the results of a single tool execution back to the model."
- id: C3 claim: tool_calls is empty if no tools are called. source: S1 evidence: "Empty if no tools are called."
Sources
- [S1] Messages. LangChain docs. https://docs.langchain.com/oss/python/langchain/messages . License: MIT. Accessed 2026-11-18.
- [S2] messages.mdx (source page). langchain-ai/docs (GitHub). https://github.com/langchain-ai/docs/blob/main/src/oss/langchain/messages.mdx . License: MIT. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: LangChain docs, Messages; langchain-ai/docs (GitHub), messages.mdx (source page). MIT (https://raw.githubusercontent.com/langchain-ai/docs/main/LICENSE). Copyright LangChain. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: LangChain docs, Messages; langchain-ai/docs (GitHub), messages.mdx (source page). MIT (https://raw.githubusercontent.com/langchain-ai/docs/main/LICENSE). Copyright LangChain.
Cite this
iinventedlight. 2026. "LangChain messages: SystemMessage, HumanMessage, AIMessage and ToolMessage carry role, content and metadata." iinventedlight Library, iil:note:am853768, version of 2026-11-18. https://iinventedlight.com/library/notes/langchain-messages/. License: CC-BY-4.0.
@misc{iil_note_am853768,
author = {{iinventedlight}},
title = {{LangChain messages: SystemMessage, HumanMessage, AIMessage and ToolMessage carry role, content and metadata}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/langchain-messages/},
note = {Permanent ID iil:note:am853768. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- langchain-messages.table.json (table; CC-BY-4.0)
- langchain-messages.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/langchain-messages.md.