Skip to main content
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.
1

Create Agent Loop

Navigate to Agent Loops and click Create Agent Loop.
2

Name It

Name: “Daily Weather Reporter”
3

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.
4

Set User Message

Get today's weather for San Francisco and create a summary report.
5

Add MCP Server

Add the HTTP Client MCP server so the agent can call weather APIs:
  • Server Type: HTTP Client
  • URL: (automatically configured)
6

Add Callback (Optional)

If you want to receive the report via webhook:
  • Callback URL: https://your-domain.com/weather-reports
  • Headers: Any authentication needed
7

Run

Click Create then Run to execute the agent loop.

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.
1

Create Agent Loop

Name: “Daily Sales Report Generator”
2

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.
3

User Message

Generate yesterday's sales report and identify any trends.
4

Add Database MCP Server

(Coming soon - use HTTP to query API for now)
5

Configure Callback

Send results to your team’s Slack channel or email system.

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

1

Start Simple

Begin with basic instructions and one tool.
2

Run Manually

Execute and review the output.
3

Check Logs

Review iteration logs to see reasoning process.
4

Refine Prompt

Adjust system prompt based on results.
5

Add Complexity

Gradually add more tools and steps.
6

Test Edge Cases

Try with different inputs and scenarios.

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

Explicit Steps

Break tasks into numbered steps in system prompt

Expected Output

Describe exactly what format you want

Error Handling

Tell the agent how to handle failures

Test Thoroughly

Run multiple times with different scenarios

Next Steps

MCP Servers

Learn about available tools

Callbacks

Set up result webhooks

API Reference

Trigger agents programmatically