Building Autonomous AI Agents · Module 1 · The ReAct Loop & Tool Calling
Thought, Action, and Observation
7 min read · lesson 1 of 6
A standard LLM call is single-shot: input in, output out. An autonomous agent, however, runs in an iterative loop known as ReAct (Reasoning + Acting). At every turn, the agent thinks about what it needs, selects an action (such as executing a tool or querying a database), and waits for the environment's observation before deciding the next step.
The Three Phases of ReAct
- Thought: The model explicitly articulates its current state and reasoning (e.g. 'I need the user's order history before calculating their discount tier').
- Action: The model outputs a structured tool invocation with exact arguments (e.g. `getUserOrders({ userId: 'u_102' })`).
- Observation: Your runtime executes the tool and injects the actual result back into the prompt history as system/tool feedback.
type AgentStep =
| { type: 'thought'; reasoning: string }
| { type: 'action'; tool: string; args: Record<string, unknown> }
| { type: 'observation'; output: unknown }
| { type: 'finish'; response: string };Always force the model to emit its thought before its action. Asking the model to reason first primes its autoregressive attention weights, dramatically reducing erroneous tool parameters.
Practice
Map out a 3-step ReAct sequence for an agent that checks weather in Paris and drafts an outfit recommendation.