Message State is a part of the agent's state that stores the entire chat history as a list of structured message objects like HumanMessage
, AIMessage
, or ToolMessage
.
✅ Context Retention: It helps the agent remember the full conversation.
🧠 Prompt Construction: These messages are passed to the LLM as context.
🔄 State Transitioning: Decisions (like which tool to call or how to respond) depend on recent messages.
{
"messages": [
HumanMessage(content="What's the weather like?"),
AIMessage(content="Where are you located?")
]
}
Type | Class | Purpose |
---|---|---|
👤 HumanMessage |
From user | |
🤖 AIMessage |
From AI model | |
🛠️ ToolMessage |
Output from a tool | |
📤 SystemMessage |
System-level instructions (optional) |
Defined inside the agent’s state as:
from typing import TypedDict, List
from langchain_core.messages import BaseMessage
class AgentState(TypedDict):
messages: List[BaseMessage]
Each node in the graph reads from or appends to this message list.
Imagine a chat log in WhatsApp:
You (user) send a message → HumanMessage
Bot replies → AIMessage
You send a location → tool processes it → ToolMessage
That ongoing log = Message State.