The 1-line annotation that gives your LangGraph agent conversation memory
Hit a frustrating bug: my ReAct agent answered questions correctly in isolation, but couldn't handle follow-ups.
"What's 15 * 127?" → "1905" ✓
"Add 10 to that" → "I don't know what you're referring to" ✗
The agent was losing context between messages. Spent two days debugging.
The fix is one annotation:
messages: Annotated[list, add_messages]
Without it, LangGraph's default behavior REPLACES the messages field on every state update. Your agent only sees the latest message — no history.
With `add_messages` as the reducer, every new message gets APPENDED to the existing list. The agent sees the full conversation.
One line. Two days to figure out. The docs mention it casually in one sentence.
Repo (line 30): https://github.com/dunjeonmaster07/react-agent/blob/main/src/agent.py
Anyone else hit state management gotchas in LangGraph? Curious what other defaults surprised you.