← Back to Dashboard
October 19, 2025

Build a LangGraph ReAct agent with LangChain tools

LangChain’s agents now lean on LangGraph, a lightweight orchestration layer that compiles your agent into a graph. This starter walks through the modern stack—using `create_react_agent`, LangChain tools, and the new agent state patterns—then lets you run the finished graph directly from the page.

What’s new in LangChain agents (LangGraph era)

Prerequisites

Starter project: Market expansion advisor

We’ll build a ReAct-style agent that recommends market launch plans. The agent uses a simple knowledge base stored in code, so you can run everything locally.

Define the reusable tool

from langchain.tools import tool

MARKET_FACTS = {
    "brazil": {
        "demand": "Fast-growing premium delivery segment in São Paulo and Rio",
        "competitors": ["Mercado Livre", "Magazine Luiza"],
        "regulations": "ANATEL registration required for electronics imports",
        "support": "Portuguese 24/7 coverage expected",
    },
    "germany": {
        "demand": "Strong repeat purchase loyalty programs",
        "competitors": ["Zalando", "Otto"],
        "regulations": "BfDI expects explicit opt-ins for marketing data",
        "support": "German + English, business hours acceptable",
    },
}

@tool
def market_facts(country: str) -> str:
    """Summaries demand, competitors, regulation, and support notes for a country."""
    data = MARKET_FACTS.get(country.lower())
    if not data:
        return f"No entry for {country}."
    lines = [
        f"Demand: {data['demand']}",
        f"Competitors: {', '.join(data['competitors'])}",
        f"Regulations: {data['regulations']}",
        f"Support: {data['support']}",
    ]
    return "\n".join(lines)

Compile the LangGraph agent

from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

model = ChatOpenAI(model="gpt-4o-mini", temperature=0)
app = create_react_agent(model, [market_facts])

Invoke the graph

result = app.invoke({"messages": [
    ("human", "Outline a six-month launch plan for Germany."),
]})
for msg in result["messages"]:
    print(msg.type.upper(), "::", msg.content)

Complete script

# langgraph_agent.py

from langchain.tools import tool
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

MARKET_FACTS = {
    "brazil": {
        "demand": "Fast-growing premium delivery segment in São Paulo and Rio",
        "competitors": ["Mercado Livre", "Magazine Luiza"],
        "regulations": "ANATEL registration required for electronics imports",
        "support": "Portuguese 24/7 coverage expected",
    },
    "germany": {
        "demand": "Strong repeat purchase loyalty programs",
        "competitors": ["Zalando", "Otto"],
        "regulations": "BfDI expects explicit opt-ins for marketing data",
        "support": "German + English, business hours acceptable",
    },
}

@tool
def market_facts(country: str) -> str:
    data = MARKET_FACTS.get(country.lower())
    if not data:
        return f"No entry for {country}."
    lines = [
        f"Demand: {data['demand']}",
        f"Competitors: {', '.join(data['competitors'])}",
        f"Regulations: {data['regulations']}",
        f"Support: {data['support']}",
    ]
    return "\n".join(lines)

model = ChatOpenAI(model="gpt-4o-mini", temperature=0)
app = create_react_agent(model, [market_facts])

if __name__ == "__main__":
    result = app.invoke({"messages": [("human", "Outline a six-month launch plan for Brazil.")]})
    final = result["messages"][-1]
    print("\n=== PLAN ===\n", final.content)

Customize the fact base, add more tools, or route multiple tools through `ToolNode` for validation before execution.

Preview a session transcript

Agent ▸
Thought: I should inspect the Brazil entry.
Action: market_facts("brazil")
Tool ▸ market_facts
Demand: Fast-growing premium delivery segment in São Paulo and Rio
Competitors: Mercado Livre, Magazine Luiza
Regulations: ANATEL registration required for electronics imports
Support: Portuguese 24/7 coverage expected
Agent ▸
Drafted six-month plan with localization, loyalty pilot, compliance track, and national launch marketing.

Run the live demo

Click the button below to run the Brazil scenario through a LangGraph agent on the server. If credentials are missing, the interface falls back to the saved transcript.

Operational checklist

  1. Model selection: use LangGraph runtime context to swap models per request.
  2. Observability: capture graph events with LangSmith or OpenTelemetry for replay.
  3. Human-in-the-loop: wire `HumanInterrupt` to approvals when agents need human confirmation.

"Treat agents as graphs: every tool, condition, and hand-off becomes explicit—and much easier to debug."

Review the LangGraph agent reference for details on `AgentState`, `ToolNode`, and advanced supervisor patterns.