HumanMessage represents content supplied by a human participant in a LangChain conversation. It corresponds to the user role, alongside AIMessage for assistant responses and SystemMessage for system instructions. section 10.2.3
A HumanMessage stores the participant’s text in its content field and can be placed in a messages list. LangGraph nodes can pass that list to an LLM, allowing the model to respond using the user’s input. section 10.2.3 section 10.3.2
Create the initial graph state
Read a prompt, wrap it as HumanMessage, and place it in the graph state: input_message = input("Talk to the bot: "); initial_state = {"messages": [HumanMessage(content=input_message)]}. The graph can then invoke the assistant node with this human message. section 10.2.3
Listing 10.1 An example of a graph
from langgraph.graph import START, END, StateGraph
from langchain_core.messages import AnyMessage, HumanMessage
from langchain_openai import ChatOpenAI
from typing import TypedDict
llm = ChatOpenAI(model_name="gpt-5.1", openai_api_key="sk-proj-...")
class MyGraphState(TypedDict):
messages: list[AnyMessage]
builder = StateGraph(MyGraphState)
def assistant_node(state):
messages = state["messages"]
ai_response_message = llm.invoke(messages)
return {"messages": messages + [ai_response_message]}
builder.add_node("assistant", assistant_node)
builder.add_edge(START, "assistant")
builder.add_edge("assistant", END)
graph = builder.compile()
input_message = input("Talk to the bot: ")
initial_state = {"messages": [HumanMessage(content=input_message)]}
final_state = graph.invoke(initial_state)
print("Bot:\n" + final_state["messages"][-1].content)
Listing 10.1 shows HumanMessage in a complete single-node LangGraph example, from prompt collection through graph invocation and response printing. section 10.2.3
