By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
A chat model call takes the whole conversation so far, not just the latest sentence. Each message has a role: system sets behaviour, human is the customer, AI is the model's own turn, and tool carries a function's result. The model reads the roles and predicts the next message.
| Message | Who creates it | What it carries |
|---|---|---|
SystemMessage | You, the developer | Durable rules: identity, tone, boundaries, output format |
HumanMessage | The customer or your UI | The current request, plus any image, file or audio content |
AIMessage | The model | Text, tool calls, reasoning blocks, usage metadata |
ToolMessage | Your code or the agent runtime | One tool result, linked to the request by tool_call_id |
The example below is a complete model call against a live provider. The captured output is illustrative: wording and token counts vary between runs, and the number you see depends on the system prompt, the model and the provider's tokenizer.
from langchain.chat_models import init_chat_model
from langchain.messages import HumanMessage, SystemMessage
model = init_chat_model("openai:gpt-4.1-mini", temperature=0)
reply = model.invoke(
[
SystemMessage(
"You are Harbor Supply's support agent. Be concise. Never invent "
"order details; ask for an order number when it is missing."
),
HumanMessage("My order #4521 arrived with a cracked lid. What now?"),
]
)
print(reply.content)
print(reply.usage_metadata)text, tool_call, reasoning, …). Lesson 3 works through this property.Key takeaways
A model call is a full message list in, one AIMessage out.
System messages carry durable rules; human messages carry the turn; AI and tool messages carry the rest of the conversation.
Read the reply object, not just .content: content blocks, tool calls and usage live on the same object.
With no tools bound, a successful call ends with plain text and tool_calls == [].
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.