The ReAct pattern helps AI think step-by-step and take actions to solve problems better. It mixes reasoning with doing, like how we think and then act.
ReAct pattern (Reasoning + Acting) in Agentic AI
Start learning this pattern below
Jump into concepts and practice - no test required
Thought: <reasoning about the problem> Action: <an action to take> Observation: <result from the action> ... (repeat Thought, Action, Observation as needed) Final Answer: <the answer or decision>
The pattern alternates between Thought (reasoning) and Action (doing something).
Observation records what happened after the action, helping the AI learn and decide next steps.
Thought: I need to find the capital of France. Action: Search('capital of France') Observation: Paris Final Answer: The capital of France is Paris.
Thought: I want to know today's weather. Action: CallWeatherAPI('today') Observation: Sunny, 25°C Final Answer: Today's weather is sunny and 25 degrees Celsius.
This simple program shows the ReAct pattern. The agent thinks about the question, acts by searching, observes the result, and then gives the final answer.
class ReActAgent: def __init__(self): self.knowledge = {} def think(self, question): print(f"Thought: I need to answer '{question}'") if 'capital' in question.lower(): print("Action: Search('capital of France')") observation = 'Paris' print(f"Observation: {observation}") print(f"Final Answer: The capital of France is {observation}.") else: print("Action: No action available") print("Observation: None") print("Final Answer: Sorry, I don't know.") agent = ReActAgent() agent.think('What is the capital of France?')
The ReAct pattern helps AI explain its steps, making it easier to trust and improve.
It works well when AI can use tools or APIs to get information.
Each cycle of Thought, Action, Observation helps the AI refine its answer.
The ReAct pattern mixes thinking and doing for better AI problem solving.
It uses clear steps: Thought, Action, Observation, and Final Answer.
This pattern helps AI explain its reasoning and use tools effectively.
Practice
Solution
Step 1: Understand the ReAct pattern components
The ReAct pattern mixes reasoning (thought) and acting (actions) to solve problems step-by-step.Step 2: Identify the main goal
Its goal is to help AI explain its reasoning clearly while using tools effectively.Final Answer:
To combine reasoning steps with actions for clearer problem solving -> Option CQuick Check:
ReAct = Reasoning + Acting [OK]
- Confusing ReAct with data storage methods
- Thinking it speeds up training only
- Believing it replaces humans fully
Solution
Step 1: Recall the ReAct step order
The ReAct pattern follows Thought (reasoning), then Action (doing), then Observation (seeing results), and finally Final Answer.Step 2: Match the correct sequence
Thought -> Action -> Observation -> Final Answer matches this exact order.Final Answer:
Thought -> Action -> Observation -> Final Answer -> Option BQuick Check:
Step order = Thought, Action, Observation, Final Answer [OK]
- Swapping Action and Thought order
- Placing Final Answer too early
- Confusing Observation with Action
thought = "Check if number is even" action = "Divide number by 2" observation = 4 / 2 final_answer = "Number is even" if observation == 2 else "Number is odd" print(final_answer)
Solution
Step 1: Evaluate the action and observation
The action divides 4 by 2, resulting in observation = 2.Step 2: Determine the final answer based on observation
Since observation == 2, the final answer is "Number is even".Final Answer:
Number is even -> Option DQuick Check:
4 / 2 = 2 -> even number [OK]
- Confusing observation value with input number
- Assuming division error
- Ignoring the if-else condition
thought = "Find square root" action = "Calculate sqrt of 16" observation = sqrt(16) final_answer = "Square root is " + observation print(final_answer)
Solution
Step 1: Check usage of sqrt function
The code uses sqrt(16) but does not import sqrt from math module.Step 2: Identify missing import causing error
Without 'from math import sqrt', this will cause a NameError.Final Answer:
Missing import for sqrt function -> Option AQuick Check:
sqrt needs import from math [OK]
- Assuming string concatenation error
- Thinking variable names are wrong
- Believing code runs without imports
Solution
Step 1: Understand prime checking logic
To check if 15 is prime, test divisibility by numbers from 2 up to 14.Step 2: Follow ReAct steps correctly
The agent thinks about divisibility, acts by testing 3, observes 15 is divisible, then concludes not prime.Final Answer:
Thought: Check divisibility from 2 to 14 -> Action: Test divisibility by 3 -> Observation: 15 divisible by 3 -> Final Answer: Not prime -> Option AQuick Check:
Divisible by 3 means not prime [OK]
- Only checking even divisibility
- Guessing without testing
- Ignoring observations in reasoning
