Some text some message..
Back Message State in LangGraph 29 Jul, 2025

💬 What is Message State in LangGraph?

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.


🔍 Why is it Important?

  1. Context Retention: It helps the agent remember the full conversation.

  2. 🧠 Prompt Construction: These messages are passed to the LLM as context.

  3. 🔄 State Transitioning: Decisions (like which tool to call or how to respond) depend on recent messages.


🧱 Typical Structure

{
  "messages": [
    HumanMessage(content="What's the weather like?"),
    AIMessage(content="Where are you located?")
  ]
}

🔧 Message Types in LangChain

Type Class Purpose
👤 HumanMessage From user
🤖 AIMessage From AI model
🛠️ ToolMessage Output from a tool
📤 SystemMessage System-level instructions (optional)

💡 How It’s Used in LangGraph

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.


📌 Real-World Analogy

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.