# Guide to Implementing LLM Agents: ReAct and Simple Agents

In this guide, we will walk through the configuration and usage of two main types of LLM-based agents: **ReAct Agent** and **Simple Agent**. We will discuss their unique features, configuration steps, and best practices, along with how to use tool integrations to enhance their capabilities.

#### 1. ReAct Agent: Reasoning + Action

**Overview**

The ReAct Agent combines reasoning and tool-based actions to handle complex, dynamic tasks. This agent operates in a loop-based framework that iteratively uses external tools, makes decisions, and processes feedback to achieve its goals.

**How It Works**

The ReAct approach is inspired by human reasoning and action, utilizing Chain-of-Thought (CoT) prompting to guide the agent's decision-making. By incorporating external data through tools, ReAct overcomes limitations like knowledge cutoff and hallucination issues, allowing the agent to update its knowledge and respond accurately.

**Key Configuration Options**

* **Name**: Unique identifier for the agent
* **Tools**: External services the agent can leverage (search engines, scrapers, etc.)
* **LLM**: The large language model powering the agent
* **Role**: Defines the agent's persona and behavior guidelines
* **Memory**: Optional configuration for persistent knowledge retention
* **Advanced Settings**:
  * **Max Loop**: Maximum number of reasoning-action cycles (default: 10)
  * **Behavior on Max Loops**: Action when max loops is reached (Return/Continue)
  * **Inference Mode**: Response format (XML recommended)
  * **Streaming**: Toggle for incremental response generation
  * **Streaming Mode**: Controls how streaming responses are delivered (Final/Incremental)
  * **By Tokens**: Stream responses token by token
  * **Tool Params**: Whether to include tool parameters in streaming responses

**Step-by-Step Setup**

<figure><img src="https://4279757243-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTbBxR0Ob7RUmbvHZkQi2%2Fuploads%2FD7embvfKYmXECJH1uCL0%2FLLM%20agents%20-%20React%20and%20simple%20agents%20(1.1).gif?alt=media&#x26;token=a330bfce-e4d6-4ea0-9425-76a4d14a717f" alt=""><figcaption><p>Creating the agent</p></figcaption></figure>

<figure><img src="https://4279757243-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTbBxR0Ob7RUmbvHZkQi2%2Fuploads%2Fy2mTYYutrEAQAALq64lr%2FLLM%20agents%20-%20React%20and%20simple%20agents%20(2).gif?alt=media&#x26;token=8cb08f11-1c30-46a9-8232-50187f939125" alt=""><figcaption><p>Configuring the agent</p></figcaption></figure>

<figure><img src="https://4279757243-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTbBxR0Ob7RUmbvHZkQi2%2Fuploads%2F0srCc67dxnG2d0k5k9yg%2FLLM%20agents%20-%20React%20and%20simple%20agents%20(3).gif?alt=media&#x26;token=52b71890-2edb-4c5c-8aac-906483cd8edf" alt=""><figcaption><p>Saving the agent</p></figcaption></figure>

1. **Basic Configuration**\
   Start by defining the **name**, **role**, and selecting an **LLM** for the agent.
2. **Tool Integration**\
   Select and configure tools like **ScaleSerp** or **ZenRows**. These tools are employed in the reasoning-action loop to fetch external data and assist with decision-making.
   * **Example Tool Setup**: Use ScaleSerp for web search and ZenRows for structured data extraction from web pages.
   * Agents equipped with search tools can access real-time information, improving response accuracy.
3. **Execution Flow**\
   The ReAct Agent works in a cycle of thinking, acting, and evaluating results. The agent:
   * Receives an input query
   * Determines the necessary actions
   * Utilizes the appropriate tools
   * Assesses the gathered data
   * Loops if additional information or reasoning is needed
   * Concludes with a formatted response
4. **Testing the Agent**\
   Test the ReAct agent with a series of queries to evaluate its decision-making, data handling, and loop termination when reaching **max\_loops**.

**Best Practices**

* Set reasonable `max_loops` value based on task complexity
* Define clear roles with specific behavioral guidelines
* Configure appropriate error handling for loop termination
* Use tool combinations that complement each other

***

#### 2. Simple Agent: Direct Prompt-Response

**Overview**

The Simple Agent is designed for straightforward tasks, focusing on single-turn, prompt-response interactions without the need for external tools. It is ideal for content generation, summarization, or any task that requires minimal context and processing.

**Key Configuration Options**

* **Name**: Unique identifier for the agent
* **LLM**: The language model powering the agent
* **Role**: Detailed instructions guiding the agent's responses
* **Memory**: Optional but typically not needed for simple agents

**Step-by-Step Setup**

<figure><img src="https://4279757243-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTbBxR0Ob7RUmbvHZkQi2%2Fuploads%2F5hSdqmoUl8fNdSHLRSBM%2FSimple%20agent%20-%20Direct%20prompt%20response%20(1).gif?alt=media&#x26;token=574bb770-aaf3-4b36-9728-9f3ec8f610c7" alt=""><figcaption><p>Creating the simple agent</p></figcaption></figure>

<figure><img src="https://4279757243-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTbBxR0Ob7RUmbvHZkQi2%2Fuploads%2FpnfDfV1ta4jASn18XJGp%2FSimple%20agent%20-%20Direct%20prompt%20response%20(2).gif?alt=media&#x26;token=e2fd040c-4194-45b8-91c7-c56824935be9" alt=""><figcaption><p>Configuring and saving the simple agent</p></figcaption></figure>

1. **Basic Configuration**\
   Define the **name**, select the **LLM**, and set up the **role**.
2. **Role Definition**\
   Provide detailed instructions in the role field to ensure the agent’s responses align with your requirements.\
   Example role definition:

   ```
   You are a helpful AI assistant that:
   - Provides clear, concise answers
   - Maintains a professional tone
   - Follows specific formatting guidelines
   - Avoids speculation
   ```
3. **Execution Flow**\
   The Simple Agent’s flow is straightforward:
   * Receives input
   * Processes based on role
   * Directly generates a response

**Best Practices for Simple Agent**

* **Role Specificity**: A well-defined role ensures the agent’s responses are aligned with expectations.
* **Usage Suitability**: Ideal for tasks that do not require tool usage or iterative reasoning, such as content modification or summarization.
* **Reflection Strategy**: Use the role section for reflective tasks, where the agent can assess or refine content based on role instructions

#### 3. Reflection Agent

**Overview** The Reflection Agent extends the ReAct paradigm by adding self-assessment capabilities. It evaluates its own responses before finalizing outputs, improving accuracy and reducing hallucinations.

**Key Features**

* Self-criticism loop for quality control
* Can backtrack and revise responses
* Higher accuracy on complex reasoning tasks
* Uses the same configuration options as ReAct Agent

**Best Practices**

* Use for high-stakes or fact-sensitive applications
* Set appropriate max loops as reflection adds processing cycles
* Define clear evaluation criteria in the role description

***

### Memory Systems

Memory enables agents to retain information across interactions, providing context and continuity for complex workflows.

#### Memory Types

1. **Pinecone**
   * Vector database for semantic search
   * Configuration options:
     * Connection: Select existing or create new
     * Index name: Name of the memory store (e.g., "conversations")
     * Namespace: Logical division within index (e.g., "default")
     * Dimension: Vector size (typically 1536 for OpenAI embeddings)
     * Index type: Serverless or Cloud-based
     * Region: Geographic location for data storage
2. **Qdrant**
   * Alternative vector database
   * Similar configuration options to Pinecone
   * Better for certain specialized use cases

#### Embedder Configuration

* Select the embedding model for converting text to vectors
* Options typically include OpenAI, Cohere, or custom embedders
* Dimension size must match the selected embedder's output

#### Memory Best Practices

* Use memory for multi-turn conversations
* Consider privacy implications and data retention policies
* Test memory retrieval with various query types
* Implement regular memory maintenance to prevent vector store bloat

### Agent Comparison

| Feature                  | ReAct Agent                             | Simple Agent                                  | Reflection Agent                    |
| ------------------------ | --------------------------------------- | --------------------------------------------- | ----------------------------------- |
| Use Case                 | Complex tasks, research, data gathering | Content generation, formatting, summarization | Fact-sensitive, high-accuracy needs |
| Tool Integration         | Extensive                               | None                                          | Extensive                           |
| Processing Steps         | Multiple loops                          | Single-turn                                   | Multiple loops with self-assessment |
| Memory Requirements      | Often beneficial                        | Rarely needed                                 | Often beneficial                    |
| Configuration Complexity | High                                    | Low                                           | High                                |
| Response Time            | Longer                                  | Quick                                         | Longest                             |

***

#### Workflow Examples

**ReAct Agent Workflow**

* **Objective**: Create a search assistant that finds real-time information on the web.
* **Execution**:
  * User inputs a query
  * ReAct agent engages **ScaleSerp** to search
  * Extracts, processes, and verifies data
  * Provides a formatted, factual response

**Simple Agent Workflow**

* **Objective**: Summarize a provided document.
* **Execution**:
  * User provides document text
  * Simple agent processes the text based on its summarization role
  * Returns a concise summary, maintaining a professional tone as specified in the role.

***

#### Conclusion

LLM agents provide a powerful framework for building AI applications with varying levels of complexity. By understanding the strengths and configuration options of each agent type, you can design workflows that effectively solve real-world problems.

The key to success lies in proper configuration, clear role definitions, and appropriate tool selection. Start with simpler implementations and gradually incorporate more advanced features as you become familiar with the platform's capabilities
