Skip to main content

Messages

A chat model's input and output are both lists of typed message objects, not raw strings. Each message type maps to a role.

TypeRoleWritten byPurpose
SystemMessagesystemyou, once per chain/conversationinstructions and persona, not user-visible
HumanMessageuseryour application, from user inputthe user's turn
AIMessageassistantthe modelthe model's reply — may carry tool_calls instead of (or alongside) text
ToolMessagetoolyour application, after executing a toolthe result of a tool call, keyed to a tool_call_id
from langchain.messages import AIMessage, HumanMessage, SystemMessage, ToolMessage

messages = [
SystemMessage("You can call the get_weather tool."),
HumanMessage("What's the weather in Lisbon?"),
AIMessage(
content="",
tool_calls=[{"name": "get_weather", "args": {"city": "Lisbon"}, "id": "call_1"}],
),
ToolMessage(content="18°C, partly cloudy", tool_call_id="call_1"),
]

response = model.invoke(messages) # model now answers using the tool result

An AIMessage carrying tool_calls is the shape the tool-calling loop depends on — see Tool Calling.

See also