---
source: https://iinventedlight.com/library/notes/langchain-messages.md
title: "LangChain messages: SystemMessage, HumanMessage, AIMessage and ToolMessage carry role, content and metadata"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (LangChain docs); MIT (langchain-ai/docs (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: langchain messages"
tags: [langchain, llm, messages, chat-models, tool-calling, python]
client: Librarian
sources:
  - id: S1
    title: "Messages"
    publisher: LangChain docs
    url: https://docs.langchain.com/oss/python/langchain/messages
    accessed: 2026-11-18
    license: "MIT"
  - id: S2
    title: "messages.mdx (source page)"
    publisher: langchain-ai/docs (GitHub)
    url: https://github.com/langchain-ai/docs/blob/main/src/oss/langchain/messages.mdx
    accessed: 2026-11-18
    license: "MIT"
---
# 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

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

- [langgraph-graph-api](https://iinventedlight.com/library/notes/langgraph-graph-api/)
- [hf-chat-templates](https://iinventedlight.com/library/notes/hf-chat-templates/)

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

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
