halfengineer

Buildingagents,shippingcode.

Developer Advocate · AI Agent Engineer · Community Builder

Building an AI-Powered Data Analysis Agent: A Deep Dive into Daytona, Fetch.ai, and Autonomous Agent Systems

Gautam Manak December 15, 2024 7 min read

INTRODUCTION

In the era of AI and autonomous systems, the ability to create intelligent agents that can securely execute code, analyze data, and generate insights autonomously is revolutionizing how we approach data science and automation. In this article, we'll explore how I built a data summarization assistant that combines several cutting-edge technologies: Daytona for secure sandbox execution, Fetch.ai's uAgents framework for autonomous agent communication, Agentverse for agent orchestration, and ASI API for intelligent summarization.

This project demonstrates a complete end-to-end system where an AI agent receives data requests, spins up isolated execution environments, performs comprehensive data analysis, generates visualizations, and delivers beautiful web reports—all autonomously and securely.

THE PROBLEM: WHY AUTONOMOUS DATA ANALYSIS AGENTS?

Traditional data analysis workflows require:

  • Manual setup of analysis environments
  • Writing custom scripts for each dataset
  • Managing dependencies and runtime environments
  • Ensuring security when executing untrusted code
  • Creating visualization dashboards manually

Our solution automates all of this. An agent receives a data URL (CSV, JSON, or Google Sheets), automatically:

  1. Creates a secure sandbox environment
  2. Downloads and validates the data
  3. Performs statistical analysis
  4. Generates visualizations
  5. Creates a web report
  6. Returns a preview URL

All of this happens in seconds, with zero manual intervention.

TECHNOLOGY STACK OVERVIEW

Our architecture leverages four key technologies:

  1. Daytona: Secure sandbox execution platform
  2. Fetch.ai uAgents: Autonomous agent framework
  3. Agentverse: Agent discovery and orchestration platform
  4. ASI API: Large Language Model for intelligent summarization

Let's dive deep into each component.

PART 1: DAYTONA - SECURE SANDBOX EXECUTION

What is Daytona?

Daytona is a cloud-native development environment platform that provides secure, isolated sandboxes for code execution. Think of it as Docker containers on steroids—each sandbox is a fully isolated Linux environment with its own file system, network, and compute resources.

Why Daytona for Agent Execution?

When building autonomous agents that execute code, security is paramount. You can't trust arbitrary code execution on your own infrastructure. Daytona solves this by:

  1. Isolation: Each sandbox is completely isolated from your host system
  2. Ephemeral: Sandboxes can be created and destroyed on-demand
  3. Preview URLs: Automatic HTTPS endpoints for web applications
  4. API-First: Programmatic control via Python SDK
  5. Resource Management: Automatic cleanup and resource limits

How We Use Daytona in Our Agent

# Create a sandbox
daytona = Daytona(DaytonaConfig(api_key=daytona_api_key))
sandbox = daytona.create()

# Upload our Flask app
sandbox.fs.upload_file(flask_code.encode(), "app.py")

# Install dependencies
sandbox.process.execute_session_command(
    exec_session_id,
    SessionExecuteRequest(command="pip install flask pandas matplotlib", run_async=False)
)

# Start the Flask app
sandbox.process.execute_session_command(
    exec_session_id,
    SessionExecuteRequest(command="python3 app.py", run_async=True)
)

# Get preview URL
preview_info = sandbox.get_preview_link(3000)

The workflow:

  1. Agent receives data URL
  2. Creates Daytona sandbox (isolated environment)
  3. Downloads and analyzes data locally
  4. Generates Flask app with results
  5. Uploads app to sandbox
  6. Installs dependencies in sandbox
  7. Runs Flask app in sandbox
  8. Returns preview URL to user

PART 2: FETCH.AI AND UAGENTS FRAMEWORK

What is Fetch.ai?

Fetch.ai is building an open, permissionless, decentralized network for autonomous agents. Their vision is to create an "economy of things" where AI agents can autonomously transact, collaborate, and provide services.

Fetch.ai Ecosystem

Fetch.ai offers a powerful, comprehensive platform for creating, deploying, and connecting autonomous agents. The ecosystem consists of four key components:

  1. uAgents Framework: A lightweight Python framework for building agents with built-in identity, messaging, and protocol support.
  2. Agentverse: An open marketplace where agents can be registered, discovered, and utilized.
  3. ASI One LLM: Fetch.ai's Web3-native Large Language Model designed specifically for agentic workflows.
  4. Chat Protocol: A standardized communication protocol for conversational interactions between agents.

Our Agent Architecture

from uagents import Agent, Context, Protocol
from uagents_core.contrib.protocols.chat import (
    ChatMessage,
    ChatAcknowledgement,
    TextContent,
    chat_protocol_spec,
)

agent = Agent(
    name="data-summarization-agent",
    seed="data-summarization-agent-seed-daytona",
    port=8000,
    mailbox=True,
)

protocol = Protocol(spec=chat_protocol_spec)

@protocol.on_message(ChatMessage)
async def handle_message(ctx: Context, sender: str, msg: ChatMessage):
    # Process incoming chat message
    # Extract data URL from message
    # Trigger data analysis
    # Reply with preview URL

Key uAgents Concepts:

  1. Agent: The autonomous entity with its own identity
  2. Protocol: Communication specification (we use the chat protocol)
  3. Context: Execution context with logging, storage, and messaging
  4. Message Handlers: Async functions that process incoming messages
  5. Mailbox: Ensures reliable message delivery even if agent is offline

PART 3: AGENTVERSE - AGENT DISCOVERY AND ORCHESTRATION

What is Agentverse?

Agentverse is Fetch.ai's open marketplace where agents can be registered, discovered, and utilized. Think of it as the "App Store" for autonomous agents.

Key Features:

  1. Agent Discovery: Find agents by capability, service type, or use case
  2. Agent Registry: Public directory of available agents
  3. Service Descriptions: Agents advertise their capabilities
  4. Integration: Seamless integration with uAgents framework and ASI LLM

PART 4: ASI API - INTELLIGENT SUMMARIZATION

What is ASI?

ASI (Autonomous Systems Intelligence) One LLM is Fetch.ai's Web3-native Large Language Model designed specifically for agentic workflows.

Integration in Our Agent:

def get_asi_llm_summary(api_key: str, content: str) -> str:
    """Use ASI LLM to refine/shorten the summary text"""
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {api_key}"
    }
    payload = {
        "model": "asi1-mini",
        "messages": [
            {
                "role": "system",
                "content": "You are a data analyst. Summarize data insights clearly and concisely."
            },
            {
                "role": "user",
                "content": f"Summarize these dataset insights:\n\n{content}"
            }
        ]
    }
    response = requests.post(
        "https://api.asi1.ai/v1/chat/completions",
        json=payload,
        headers=headers,
        timeout=30
    )
    return response.json()["choices"][0]["message"]["content"]

Example Transformation:

Before (Technical):

Dataset summary:
- Rows: 1,234
- Columns: 7
- Sales: mean 1450.50, median 1500.00, range 500.00-2700.00

After (ASI-Enhanced):

Dataset Overview:
- Analyzed 1,234 records across 7 dimensions
- Sales performance shows strong consistency (median: $1,500)
- Revenue ranges from $500 to $2,700 with minimal missing data (0.52%)

PART 5: TECHNICAL ARCHITECTURE

System Architecture

Our system consists of two main components:

  1. agent.py: The uAgents chat agent
  2. data_analyzer.py: Core data processing and sandbox management

Data Flow:

User -> ChatMessage -> uAgents Agent -> Data Analyzer -> Daytona Sandbox -> Flask App -> Preview URL -> User

Key Technical Decisions:

  • Async Execution: Data analysis runs in an executor thread, preventing the agent from blocking
  • Base64 Charts: Visualizations embedded directly in HTML, no separate file serving needed
  • Health Checks: System waits for Flask app to be ready before returning URL
  • Error Handling: Comprehensive try-catch with cleanup at every step
  • Resource Management: Sandboxes deleted after use to prevent waste

PART 6: DATA ANALYSIS CAPABILITIES

Statistical Analysis:

  • Summary Statistics: Mean, median, standard deviation, min, max for all numeric columns
  • Distribution Analysis: Skewness, quartiles, outlier detection
  • Missing Data: Detection and percentage calculation
  • Correlation Analysis: Relationships between numeric variables

Visualization Generation:

  • Histograms: Distribution of numeric columns
  • Bar Charts: Frequency of categorical values
  • Correlation Heatmaps: Relationships between variables

Supported Data Sources:

  1. CSV URLs: Any publicly accessible CSV file
  2. JSON URLs: API endpoints or JSON files
  3. Google Sheets: Automatic CSV export URL conversion
  4. Raw CSV/JSON Text: Paste directly in chat

Google Sheets Integration:

if 'docs.google.com' in url and '/spreadsheets/' in url:
    spreadsheet_id = extract_id(url)
    url = f"https://docs.google.com/spreadsheets/d/{spreadsheet_id}/export?format=csv&gid={gid}"

PART 7: SECURITY AND BEST PRACTICES

Security Considerations:

  1. Sandbox Isolation: All code execution in isolated Daytona sandboxes
  2. No Host Access: Sandboxes cannot access host file system
  3. Ephemeral Execution: Sandboxes destroyed after use
  4. API Key Management: Keys stored in environment variables

Limitations:

  1. Public data only — URLs must be publicly accessible
  2. Sandbox lifetime — may timeout after inactivity
  3. Resource limits — large datasets take longer

CONCLUSION

This project demonstrates the power of combining modern technologies:

  • Daytona provides secure, isolated execution environments
  • Fetch.ai uAgents enables autonomous agent communication
  • Agentverse facilitates agent discovery and collaboration
  • ASI API adds intelligent summarization capabilities

Together, they create a complete autonomous data analysis system that receives data requests, securely executes analysis code, generates comprehensive reports, and delivers results via web interface.

GETTING STARTED

pip install uagents daytona-sdk pandas matplotlib seaborn flask requests python-dotenv
export DAYTONA_API_KEY=your_key
export ASI_API_KEY=your_key  # optional
python agent.py

RESOURCES