Articles → LANGCHAIN → Message Classes In Langchain
Message Classes In Langchain
Message Classes
- HumanMessage
- SystemMessage
- AIMessage
Humanmessage
Systemmessage
Aimessage
Example
from langchain_openai import ChatOpenAIfrom langchain_core.messages import HumanMessage, SystemMessage, AIMessage# Create modelllm = ChatOpenAI( model="gpt-4o-mini", temperature=0)# Conversation messagesmessages = [ SystemMessage(content="You are a helpful coding assistant."), HumanMessage(content="What is Python?"), AIMessage(content="Python is a programming language."), HumanMessage(content="Who created it?")]# Send conversation to modelresponse = llm.invoke(messages)print(response.content)
Output
How Does The Flow Work?
SystemMessage(content="You are a helpful coding assistant.")
HumanMessage(content="What is Python?")
AIMessage(content="Python is a programming language.")
HumanMessage(content="Who created it?")
| Posted By - | Karan Gupta |
| |
| Posted On - | Thursday, May 14, 2026 |