promptingadvanced

ReAct Pattern: Reasoning + Acting with LLMs (2026)

Quick Answer

ReAct prompts a model to alternate between Thought (reasoning about what to do), Action (calling a tool), and Observation (incorporating the tool result) until the task is complete. This loop lets LLMs solve tasks requiring multiple external lookups while maintaining reasoning coherence. ReAct outperforms chain-of-thought alone on tool-use tasks because observations ground the reasoning in real data.

When to Use

  • Multi-step tasks that require calling external APIs, databases, or search engines to gather information
  • Research tasks where the model needs to explore different sources and synthesize findings
  • Debugging agents when you need to see the model's reasoning at each step
  • Tasks with uncertain information needs — when you don't know upfront which tools will be needed
  • Building explainable AI systems where you need an audit trail of how the model reached its answer

How It Works

  1. 1Structure the prompt with a Thought/Action/Observation pattern. The model generates a Thought (reasoning), then specifies an Action (tool call with parameters), then receives an Observation (tool result) — all appended to the context.
  2. 2Define available tools clearly in the system prompt: tool name, description, input schema, and example usage. The model selects tools by name in the Action step.
  3. 3Parse the model's Action output to extract tool name and arguments, execute the tool, and append the Observation to the context. Repeat until the model generates a Final Answer.
  4. 4Implement a max_iterations guard (typically 10–20 steps) to prevent infinite loops. If the agent exceeds the limit, return a graceful failure message.
  5. 5For production, use structured outputs for Action steps (JSON with tool_name and arguments fields) rather than free-text parsing — it's more reliable and easier to route.

Examples

Research agent with ReAct trace
You are a research assistant with access to [search(query), fetch_page(url), calculator(expr)].

Question: What is the market cap of the largest AI chip company as of April 2026?

Thought: I need to find which company is the largest AI chip company and its current market cap.
Action: search(query='largest AI chip company market cap April 2026')
Observation: Nvidia remains the dominant AI chip company with a market cap of approximately $3.2T as of April 2026.
Thought: I have the answer from the search result.
Final Answer: Nvidia is the largest AI chip company with a market cap of approximately $3.2 trillion as of April 2026.
Output:The ReAct trace shows: 1 thought, 1 tool call, 1 observation, 1 final answer. For complex queries this pattern extends to 5-15 steps.
Multi-step data lookup
Available tools: get_user(id), get_orders(user_id), calculate_ltv(orders)

Task: What is the LTV for user 12345?

Thought: I need user 12345's data, then their orders, then calculate LTV.
Action: get_user(id=12345)
Observation: {name: 'Alice Chen', joined: '2023-01-15', plan: 'pro'}
Thought: Got user. Now get orders.
Action: get_orders(user_id=12345)
Observation: [{date: '2024-01', amount: 299}, {date: '2024-07', amount: 299}, {date: '2025-01', amount: 499}]
Thought: 3 orders totaling $1,097. Calculate LTV.
Action: calculate_ltv(orders=[299, 299, 499])
Observation: LTV: $1,097, projected_annual: $549
Final Answer: User 12345 (Alice Chen) has a lifetime value of $1,097 with projected annual value of $549.
Output:4-step ReAct trace completing a multi-hop data lookup. Each observation updates the model's world state before the next action.

Common Mistakes

  • Not limiting iterations — ReAct agents can loop indefinitely if a tool call fails silently or returns unexpected output. Always implement a step counter and fail gracefully.
  • Verbose tool descriptions that exceed the context budget — if you have 20 tools, their descriptions can consume 4K+ tokens. Use short descriptions and provide full schemas only for the most-called tools.
  • Parsing free-text actions unreliably — regex parsing of 'Action: tool_name(args)' breaks on edge cases. Use structured outputs (JSON) for action steps from the start.
  • No error handling in observations — when a tool fails, the agent must receive a meaningful error observation (not a Python traceback) and have instructions for how to recover or skip.

FAQ

What's the difference between ReAct and function calling?+

Function calling (OpenAI, Anthropic tool_use) is a structured implementation of the Action step — the model returns a JSON tool call rather than free text. ReAct is the reasoning pattern (Thought/Action/Observation loop) that orchestrates multiple function calls. Modern agents use function calling to implement the Action step of ReAct.

How does ReAct compare to plain tool use?+

Plain tool use (single-turn function calling) handles one-shot tool calls. ReAct handles multi-step tasks where the result of one tool call informs the next. ReAct is strictly more capable but more expensive — use plain tool use for simple lookups, ReAct for research or multi-step workflows.

Does ReAct work with all LLMs?+

ReAct requires models that can follow instruction patterns reliably. GPT-4o, Claude 3.5+, and Gemini 1.5+ all work well. Smaller models (7B–13B) can follow ReAct with good few-shot examples but are less reliable on tool argument formatting. Models under 7B typically fail at multi-step ReAct.

How do I debug a ReAct agent that's looping?+

Add a thought_count to each observation. Log the full Thought/Action/Observation trace. Common causes: tool returning empty results causing the model to retry, ambiguous task that the model can't determine is complete, or missing a 'stop condition' instruction telling the model when it has enough information to answer.

Is ReAct still relevant with reasoning models (o3, Claude 3.7)?+

Yes, reasoning models benefit from ReAct too — the internal reasoning they perform is complementary to external tool calls. Reasoning models produce better Thought steps and are more reliable at knowing when they have enough information to stop. The main change is that you can often reduce explicit ReAct prompting and let the model's reasoning guide tool selection.

Related