Back 🧠 State vs TypedDict vs Messages (LangGraph) 08 Jan, 2026

1️⃣ STATE — The Living Memory

What is State?

State is the single source of truth in LangGraph.

It is the data object that flows through every node.

Mental Model

🧠 State = Agent’s brain

Everything the agent knows or has produced so far lives here.


What State Contains

State can contain:

  • Messages (conversation history)

  • Tool outputs

  • Flags

  • Counters

  • Intermediate results

  • Retrieved documents


Example (Conceptual)

state = {
  "messages": [...],
  "documents": [...],
  "step_count": 3,
  "is_finished": False
}

📌 State is mutable across nodes
📌 State grows as the graph runs


2️⃣ TypedDict — The Blueprint of State

What is TypedDict?

TypedDict defines WHAT keys the state can have and their types.

It does not store data.
It describes data.


Mental Model

📐 TypedDict = Architectural blueprint

It tells LangGraph:

  • Which fields exist

  • What type each field must be


Why TypedDict Exists

  • Prevents accidental state corruption

  • Makes large graphs predictable

  • Enables static checks & IDE support

  • Forces discipline in agent design


Example (Conceptual)

class AgentState(TypedDict):
    messages: list
    documents: list
    is_finished: bool

📌 TypedDict never changes at runtime
📌 It enforces structure, not behavior


3️⃣ Messages — Reasoning Units

What are Messages?

Messages are atomic units of conversation.

Each message is an instance of:

  • HumanMessage

  • AIMessage

  • SystemMessage

  • ToolMessage

All inherit from BaseMessage.


Mental Model

💬 Messages = Thoughts and memory fragments

Agents think by appending messages.


What Messages Do

Messages:

  • Carry user intent

  • Store LLM reasoning

  • Preserve tool results

  • Drive routing decisions

  • Enable replay & explainability


Example (Conceptual)

messages = [
  HumanMessage("Explain RAG"),
  AIMessage("Let me explain..."),
  ToolMessage("Search results")
]

📌 Messages are append-only
📌 They form the reasoning timeline


🔁 How They Work Together (Very Important)

Flow Relationship

TypedDict → defines State structure
State     → holds Messages + data
Messages  → drive reasoning & control

Runtime Reality

  • TypedDict stays constant

  • State evolves

  • Messages accumulate


⚙️ Who Does What (Quick Comparison)

ConceptRoleChanges at Runtime?Purpose
TypedDictStructure❌ NoSafety & predictability
StateContainer✅ YesMemory & flow
MessagesContent✅ YesReasoning & control

🧠 Agentic RAG Perspective

  • TypedDict ensures RAG fields exist

  • State carries retrieved chunks

  • Messages store:

    • user query

    • retrieval results

    • reasoning steps

    • final answer

📌 Without messages, RAG is just search.
📌 Without state, agents forget.
📌 Without TypedDict, systems break.


🥇 Interview Gold Line

“TypedDict defines the shape of state, state carries the data, and messages are the reasoning units that drive LangGraph execution.”


🧠 One-Line Summary

TypedDict is the contract, State is the memory, Messages are the thoughts.