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.

[留言]

为什么值得关注

有直接可用的方法、工具或操作价值;符合当前抓取需求;它有实际可用价值,可以直接迁移到方法、工具或工作流

来源:reddit,领域:tech,保留分:0.61