cd /news/ai-agents/day-8-30-react-loop-in-langgraph · home topics ai-agents article
[ARTICLE · art-64382] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=· neutral

Day 8/30: ReAct Loop in LangGraph

A developer building a support bot with LangGraph's ReAct loop encountered a memory issue where the bot forgets user input from two turns ago. The StateGraph lacks built-in context, requiring integration with MCP tools for memory. The developer warns of infinite loop risks without proper termination conditions.

read3 min views1 publishedJul 18, 2026

So you've built an agentic AI system with LangGraph and MCP, and it's working great - until it starts forgetting what the user said two turns ago. You're trying to implement a simple support bot that can answer follow-up questions, but it keeps responding as if it has no memory. You've checked the LangGraph documentation, and it seems like the StateGraph

should be able to handle this kind of context. But for some reason, it's just not working.

Let's take a step back and look at how LangGraph's ReAct

loop is supposed to work. The idea is that your agent will reason about the current state of the world, act based on that reasoning, observe the consequences of its action, and then repeat the process. This loop is the core of how LangGraph agents make decisions and learn from their environment.

In your support bot, the ReAct

loop might look something like this:

import langgraph as lg

graph = lg.StateGraph()

graph.add_node("greeting", "Hello! How can I help you?")
graph.add_node("question", "You asked a question")
graph.add_node("answer", "Here's an answer to your question")

graph.add_conditional_edges(
    ("greeting", "question", lambda x: x["user_input"] != ""),
    ("question", "answer", lambda x: x["user_input"] != "")
)

def checkpoint(state):
    print("Checkpointing state:", state)

while True:
    state = graph.get_current_state()

    next_node = graph.get_next_node(state)

    user_input = input("User: ")
    state["user_input"] = user_input

    graph.update_state(state)
    checkpoint(state)

This code sets up a simple StateGraph

with three nodes: a greeting, a question, and an answer. The ReAct

loop runs indefinitely, reasoning about the current state of the graph, acting based on that reasoning, observing the user's input, and repeating the process.

But here's the thing: if you run this code, you'll notice that the bot doesn't actually remember what the user said two turns ago. That's because the StateGraph

is designed to be a relatively simple, reactive system - it doesn't have any built-in memory or context.

To fix this, you need to add some kind of memory or context to the StateGraph

. One way to do this is by using LangGraph's MCP

tools to create a more complex, contextual model of the user's input. We'll dive into that tomorrow, but for now, let's just say that it's a good idea to use a combination of StateGraph

and MCP

to build a more robust, contextual AI system.

One practical gotcha to watch out for when working with the ReAct

loop is that it can be easy to get stuck in an infinite loop if your agent doesn't have a clear way to terminate or exit the loop. For example, if your agent is designed to keep responding to user input indefinitely, you may need to add some kind of timeout or exit condition to prevent it from running forever.

Looking ahead, we'll be exploring more advanced techniques for building contextual AI systems with LangGraph and MCP - including how to integrate multiple models and systems to create more sophisticated, human-like behavior.

── more in #ai-agents 4 stories · sorted by recency
── more on @langgraph 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/day-8-30-react-loop-…] indexed:0 read:3min 2026-07-18 ·