Messages
A message carries a role, content, and optional metadata. The main types are SystemMessage, HumanMessage, AIMessage, and ToolMessage.
Tiny example
Section titled “Tiny example”from langchain.messages import HumanMessage, SystemMessage
messages = [ SystemMessage("Answer from the supplied refund policy only."), HumanMessage("Can order A-19 be returned after 45 days?"),]reply = model.invoke(messages)Think of the list as the envelope sent on this call. A model is not remembering an earlier Python request unless your application sends or retrieves that history again.
What belongs where?
Section titled “What belongs where?”| Message | Job |
|---|---|
| System | Stable role, rules, and boundaries |
| Human | The user’s current request |
| AI | A model response, including requested tool calls |
| Tool | One tool result tied to one tool-call ID |
Failure note
Section titled “Failure note”Do not treat message history as durable memory. Long histories can exceed the context window, retain stale facts, or cross tenant boundaries if keyed incorrectly. Store, filter, and trim history deliberately.