Skip to main content

ReAct Pattern (Reasoning + Acting)

FOR AI AGENTChatGPTClaude

A fundamental algorithmic pattern for autonomous agents that alternates between internal reasoning steps (Thought), executing external tools (Action), and analyzing the resulting output (Observation).

1. Concept Overview & Systemic Problem

Before the introduction of the ReAct concept (published by researchers from Princeton University and Google Research in 2022), there was a divide in the community regarding two approaches to LLM automation:

  1. Chain-of-Thought (Thought-Only): The model writes long chains of reasoning but lacks access to the external world. As a result, the logic of reasoning appears convincing but is based on fabricated facts and outdated data.
  2. Act-Only: The model calls APIs or executes bash commands without intermediate self-analysis. This leads to chaotic repetitions, blind parameter exploration, and an inability to solve even simple multi-step tasks.

The ReAct Pattern (Reasoning + Acting) unifies these two forces into a single iterative cycle: the model first verbalizes its thoughts and plans the next step, then executes the target action, analyzes the actual result from the environment (Observation), and only then makes the next decision.

2. Architectural Taxonomy & Mental Model

The classic step of the ReAct cycle consists of three sequential states:

  • 1. Thought: The agent analyzes the current state of the task, formulates a hypothesis, and articulates a specific intention: “I need to check if the Redis service is running on port 6379 before running tests.” This stage critically reduces the likelihood of errors in tool arguments.
  • 2. Action: The agent formulates a specific action with strict parameters: function name and valid JSON object (e.g., execute_bash(command="systemctl status redis")).
  • 3. Observation: The external runtime intercepts the action, executes it on the server or database, and returns raw text output or an error code back to the agent's context.
  • 4. Finish / Final Answer: When the agent sees in the last Observation that the goal has been achieved, it stops the cycle and formulates the final response to the user.

3. Technical Pipeline & Internal Mechanics

The lifecycle of a ReAct agent in a software environment:

  1. Context & Scratchpad Injection: Interaction rules, descriptions of available tools, and the history of previous iterations of the current session (Scratchpad) are embedded into the system prompt.
  2. Inference with Tool Delimiter: The LLM generates tokens for the Thought section. Once the model reaches the tool call, generation is paused by the client, and the call arguments are validated.
  3. Execution & Observation Feedback: The orchestrator sends the command to the appropriate subsystem (local terminal, database, or browser), reads the output, limits its length for token economy, and adds the message Observation: ... to the context.
  4. Loop Progression & Termination Check: If the agent has achieved its goal or the counter max_iterations = 10 is reached, the cycle is interrupted. Otherwise, the next iteration begins with a new block of Thought.

4. Production Engineering Scenarios

01. Interactive Diagnosis and Repair of Server Infrastructure

  • Thought: The service returns a 502 error. First, I will check the Nginx logs for the last 5 minutes.
  • Action: read_logs(service="nginx", lines=20)
  • Observation: connect() failed (111: Connection refused) while connecting to upstream 127.0.0.1:3000
  • Thought: The upstream on port 3000 has crashed. I need to check the status of the Node.js process via PM2.
  • Action: execute_cmd(command="pm2 status")
  • Observation: app-server: errored (out of memory)
  • Thought: The service crashed due to lack of memory. I will restart it with a larger heap limit.

02. Iterative Search in Documentation and API

The agent attempts to call the external Stripe service. At the first step, it receives an invalid_api_key error. Through the Thought block, the agent recalls that a prefix sk_test_ is required for test mode, retrieves the correct environment variable, and successfully creates a payment intent on the second attempt.

03. Step-by-Step Debugging of Unit Tests

The code agent sees a test failure due to a mismatch in the expected value. It formulates a hypothesis, makes a minimal one-line change, reruns the test, sees a green result, and only then reports task completion.

5. Pitfalls, Common Mistakes & Security

  • Self-Reinforcing Delusion: If the model makes a faulty conclusion at the first step, it tends to interpret all subsequent Observations in favor of its mistake. Solution: mandatory addition of a critique step (Reflection) after 3 consecutive failed actions.
  • Context Bloat from Raw Observations: The command cat huge_file.json returns 50,000 tokens of garbage, pushing out the system prompt. Always limit the size of the returned Observation in runtime (e.g., no more than 2000 characters).
  • Calling Non-Existent Tools (Action Hallucination): The model attempts to call a tool that is not on the list. Solution: use the native API Tool Calling instead of raw text parsing.
/ Frequently Asked QuestionsSchema.org FAQPage

FAQ: ReAct Pattern (Reasoning + Acting)

Pure reasoning (Chain-of-Thought) suffers from a lack of connection to reality: the model operates on outdated data and hallucinates facts. Pure action (Act-only) operates blindly through chaotic trial and error. ReAct allows the model to first justify its action in thoughts, execute it in the external world, and adjust its worldview based on the actual result (Grounding).
/ Internal links
All terms

Related Ecosystem Resources

Explore practical workflows, core terminology, and engineering tools

Glossary Concept

Zero-Shot CoT vs Dynamic Reasoning

The historical and practical evolution of reasoning techniques: from the simple phrase 'Let's think step by step' (Zero-Shot Chain-of-Thought) to native computational budgeting of reasoning in modern models.

Practical Guide

OpenGlass UI: Complete Guide to the Liquid Glass React Library

Architecture and integration guide for OpenGlass UI: 40 native components, CSS, SVG SDF, and WebGL2 renderers, token systems, Next.js SSR, and WCAG 2.2.

Practical Guide

How to Write and Test SKILL.md Patterns: The Complete Engineering Guide

A professional engineering guide to developing AI agent skills: four mandatory sections of SKILL.md, Codex and Claude Code synchronization, composition patterns, 5 essential tests, and regression prevention.

Glossary Concept

Agentic Loop: Steps of Thought ➔ Action ➔ Observation (ReAct)

A fundamental algorithmic pattern for autonomous agents, known as ReAct: Reasoning + Acting, consisting of an infinite cycle of three steps: 1) Thought — situation analysis; 2) Action — tool invocation; 3) Observation — result analysis and plan adjustment.

News

ultrathink returns to Claude Code CLI

Claude Code has brought back the ultrathink command, allowing users to increase reasoning depth during the current turn when a task turns out to be more complex than expected.

News

Claude Code cuts background subagent status update costs by 99%

In the CLI version of Claude Code, status updates for background subagents now use Haiku 5.5 based on short notes, reducing limit consumption.