u/Low_Edge7695

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.

reddit.com
u/Low_Edge7695 — 21 hours ago
▲ 17 r/LangChain+2 crossposts

The 4-line function that fixed my agent's wrong answers (conditional edge in LangGraph)

My ReAct agent gave wrong answers for a week. It would call a tool, get a result, and immediately answer without checking if the result made sense.

The fix was a conditional edge — 4 lines:

    def conditional_edge(state: MessageState):
        last_message = state["messages"][-1]
        if last_message.tool_calls:
            return "tool"
        return END

Without it: LLM → tool → answer (one shot, no self-correction)

With it: LLM → tool → check → loop back if needed → answer

Full repo (67 lines total): https://github.com/dunjeonmaster07/react-agent

What other simple patterns made a big difference in your agent's reliability?

u/Low_Edge7695 — 3 days ago