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

# Getting Started with Agent Loops

> Create your first autonomous AI agent

This guide walks you through creating your first Agent Loop - an autonomous AI workflow that can use tools and complete tasks without user interaction.

## Simple Example: Daily Weather Report

Let's create an agent that fetches weather data and sends a report.

<Steps>
  <Step title="Create Agent Loop">
    Navigate to **Agent Loops** and click **Create Agent Loop**.
  </Step>

  <Step title="Name It">
    Name: "Daily Weather Reporter"
  </Step>

  <Step title="Write System Prompt">
    ```
    You are a weather reporter. Your job is to fetch current weather
    data for San Francisco and create a brief summary report.

    Use the HTTP tool to call a weather API, then format the results
    into a readable summary including temperature, conditions, and
    a brief forecast.
    ```
  </Step>

  <Step title="Set User Message">
    ```
    Get today's weather for San Francisco and create a summary report.
    ```
  </Step>

  <Step title="Add MCP Server">
    Add the **HTTP Client** MCP server so the agent can call weather APIs:

    * Server Type: HTTP Client
    * URL: (automatically configured)
  </Step>

  <Step title="Add Callback (Optional)">
    If you want to receive the report via webhook:

    * Callback URL: `https://your-domain.com/weather-reports`
    * Headers: Any authentication needed
  </Step>

  <Step title="Run">
    Click **Create** then **Run** to execute the agent loop.
  </Step>
</Steps>

## What Happens

When you run the agent loop:

1. **Agent Reads Instructions**: Processes system prompt and user message
2. **Plans Approach**: Decides to use HTTP tool to call weather API
3. **Calls Tool**: Makes HTTP request to weather service
4. **Processes Response**: Extracts temperature, conditions, forecast
5. **Generates Report**: Creates formatted summary
6. **Sends Callback**: Delivers report to your webhook (if configured)
7. **Completes**: Marks execution as successful

## Example Output

The agent might produce:

```
Weather Report for San Francisco - January 15, 2024

Current Conditions:
- Temperature: 62°F (17°C)
- Conditions: Partly Cloudy
- Humidity: 65%
- Wind: 10 mph SW

Forecast:
Expect partly cloudy skies throughout the day with temperatures
reaching a high of 65°F. No precipitation expected. A pleasant
day ahead!
```

## More Complex Example: Database Report

Create an agent that queries a database and generates a report.

<Steps>
  <Step title="Create Agent Loop">
    Name: "Daily Sales Report Generator"
  </Step>

  <Step title="System Prompt">
    ```
    You are a sales analyst. Your task is to:

    1. Query the sales database for yesterday's data
    2. Calculate these metrics:
       - Total revenue
       - Number of orders
       - Average order value
       - Top 5 products by revenue
    3. Format results as a professional report
    4. Include insights about any notable trends

    Use the database tool to execute queries.
    ```
  </Step>

  <Step title="User Message">
    ```
    Generate yesterday's sales report and identify any trends.
    ```
  </Step>

  <Step title="Add Database MCP Server">
    (Coming soon - use HTTP to query API for now)
  </Step>

  <Step title="Configure Callback">
    Send results to your team's Slack channel or email system.
  </Step>
</Steps>

## Agent Loop Patterns

### Pattern 1: Data Fetcher

**Purpose**: Retrieve data from external sources

**Components**:

* HTTP MCP server
* Clear data source instructions
* Output formatting guidelines

**Example**: Fetch stock prices, weather, news

### Pattern 2: Data Processor

**Purpose**: Transform or analyze data

**Components**:

* File system MCP server
* Processing instructions
* Output format specification

**Example**: Analyze CSV files, process logs, summarize documents

### Pattern 3: Report Generator

**Purpose**: Create scheduled reports

**Components**:

* Data source access (HTTP/Database)
* Report template in system prompt
* Callback for delivery

**Example**: Daily sales reports, weekly summaries, monthly analytics

### Pattern 4: Monitoring Agent

**Purpose**: Check systems and alert on issues

**Components**:

* HTTP MCP for API checks
* Conditional logic in prompt
* Callback for alerts

**Example**: Website uptime, API health, error rates

## Iterative Development

Agents use multiple reasoning steps:

```
Iteration 1: "I need to fetch weather data. I'll call the API."
→ Uses HTTP tool

Iteration 2: "I got the data. Now I'll extract key information."
→ Processes response

Iteration 3: "I have the information. I'll format it as a report."
→ Generates output

Iteration 4: "Report complete. I'll send it via callback."
→ Completes task
```

Set max iterations based on task complexity:

* Simple: 5 iterations
* Medium: 10 iterations
* Complex: 20+ iterations

## Testing Your Agent

<Steps>
  <Step title="Start Simple">
    Begin with basic instructions and one tool.
  </Step>

  <Step title="Run Manually">
    Execute and review the output.
  </Step>

  <Step title="Check Logs">
    Review iteration logs to see reasoning process.
  </Step>

  <Step title="Refine Prompt">
    Adjust system prompt based on results.
  </Step>

  <Step title="Add Complexity">
    Gradually add more tools and steps.
  </Step>

  <Step title="Test Edge Cases">
    Try with different inputs and scenarios.
  </Step>
</Steps>

## Common Mistakes

### Vague Instructions

**Bad**:

```
Analyze the data.
```

**Good**:

```
Query the database for yesterday's sales. Calculate total revenue
and average order value. Format as a JSON report with these fields:
{date, total_revenue, order_count, average_order_value}.
```

### Too Many Tools

**Problem**: Providing unnecessary MCP servers confuses the agent.

**Solution**: Only include tools needed for the specific task.

### Insufficient Iterations

**Problem**: Agent runs out of iterations before completing.

**Solution**: Increase max iterations or simplify the task.

### No Error Handling

**Problem**: Agent fails when API returns an error.

**Solution**: Include error handling instructions in system prompt:

```
If the API returns an error, try once more. If it fails again,
return a message explaining the issue.
```

## Best Practices

<CardGroup cols={2}>
  <Card title="Explicit Steps" icon="list-ol">
    Break tasks into numbered steps in system prompt
  </Card>

  <Card title="Expected Output" icon="file-export">
    Describe exactly what format you want
  </Card>

  <Card title="Error Handling" icon="triangle-exclamation">
    Tell the agent how to handle failures
  </Card>

  <Card title="Test Thoroughly" icon="vial">
    Run multiple times with different scenarios
  </Card>
</CardGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="MCP Servers" icon="server" href="/agent-loops/mcp-servers">
    Learn about available tools
  </Card>

  <Card title="Callbacks" icon="webhook" href="/agent-loops/callbacks">
    Set up result webhooks
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/introduction">
    Trigger agents programmatically
  </Card>
</CardGroup>
