Home Knowledge Base ReAct: Reasoning and Acting

ReAct: Reasoning and Acting

What is ReAct? ReAct (Reasoning and Acting) is an agent framework that interleaves reasoning traces with tool-use actions, enabling more reliable and interpretable problem-solving.

The ReAct Loop

Question: What is the population of the capital of France?

Thought 1: I need to find the capital of France first.
Action 1: search("capital of France")
Observation 1: Paris is the capital of France.

Thought 2: Now I need to find the population of Paris.
Action 2: search("Paris population")
Observation 2: Paris has approximately 2.1 million people in the city proper.

Thought 3: I now have the answer.
Answer: The population of Paris, the capital of France, is approximately 2.1 million.

Key Components

Reasoning (Thought)

Acting (Action)

Observing

Implementation

def react_agent(question: str, tools: dict) -> str:
    prompt = f"Question: {question}

"

    while True:
        response = llm.generate(prompt + "Thought:")
        thought = parse_thought(response)
        prompt += f"Thought: {thought}
"

        if "Answer:" in thought:
            return thought.split("Answer:")[-1]

        action = parse_action(response)
        prompt += f"Action: {action}
"

        observation = tools[action.tool](action.args)
        prompt += f"Observation: {observation}

"

ReAct vs Other Approaches

ApproachReasoningActingTrace
Standard promptingImplicitNoNo
Chain-of-ThoughtExplicitNoYes
Tool use onlyNoYesNo
ReActExplicitYesYes

Benefits

Available in Frameworks

reactreason actagent loop

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.