1️⃣ STATE — The Living Memory
State is the single source of truth in LangGraph.
It is the data object that flows through every node.
🧠 State = Agent’s brain
Everything the agent knows or has produced so far lives here.
State can contain:
Messages (conversation history)
Tool outputs
Flags
Counters
Intermediate results
Retrieved documents
state = {
"messages": [...],
"documents": [...],
"step_count": 3,
"is_finished": False
}
📌 State is mutable across nodes
📌 State grows as the graph runs
TypedDict defines WHAT keys the state can have and their types.
It does not store data.
It describes data.
📐 TypedDict = Architectural blueprint
It tells LangGraph:
Which fields exist
What type each field must be
Prevents accidental state corruption
Makes large graphs predictable
Enables static checks & IDE support
Forces discipline in agent design
class AgentState(TypedDict):
messages: list
documents: list
is_finished: bool
📌 TypedDict never changes at runtime
📌 It enforces structure, not behavior
Messages are atomic units of conversation.
Each message is an instance of:
HumanMessage
AIMessage
SystemMessage
ToolMessage
All inherit from BaseMessage.
💬 Messages = Thoughts and memory fragments
Agents think by appending messages.
Messages:
Carry user intent
Store LLM reasoning
Preserve tool results
Drive routing decisions
Enable replay & explainability
messages = [
HumanMessage("Explain RAG"),
AIMessage("Let me explain..."),
ToolMessage("Search results")
]
📌 Messages are append-only
📌 They form the reasoning timeline
TypedDict → defines State structure
State → holds Messages + data
Messages → drive reasoning & control
TypedDict stays constant
State evolves
Messages accumulate
| Concept | Role | Changes at Runtime? | Purpose |
|---|---|---|---|
| TypedDict | Structure | ❌ No | Safety & predictability |
| State | Container | ✅ Yes | Memory & flow |
| Messages | Content | ✅ Yes | Reasoning & control |
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.
“TypedDict defines the shape of state, state carries the data, and messages are the reasoning units that drive LangGraph execution.”
TypedDict is the contract, State is the memory, Messages are the thoughts.