LangChain ReAct: the loop that still wins for general agents
TL;DR
- ReAct is a three-step loop: Thought, Action, Observation, repeated until the model emits a final answer.
- The langchain react implementation migrated from the soft-deprecated AgentExecutor (Q3 2024) to
langgraph.prebuilt.create_react_agentin LangGraph 0.2+. - Each step adds 300-600 tokens of scratchpad; at GPT-4o-mini pricing ($0.15/1M tokens, Q1 2026) multi-step agents remain economically viable.
- Three failure modes require mitigation before production: infinite loops, tool argument hallucination, and context blowout.
Three years after the original paper, the langchain react pattern is still the default entry point for general-purpose agent development. The frameworks around it have multiplied: LangGraph, AutoGen, CrewAI, custom orchestration layers. Yet when you strip them back, most general agents are running the same Thought-Action-Observation loop that Yao et al. described in 2022.
This article traces why that loop works, how its LangChain implementation has evolved, where alternatives beat it, and what breaks it in production.
The Thought-Action-Observation loop: what the 2022 paper actually says
The paper, "ReAct: Synergizing Reasoning and Acting in Language Models" (Yao et al., arXiv:2210.03629, October 6, 2022), addresses one gap in chain-of-thought prompting: the model can reason, but it cannot gather new information mid-chain. ReAct closes that gap by interleaving reasoning with tool calls.
A single agent turn unfolds in three steps:
- Thought: the model produces a natural-language trace. "The user asked for today's gold price. I should call the price API with the symbol XAU."
- Action: the model emits a structured tool call.
get_spot_price(symbol="XAU"). - Observation: the tool returns a result.
{"price_usd": 2341.50, "as_of": "2026-06-16T08:00Z"}.
The loop repeats until the model emits a "Final Answer" token rather than another Thought.
The paper's empirical case is still cited today. On HotpotQA, a multi-hop question-answering benchmark, the thought-action cycle outperforms chain-of-thought-only prompting by several percentage points in exact-match accuracy. On FEVER, a fact-verification benchmark, access to live observations reduces hallucination rates noticeably. The core finding: a model that can observe fresh data mid-reasoning makes fewer fabrications than one forced to reason in a closed context.
The deeper structural advantage is debuggability. Every Thought is visible in the trace. When a step-by-step reasoning agent fails, you can read exactly where its logic broke. That property separates ReAct from architectures that collapse multi-step decisions into a single opaque call, and it remains the primary reason teams choose this agentic workflow for general tasks.
How LangChain ReAct is implemented today (LangGraph 0.2+)
AgentExecutor vs LangGraph prebuilt: what changed
The legacy langchain react entry point was create_react_agent from langchain.agents, combined with AgentExecutor. The executor worked, but it carried significant surface area: callback chains, output parsers, custom error recovery, and a configuration object that grew over multiple releases. LangChain soft-deprecated AgentExecutor in Q3 2024 and consolidated agentic work around LangGraph.
The replacement is langgraph.prebuilt.create_react_agent, introduced in LangGraph 0.1 (May 2024) and stabilized in LangGraph 0.2 (Q3 2024). The same tool-calling agent now fits in roughly ten lines:
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
from langchain_core.tools import tool
@tool
def search_web(query: str) -> str:
"""Search the web for a query."""
return "results..."
llm = ChatOpenAI(model="gpt-4o-mini")
agent = create_react_agent(llm, tools=[search_web])
result = agent.invoke({"messages": [("user", "What is the current price of palladium?")]})
LangGraph encodes the Thought-Action-Observation loop as a state machine with explicit edges. You can interrupt after any step, inject state, or extend the graph without touching the core cycle. That composability is what AgentExecutor did not offer.
The system prompt that drives every step
Behind every Thought step is a system prompt instructing the model to alternate between reasoning and tool calls. LangGraph's prebuilt agent ships a default prompt, but you can override it via the state_modifier parameter. The bind_tools method attaches tool schemas to the model context, so argument values are derived from Observations rather than generated from prior knowledge.
Enabling LangSmith tracing surfaces this prompt and each step transition. It is worth activating before any production deployment, not after the first incident.
ReAct vs Plan-and-Execute vs direct function calling
Three patterns cover most production agent orchestration use cases. The right choice depends on task structure, latency budget, and per-run cost.
| Pattern | Token overhead | Adaptability | Best fit |
|---|---|---|---|
| ReAct | 300-600 tokens per step | High | Multi-hop tasks with unknown depth |
| Plan-and-Execute | High upfront | Low mid-task | Tasks with stable, pre-enumerable sub-goals |
| Direct function calling | Minimal | None (single turn) | Structured extraction, single-tool lookups |
At GPT-4o-mini input pricing ($0.15 per million tokens, OpenAI Q1 2026), a 6-step agent run consuming 3,000 tokens costs roughly $0.00045. The same run on GPT-4o at $2.50 per million tokens costs $0.0075. Token cost compounds with every step, making model selection the primary cost lever for high-volume reasoning loops.
Plan-and-Execute separates a planning phase from execution. A planning call generates a list of sub-goals; an executor handles each one. Per-step costs drop because execution calls are simpler, but the initial plan is brittle. If the task deviates mid-way, the agent cannot adapt without re-planning. This matters for open-ended tasks where the user's scope is not fully defined at turn zero.
Direct function calling via the OpenAI tools API or Anthropic tool use skips explicit reasoning. One model call selects a function and emits arguments. This is the fastest and cheapest pattern, but it removes the observation loop: using the result of tool A to inform the arguments of tool B requires you to wire that orchestration explicitly.
For general tasks where structure is not known in advance, the adaptive thought-action cycle justifies its overhead. For narrow, single-step extraction tasks, direct function calling is faster and cheaper.
Three failure modes that break the ReAct loop
Infinite loops are the most common production incident. The model never emits a final answer because each Observation prompts another refinement cycle. The mitigation is a hard max_iterations cap. LangGraph's prebuilt agent defaults to 10 iterations; capping at 6 for most production tasks reduces worst-case cost without limiting normal completion paths. A task that genuinely needs more than 6 steps usually signals a decomposition problem, not a loop ceiling problem.
Tool argument hallucination occurs when the model generates parameter values not grounded in any prior Observation. A book_flight call with a date the user never mentioned is the classic example. Strict Pydantic schema validation on tool inputs is the concrete mitigation. When arguments fail validation, the model receives an error as its next Observation and must correct its reasoning rather than propagating bad data silently to downstream tools.
Context blowout is the subtlest of the three. Every iteration appends a full Thought-Action-Observation triple to the conversation context. A 10-step reasoning loop on a 128K-context model can consume 20,000 to 40,000 tokens in scratchpad before the model begins composing its final answer. Rolling context summarization addresses this: at iteration N (typically 4 or 5), replace older Thought-Observation pairs with a compact summary. LangGraph supports this through custom state reducers, and stable community patterns for it have emerged as of early 2026.
Production checklist for LangChain ReAct agents in 2026
Enable LangSmith tracing first. Step-level observability is the only reliable diagnostic artifact when an agent fails in production. Every Thought-Action-Observation triple is logged and searchable by run ID.
Cap max_iterations at 6. The default of 10 fits a demo. For production workloads where you are paying per token, six steps cap worst-case cost at a predictable ceiling without affecting the median successful run.
Choose the model tier deliberately. GPT-4o-mini covers most tool-calling agents where tools return clean, structured data. GPT-4o is worth the cost difference when the agent must synthesize across multiple ambiguous or conflicting Observations.
Use streaming. LangGraph's astream_events API has been stable since LangGraph 0.2 (Q3 2024). As of 2025-2026, all major LLM providers expose streaming tool calls natively, removing the buffering latency that previously made ReAct feel slow to end users. Streaming each Thought and Observation to the client gives users visibility into agent progress without waiting for the full run.
Validate tool inputs with Pydantic. Every tool bound to a langchain react agent should define its argument schema via a Pydantic model. This single change reduces hallucinated tool calls more reliably than any prompt engineering adjustment.
Add retry logic for tool errors. Network timeouts and API rate limits are frequent. A tool that raises an unhandled exception produces an error Observation that often sends the agent into a confused secondary reasoning loop. Wrap tool implementations with exponential backoff before binding them to the agent.
Actually, I think the real reason ReAct persists is simpler: it's the most transparent debugging experience you can get with LLMs today. When your agent breaks (and it will), you want to see exactly where the reasoning went sideways. That visibility is worth the token overhead.
Key takeaways
ReAct's Thought-Action-Observation loop has outlasted several competing agent patterns because it is debuggable, model-agnostic, and adaptive when task depth is unknown at turn zero. The langchain react implementation has migrated cleanly from AgentExecutor to the LangGraph prebuilt API. With the right iteration cap, tool schema validation, and streaming enabled, it remains the correct default for general-purpose agentic workflows in 2026 before graduating to more structured stateful graphs.
ReAct loops still dominate production agents, but infinite loops, tool hallucination, and token bloat kill them fast. The CLI Blueprint in the welcome kit shows how to structure agent tools so they fail safely and compose without scratchpad explosion.