Model analyzes the current state
AI Models & Assistants / Knowledge library
ReAct: Reasoning and Acting Agents
Agents that alternate reasoning, tool actions, and observations
Why learn ReAct: Reasoning and Acting Agents?
Useful for tasks where intermediate observations determine the next action. Tool results, stopping conditions, and action permissions remain application responsibilities.
The problem it solves
Lets a language agent adjust its plan using external observations during a task.
Where it came from
ReAct interleaves language-model reasoning with actions and observations from an environment. An agent can revise its next step after a search result or other tool response. This agent pattern is distinct from the React user-interface library.
Build your understanding
Work through these exercises in order. Try the task before opening a reference.
- Sketch a lookup task as alternating actions and observations.
- Build a mock search tool that returns a fixed set of facts.
- Show how an empty search result should change the next action.
- Set a maximum number of steps and handle repeated tool calls.
- Evaluate final answers against the facts returned by the mock tool.
Documentation and sources
- ReAct research paper (arxiv.org)
- Google Research explanation of ReAct (research.google)
Connect the ideas
Explore next
Real World Example
Automated Logistics Compliance Auditor
Global logistics firms managing complex, multi-jurisdictional shipping regulations.
The business problem
Manual compliance checks are prone to error and slow, as agents often fail to synthesize dynamic regulatory updates with specific shipment manifests, leading to costly delays.
How this topic solves it
The ReAct framework enables agents to interleave reasoning traces with tool-based actions, allowing the system to query live regulatory databases and verify shipment data against those findings in a single, transparent workflow.
- Define the agent prompt structure to enforce a Thought-Action-Observation loop.
- Connect the agent to a secure, read-only API for real-time customs regulation lookups.
- Implement a reasoning module that decomposes complex compliance queries into sequential sub-tasks.
- Configure the observation parser to feed external API results back into the agent's context window.
- Establish a final response generation step that summarizes the reasoning path for human auditability.
The agent cycles through reasoning and acting until the compliance task is resolved.
Model selects a tool to call
External API fetches data
Result is fed back to model
- Reasoning Trace → determines → Action Generation
- Action Generation → triggers → Tool Execution
- Tool Execution → returns → Observation
- Observation → updates context → Reasoning Trace
Implementation example
This snippet illustrates the core ReAct loop where the model generates a thought, selects an action, and receives an observation to inform the next reasoning step.
def react_step(query):
thought = model.generate(f'Thought: {query}') # Reasoning trace
action = model.generate(f'Action: {thought}') # Tool selection
observation = api.call(action) # External data retrieval
return f'Observation: {observation}' # Feedback loopExpected business outcome
Improved accuracy in compliance verification and increased transparency, as human auditors can review the step-by-step reasoning trace that led to a specific shipping clearance decision.
Limitations and checks
The agent may enter infinite loops if the observation data is ambiguous or contradictory; check for this by monitoring the length of the reasoning trace and setting a maximum step threshold.