Interactive AI Lesson• 2 min
From Chatbots to Autonomous Agents: The ReAct Pattern
Understanding the iterative Thought -> Action -> Observation cycle.
Live — computed in your browser
Yesz=4.284.3%
Noz=2.110.3%
Maybez=1.03.4%
Perhapsz=0.41.9%
Anatomy of an Autonomous AI Agent
Traditional chatbots respond in a single turn. An Autonomous AI Agent, in contrast, operates in an active feedback loop with its environment.
The ReAct (Reasoning + Acting) Cycle
- Thought (Reasoning): The agent analyzes current goals and history to form a mental model of the next step.
- Action (Execution): The agent chooses an available tool (e.g. ,Code Block
search_database,Code Blockrun_python_code) and specifies precise arguments.Code Blockfetch_weather - Observation (Environment Feedback): The system executes the tool and injects the raw output back into the conversation context.
- Reflection & Decision: The agent reads the observation. If the goal is satisfied, it delivers the final answer; otherwise, it iterates back to step 1.
Example — python
class SimpleReActAgent:
def __init__(self, model_client, tools: dict):
self.client = model_client
self.tools = tools
self.history = []
def run(self, user_goal: str, max_steps: int = 5):
self.history.append({"role": "user", "content": user_goal})
for step in range(max_steps):
response = self.client.generate(self.history)
if response.tool_calls:
for tool_call in response.tool_calls:
fn_name = tool_call.name
args = tool_call.arguments
print(f"Step {step+1}: Calling {fn_name}({args})")
# Execute tool in isolated environment
result = self.tools[fn_name](**args)
# Feed observation back into context
self.history.append({
"role": "tool",
"tool_call_id": tool_call.id,
"content": str(result)
})
else:
# Agent satisfied goal
return response.text
return "Max iterations reached without resolution."Knowledge Checkpoint
In the ReAct pattern, what is the role of the "Observation" step?
Read to the end of the lesson