liveBook · Manning

HumanMessage

As explained in Build Python Web Apps with Streamlit

HumanMessage is a LangChain message class representing content supplied by a human participant.

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

How Build Python Web Apps with Streamlit covers it

How deep it goes
Defines the role, content field, message-list placement, and display type, but does not detail class internals.
Examples
Shows HumanMessage wrapping terminal input, initializing graph state, invoking a chatbot, and rendering stored conversation history.
What it assumes
Assumes basic Python lists and function calls while introducing message roles and LangGraph message state.
What you can do after
Builds a graph input from user text and displays HumanMessage content alongside AI responses.
How it connects
Connects HumanMessage with AnyMessage, AIMessage, SystemMessage, LangGraph state, LLM invocation, and Streamlit chat display.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.