The ReAct pattern helps AI agents by letting them think (reason) about the situation and then act based on that reasoning. This back-and-forth improves their ability to handle complex tasks effectively.
class SimpleReActAgent: def __init__(self): self.state = 0 def reason(self): return f"Reasoning with state {self.state}" def act(self): self.state += 1 return f"Acting to change state to {self.state}" def step(self): thought = self.reason() action = self.act() print(thought) print(action) agent = SimpleReActAgent() agent.step()
The agent first reasons with the current state (0), then acts to increase the state to 1, printing both messages in order.
The ReAct pattern requires a model that can produce reasoning and actions in sequence, which large language models are designed to do. Other models lack this capability.
Task success rate directly measures how often the agent completes the entire multi-step task correctly, which is the goal of ReAct agents.
If the agent never calls the act() method after reasoning, it will keep reasoning forever without acting, causing an infinite loop.