ReAct Pattern: Overview
What is ReAct?
Section titled âWhat is ReAct?âReAct (Reasoning + Acting) is the simplest AI agent architecture. The agent alternates between reasoning about what to do next, taking an action, and observing the result.
The name âReActâ combines:
- Reasoning: The model thinks about what to do
- Acting: The model executes a tool or completes the task
Core Concept
Section titled âCore Conceptâgraph LR A[User Request] --> B[Reasoning] B --> C{Decision} C -->|Use Tool| D[Action] C -->|Task Complete| E[Final Answer] D --> F[Observation] F --> BControl Flow
Section titled âControl FlowâThe ReAct pattern follows a simple loop:
sequenceDiagram participant User participant Agent participant Tools
User->>Agent: Initial request
loop Until task complete Agent->>Agent: Reason about next action
alt Use a tool Agent->>Tools: Execute tool Tools-->>Agent: Tool result Agent->>Agent: Observe result else Task complete Agent->>User: Final answer end endArchitecture Diagram
Section titled âArchitecture Diagramâgraph TB subgraph AppLayer["Application Layer"] App[Control Loop] end
subgraph AgentLayer["Agent Layer"] LLM[LLM] Memory[Conversation History] end
subgraph ToolLayer["Tool Layer"] T1[Read File] T2[Write File] T3[Execute Code] T4[Search] end
App --> LLM LLM --> App App --> T1 App --> T2 App --> T3 App --> T4 T1 --> Memory T2 --> Memory T3 --> Memory T4 --> Memory Memory --> LLMExample: Legal Document Review
Section titled âExample: Legal Document ReviewâHereâs how ReAct handles a legal document review task:
graph LR Start[Start Task] --> Reasoning[Reasoning] Reasoning --> Action[Action] Action --> Observe[Observe] Observe --> Decision{Task<br/>Complete?} Decision -->|No| Reasoning Decision -->|Yes| End[Complete]Key Characteristics
Section titled âKey Characteristicsââ Strengths
Section titled ââ Strengthsâ- Simple: Easy to understand and implement (~200-400 lines)
- Transparent: Clear reasoning at each step
- Debuggable: Can trace exactly what the agent did and why
- Flexible: Works with any LLM that supports tool calling
â ď¸ Limitations
Section titled ââ ď¸ Limitationsâ- No Quality Checks: Agent doesnât verify its own work
- Can Loop: May get stuck repeating actions
- No Planning: Decides one step at a time
- Error Prone: No recovery mechanism
When to Use ReAct
Section titled âWhen to Use ReActâ| â Use ReAct When⌠| â Avoid ReAct When⌠|
|---|---|
| Building prototypes or MVPs | Production systems need reliability |
| Learning agent fundamentals | Complex multi-step workflows |
| Simple, linear tasks (3-5 steps) | Quality assurance required |
| Small tool sets (< 10 tools) | Error recovery is critical |
| Fast iteration needed | Compliance/audit trails needed |
Message Flow Example
Section titled âMessage Flow ExampleâHereâs what the conversation looks like:
sequenceDiagram autonumber participant User participant Agent participant Tools
User->>Agent: Review contract.pdf Note over Agent: Need to read file first Agent->>Tools: read_file Tools-->>Agent: Contract contents Note over Agent: Found missing clause Agent->>Tools: write_file FINDINGS Tools-->>Agent: File written Note over Agent: Task complete Agent->>User: Review completeComparison with Plan-Execute-Verify
Section titled âComparison with Plan-Execute-Verifyâgraph TB subgraph Simple["ReAct Simple"] R1[Reason] --> A1[Act] A1 --> O1[Observe] O1 --> R1 end
subgraph Robust["Plan-Execute-Verify"] P[Plan] --> E[Execute] E --> V[Verify] V -->|Pass| Next[Next Step] V -->|Fail| Retry[Retry] Retry --> E Next --> E endKey Difference: ReAct is a single loop, while Plan-Execute-Verify separates planning, execution, and verification into distinct phases.
Best For
Section titled âBest Forâ- Learning: Perfect for understanding agent concepts
- Prototyping: Quick to build and iterate
- Simple Tasks: 3-5 steps, clear requirements
- Demos: Easy to explain and visualize
Implementation Options
Section titled âImplementation OptionsâContinue to one of the implementation guides:
- Claude SDK Implementation - Direct API integration (most control)
- Model Agnostic Design - Support multiple LLM providers
- LangChain Implementation - Using LangChain framework (fastest development)
Next Steps
Section titled âNext Stepsâ- New to agents? â Start with Claude SDK Implementation
- Need flexibility? â Read Model Agnostic Design
- Want speed? â Try LangChain Implementation
- Ready for production? â Explore Plan-Execute-Verify Pattern