> ## Documentation Index
> Fetch the complete documentation index at: https://docs-v1.latitude.so/llms.txt
> Use this file to discover all available pages before exploring further.

# ReAct (Reasoning and Acting) Prompting

> Learn how to combine reasoning and acting in a thought-action loop to solve complex tasks using external tools

## What is ReAct Prompting?

ReAct (Reasoning and Acting) prompting is a paradigm that enables AI models to solve complex tasks by combining natural language reasoning with external tool interactions. It mimics human problem-solving by creating a thought-action loop where the model reasons about the problem, takes actions to gather information, observes results, and iteratively refines its approach until reaching a solution.

## Why Use ReAct Prompting?

* **Complex Problem Solving**: Handles multi-step tasks requiring external information
* **Dynamic Information Access**: Retrieves real-time data through tool interactions
* **Human-like Reasoning**: Mirrors how humans think and act to solve problems
* **Iterative Improvement**: Learns from action results to refine strategies
* **Tool Integration**: Seamlessly combines reasoning with external capabilities
* **Transparent Process**: Shows the thinking and action steps for explainability
* **Agent-like Behavior**: First step towards autonomous agent modeling

## How ReAct Prompting Works

ReAct operates through a continuous thought-action loop:

1. **Thought**: The model reasons about the current state and plans next actions
2. **Action**: The model executes tools or queries to gather information
3. **Observation**: The model processes the results from actions
4. **Iteration**: The cycle repeats with updated understanding until goal completion

This process requires careful prompt management, including maintaining conversation history and trimming excessive content to stay within context limits.

## Basic Implementation in Latitude

Here's a simple ReAct example using Latitude's built-in tools:

<CodeGroup>
  ```markdown Basic ReAct Research theme={null}
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.1
  tools:
    - latitude/search
    - latitude/extract
  ---

  # Research Assistant with ReAct

  I will help you research {{ research_topic }} using a systematic thought-action approach.

  ## Instructions:
  Follow this ReAct pattern:
  1. **Thought**: Reason about what information you need
  2. **Action**: Use tools to gather that information
  3. **Observation**: Analyze the results
  4. **Thought**: Plan your next step based on what you learned
  5. Repeat until you have comprehensive information

  Let me start researching {{ research_topic }}:

  **Thought**: I need to understand the current state and recent developments in {{ research_topic }}. Let me start with a broad search to get an overview.

  **Action**: I'll search for recent information about {{ research_topic }}.
  ```
</CodeGroup>

## Advanced ReAct Implementation

For more complex tasks, create structured ReAct workflows:

<CodeGroup>
  ```markdown Advanced ReAct Analysis theme={null}
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.2
  tools:
    - latitude/search
    - latitude/extract
    - latitude/code
  ---

  <step>
  # ReAct Problem Solving Framework

  I'm tasked with: {{ complex_task }}

  ## Initial Assessment:
  **Thought**: Let me break down this complex task and identify what information and actions I need to complete it successfully.

  1. **Problem Analysis**: What are the key components of this task?
  2. **Information Requirements**: What data do I need to gather?
  3. **Tool Strategy**: Which tools will be most effective?
  4. **Success Criteria**: How will I know when the task is complete?

  Let me begin the ReAct process:
  </step>

  <step>
  # ReAct Execution Cycle

  Previous context: {{ initial_assessment }}

  ## Thought-Action Loop:

  **Thought 1**: Based on my analysis, I need to start by {{ first_reasoning_step }}

  **Action 1**: [Execute first action using appropriate tools]

  **Observation 1**: [Process and analyze results]

  **Thought 2**: Given these results, my next step should be {{ next_reasoning_step }}

  **Action 2**: [Execute second action]

  **Observation 2**: [Analyze new information]

  Continue this pattern until task completion...
  </step>

  <step>
  # Synthesis and Conclusion

  Previous ReAct cycles: {{ execution_cycles }}

  ## Final Synthesis:
  **Thought**: Now I need to synthesize all the information I've gathered and provide a comprehensive response.

  **Final Analysis**: [Combine all observations and reasoning]

  **Conclusion**: [Present final results and recommendations]

  **Reflection**: [Evaluate the effectiveness of the ReAct process]
  </step>
  ```
</CodeGroup>

## Domain-Specific ReAct Applications

### Market Research ReAct

<CodeGroup>
  ```markdown Market Research ReAct theme={null}
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.3
  tools:
    - latitude/search
    - latitude/extract
    - latitude/code
  ---

  # Market Research Agent

  Research market opportunity for: {{ product_concept }}

  ## ReAct Research Process:

  **Thought**: To assess this market opportunity, I need to gather data on market size, competition, trends, and customer needs. Let me start systematically.

  **Action**: Search for market size and growth data for {{ product_concept }}

  [Tool will execute search]

  **Observation**: [Analyze market size data]

  **Thought**: Now I need competitive intelligence. Who are the key players and what gaps exist?

  **Action**: Search for competitors and competitive analysis in {{ market_segment }}

  [Continue ReAct cycle through:]
  - Market trends analysis
  - Customer pain points research
  - Regulatory considerations
  - Technology landscape assessment

  **Final Market Assessment**: [Synthesized conclusion]
  ```
</CodeGroup>

### Technical Problem Solving ReAct

<CodeGroup>
  ```markdown Technical ReAct Debugging theme={null}
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.1
  tools:
    - latitude/search
    - latitude/code
    - latitude/extract
  ---

  # Technical Debugging Assistant

  Debug and solve: {{ technical_problem }}

  ## ReAct Debugging Process:

  **Thought**: I need to understand this technical issue systematically. Let me gather information about the error, check documentation, and test potential solutions.

  **Action**: Search for common causes and solutions for {{ error_type }}

  **Observation**: [Analyze search results for patterns]

  **Thought**: Based on these patterns, let me examine the specific technical details and run some diagnostic code.

  **Action**: Execute diagnostic code to analyze {{ system_component }}

  **Observation**: [Review diagnostic results]

  **Thought**: The diagnostics suggest {{ hypothesis }}. Let me verify this with additional research and testing.

  [Continue ReAct cycle through:]
  - Documentation research
  - Code analysis
  - Solution testing
  - Validation steps

  **Solution**: [Present debugged solution with reasoning]
  ```
</CodeGroup>

### Content Creation ReAct

<CodeGroup>
  ```markdown Content ReAct Strategy theme={null}
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.4
  tools:
    - latitude/search
    - latitude/extract
  ---

  # Strategic Content Creator

  Create content strategy for: {{ content_topic }}

  ## ReAct Content Development:

  **Thought**: To create effective content, I need to understand the audience, analyze successful content in this space, and identify unique angles.

  **Action**: Research trending content and successful approaches for {{ content_topic }}

  **Observation**: [Analyze content trends and engagement patterns]

  **Thought**: Now I need to understand the target audience better and identify content gaps.

  **Action**: Search for audience demographics and content preferences in {{ target_market }}

  **Observation**: [Review audience insights]

  **Thought**: With this audience data, let me identify unique angles and content opportunities.

  [Continue ReAct cycle through:]
  - Competitive content analysis
  - SEO and keyword research
  - Platform-specific optimization
  - Content format testing

  **Content Strategy**: [Present comprehensive strategy]
  ```
</CodeGroup>

## Best Practices for ReAct Prompting

<AccordionGroup>
  <Accordion title="Thought-Action Structure">
    **Clear Pattern Establishment**:

    * Always label thoughts, actions, and observations explicitly
    * Maintain consistent format throughout the conversation
    * Ensure each thought logically leads to the next action
    * Make observations comprehensive and actionable

    **Reasoning Quality**:

    * Encourage detailed reasoning in thought phases
    * Connect new information to previous observations
    * Show how each action builds toward the goal
    * Maintain logical flow between iterations
  </Accordion>

  <Accordion title="Tool Integration">
    **Effective Tool Usage**:

    * Choose appropriate tools for each information need
    * Combine multiple tools when necessary
    * Use tool results to inform subsequent actions
    * Validate information across multiple sources

    **Tool Strategy**:

    * Start with broad searches, then narrow focus
    * Use extraction tools for detailed analysis
    * Employ code tools for calculations and data processing
    * Chain tool calls for complex workflows
  </Accordion>

  <Accordion title="Context Management">
    **Conversation History**:

    * Maintain relevant context from previous cycles
    * Trim excessive detail while preserving key insights
    * Reference previous observations in new reasoning
    * Build cumulative understanding over iterations

    **Memory Optimization**:

    * Summarize key findings periodically
    * Remove redundant information to save tokens
    * Prioritize recent and relevant context
    * Use step-based approaches for complex tasks
  </Accordion>

  <Accordion title="Quality Control">
    **Validation Techniques**:

    * Cross-verify information from multiple sources
    * Test hypotheses through targeted actions
    * Evaluate solution effectiveness before concluding
    * Maintain skeptical reasoning throughout

    **Error Handling**:

    * Acknowledge when tools return unexpected results
    * Adjust strategy based on failed actions
    * Seek alternative information sources
    * Document limitations and assumptions
  </Accordion>
</AccordionGroup>

## Advanced ReAct Techniques

### Multi-Agent ReAct

Coordinate multiple specialized agents in ReAct loops:

<CodeGroup>
  ```markdown Multi-Agent ReAct theme={null}
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.3
  tools:
    - latitude/search
    - latitude/extract
    - latitude/code
  type: agent
  agents:
    - agents/researcher
    - agents/analyst
    - agents/strategist
  ---

  # Multi-Agent ReAct Coordination

  Task: {{ complex_multi_faceted_task }}

  ## Coordinated ReAct Process:

  **Coordination Thought**: This task requires multiple specialized perspectives. Let me coordinate researcher, analyst, and strategist agents in a ReAct workflow.

  **Action**: Initiate research phase with specialist agents

  [Agents execute their ReAct cycles]

  **Observation**: Synthesize findings from all agent perspectives

  **Coordination Thought**: Based on multi-agent insights, determine next coordinated actions

  [Continue coordinated ReAct cycles]

  **Final Synthesis**: Integrate all agent findings into comprehensive solution
  ```
</CodeGroup>

### Hierarchical ReAct

Structure ReAct with multiple levels of planning:

<CodeGroup>
  ```markdown Hierarchical ReAct theme={null}
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.2
  tools:
    - latitude/search
    - latitude/extract
    - latitude/code
  ---

  <step as="strategic_plan">
  # Strategic ReAct Planning

  High-level task: {{ strategic_objective }}

  **Strategic Thought**: I need to break this into manageable sub-goals and plan a hierarchical approach.

  ## Strategic Planning:
  1. **Goal Decomposition**: Break into sub-objectives
  2. **Priority Setting**: Determine order of operations
  3. **Resource Planning**: Identify tool and information needs
  4. **Success Metrics**: Define completion criteria

  **Strategic Action**: Define detailed execution plan
  </step>

  <step as="tactical_results">
  # Tactical ReAct Execution

  Strategic plan: {{ strategic_plan }}

  ## Tactical ReAct Cycles:

  For each sub-objective:
  **Tactical Thought**: [Specific reasoning for this sub-goal]
  **Tactical Action**: [Focused tool usage]
  **Tactical Observation**: [Sub-goal specific analysis]

  [Repeat for each tactical objective]
  </step>

  <step>
  # Operational ReAct Implementation

  Tactical progress: {{ tactical_results }}

  ## Operational Actions:

  **Operational Thought**: Now execute specific implementation steps
  **Operational Action**: [Detailed implementation]
  **Operational Observation**: [Immediate results]

  [Rapid operational cycles]

  **Integration**: Combine operational results with tactical and strategic levels
  </step>
  ```
</CodeGroup>

### Self-Correcting ReAct

Implement error detection and correction in ReAct loops:

<CodeGroup>
  ```markdown Self-Correcting ReAct theme={null}
  ---
  provider: OpenAI
  model: gpt-4o
  temperature: 0.3
  tools:
    - latitude/search
    - latitude/extract
    - latitude/code
  ---

  # Self-Correcting ReAct System

  ## Enhanced ReAct with Error Detection:

  **Thought**: [Standard reasoning]
  **Action**: [Tool execution]
  **Observation**: [Standard result analysis]

  **Validation Thought**: Let me check if this information seems accurate and complete
  **Validation Action**: Cross-reference with additional sources
  **Validation Observation**: [Quality assessment]

  **Correction Thought**: [If errors detected] I need to correct my approach because [reasoning]
  **Correction Action**: [Alternative approach]
  **Correction Observation**: [Verified results]

  **Meta-Thought**: Evaluate the effectiveness of my ReAct process and adjust if needed

  [Continue with improved approach]
  ```
</CodeGroup>

## Integration with Other Techniques

ReAct prompting combines effectively with other approaches:

* **Chain-of-Thought + ReAct**: Detailed reasoning within each thought phase
* **Self-Consistency + ReAct**: Multiple ReAct cycles to verify solutions
* **Step-Back + ReAct**: Establish principles before action planning
* **Few-Shot + ReAct**: Provide examples of effective thought-action patterns

## Common Patterns and Templates

### The "Investigation" Pattern

* Thought: Identify information gaps
* Action: Gather specific data
* Observation: Analyze findings
* Repeat: Drill deeper or pivot based on results

### The "Problem-Solving" Pattern

* Thought: Hypothesize solutions
* Action: Test hypotheses with tools
* Observation: Evaluate effectiveness
* Iterate: Refine approach based on results

### The "Synthesis" Pattern

* Thought: Plan comprehensive analysis
* Action: Gather diverse information sources
* Observation: Compare and contrast findings
* Conclude: Synthesize insights into coherent solution

ReAct prompting transforms AI from passive responders to active problem-solvers, enabling complex task completion through iterative reasoning and tool-assisted action cycles.
