{"slug": "day-1-30-react-pattern-explained", "title": "Day 1/30: ReAct Pattern Explained", "summary": "A developer building a customer support bot encountered context loss issues and adopted the ReAct pattern to maintain conversation state. The pattern, implemented with LangGraph and MCP, uses Reasoning, Action, and Context components to enable the bot to respond appropriately based on conversation history.", "body_md": "I was recently tasked with building a support bot that could handle customer inquiries about our company's products. The bot was supposed to be able to understand the context of the conversation and respond accordingly. However, I soon realized that my initial implementation had a major flaw - the bot would often forget the context of the conversation and respond with irrelevant answers. For example, if a customer asked about the features of a specific product, the bot would respond with a generic description of the product, without taking into account the customer's previous questions.\n\nThis is when I stumbled upon the ReAct pattern, a fundamental concept in building agentic AI systems. The ReAct pattern is a simple yet powerful idea that helps AI agents maintain context and make decisions based on their current state. In the context of my support bot, the ReAct pattern helped me understand how to design the bot's behavior to take into account the conversation history and respond accordingly.\n\nThe ReAct pattern consists of three main components: **Reasoning**, **Action**, and **Context**. The **Reasoning** component is responsible for evaluating the current state of the agent and determining the best course of action. The **Action** component is responsible for executing the chosen action, and the **Context** component is responsible for updating the agent's state based on the outcome of the action.\n\nIn the case of my support bot, the **Reasoning** component would evaluate the customer's input and determine the best response based on the conversation history. The **Action** component would then generate the response, and the **Context** component would update the conversation history to reflect the customer's new question.\n\nHere's an example of how I implemented the ReAct pattern in my support bot using LangGraph and MCP:\n\n``` python\nimport langgraph as lg\nfrom mcp import tools\n\n# Define the support bot's state graph\nstate_graph = lg.StateGraph()\n\n# Add nodes for each possible state\nstate_graph.add_node(\"start\")\nstate_graph.add_node(\"product_inquiry\")\nstate_graph.add_node(\"pricing_inquiry\")\n\n# Add conditional edges between nodes\nstate_graph.add_conditional_edges(\n    (\"start\", \"product_inquiry\", lambda x: x[\"intent\"] == \"product_inquiry\"),\n    (\"product_inquiry\", \"pricing_inquiry\", lambda x: x[\"intent\"] == \"pricing_inquiry\")\n)\n\n# Define the reasoning function\ndef reasoning(state, input_data):\n    # Evaluate the customer's input and determine the best course of action\n    if input_data[\"intent\"] == \"product_inquiry\":\n        return \"product_inquiry\"\n    elif input_data[\"intent\"] == \"pricing_inquiry\":\n        return \"pricing_inquiry\"\n    else:\n        return \"start\"\n\n# Define the action function\ndef action(state, input_data):\n    # Generate a response based on the current state and customer input\n    if state == \"product_inquiry\":\n        return \"What product would you like to know more about?\"\n    elif state == \"pricing_inquiry\":\n        return \"What is your budget for the product?\"\n    else:\n        return \"Welcome to our support bot! How can I help you today?\"\n\n# Define the context function\ndef context(state, input_data):\n    # Update the conversation history based on the customer's input\n    if input_data[\"intent\"] == \"product_inquiry\":\n        return {\"conversation_history\": [\"product_inquiry\"]}\n    elif input_data[\"intent\"] == \"pricing_inquiry\":\n        return {\"conversation_history\": [\"pricing_inquiry\"]}\n    else:\n        return {\"conversation_history\": []}\n\n# Create an MCP tool to interact with the support bot\ntool = tools.Tool(\n    state_graph=state_graph,\n    reasoning_function=reasoning,\n    action_function=action,\n    context_function=context\n)\n\n# Test the support bot\ninput_data = {\"intent\": \"product_inquiry\", \"text\": \"I'm interested in learning more about your products\"}\nresponse = tool.interact(input_data)\nprint(response)  # Output: What product would you like to know more about?\n```\n\nOne practical gotcha I learned while implementing the ReAct pattern is that it's essential to carefully design the state graph and conditional edges to ensure that the agent can transition between states correctly. If the state graph is not well-designed, the agent may get stuck in an infinite loop or fail to respond to certain inputs.\n\nAs I continue to work on my support bot, I'm excited to explore more advanced topics in agentic AI, such as how to integrate multiple AI models and handle complex decision-making scenarios. Tomorrow, I'll be diving deeper into the world of LangGraph and MCP, and I'm looking forward to sharing my discoveries with you.", "url": "https://wpnews.pro/news/day-1-30-react-pattern-explained", "canonical_source": "https://dev.to/yashwanth_kasi/day-130-react-pattern-explained-3nbf", "published_at": "2026-07-12 08:25:11+00:00", "updated_at": "2026-07-12 08:43:23.115364+00:00", "lang": "en", "topics": ["ai-agents", "large-language-models", "developer-tools"], "entities": ["LangGraph", "MCP"], "alternates": {"html": "https://wpnews.pro/news/day-1-30-react-pattern-explained", "markdown": "https://wpnews.pro/news/day-1-30-react-pattern-explained.md", "text": "https://wpnews.pro/news/day-1-30-react-pattern-explained.txt", "jsonld": "https://wpnews.pro/news/day-1-30-react-pattern-explained.jsonld"}}