Deep Research Email

An automated email-based research assistant powered by Google's Deep Research AI. Send an email with your research question, and receive a comprehensive research report back via email.

🚀 Features

  • Email-triggered research: Send a research query via email to initiate deep research
  • Asynchronous processing: Research runs in the background using Google's Deep Research Pro
  • Automated delivery: Completed research reports are automatically emailed back to you
  • Status tracking: Uses Val Town blob storage to track ongoing research tasks
  • Markdown formatting: Receive beautifully formatted research reports in HTML

📧 How to Use

  1. Send an email to: deep-research@valtown.email
  2. Subject: Your research topic (e.g., "Latest advances in quantum computing")
  3. Body: Detailed research question or context
  4. Wait: The system will process your request and send the research report back to your email

🏗️ Architecture

This val consists of two main components:

1. Email Handler (main.ts)

  • Type: Email Val
  • Trigger: Incoming email
  • Function:
    • Receives email and extracts the research question
    • Initiates a Deep Research task via Google GenAI API
    • Stores task metadata in blob storage for tracking
    • Returns immediately while research continues in background

2. Status Checker (cron.ts)

  • Type: Interval Val
  • Trigger: Scheduled (periodic check)
  • Function:
    • Polls blob storage for pending research tasks
    • Checks completion status with Google GenAI API
    • Sends email with research results when completed
    • Handles failed research attempts
    • Cleans up completed tasks from storage

🛠️ Technical Details

Dependencies

  • @google/genai - Google GenAI SDK for Deep Research
  • markdown-it - Markdown to HTML conversion
  • Val Town standard library (blob, email)

Data Flow

Email arrives → Store task → Background research
                    ↓
            Periodic status check
                    ↓
         Research complete? → Email results

Storage Schema

Tasks are stored in blob storage as:

{ [interactionId]: { interaction: { id, status, ... }, e: { from, subject, text, ... } } }

⚠️ Known Issues

  • Race condition: Concurrent emails or simultaneous status checks may cause conflicts (noted in code comments)
  • Consider implementing proper locking mechanism for production use

🔧 Configuration

Required Environment Variables

  • Google GenAI API credentials (configured through Val Town secrets)

Email Configuration

  • From address: paulkinlan.deep-research-email@valtown.email
  • Reply name: "Deep Research"

📝 Example Usage

Email to send:

To: paulkinlan.deep-research-email@valtown.email
Subject: The impact of AI on software development
Body: I'm interested in understanding how AI tools like 
      GitHub Copilot and ChatGPT are changing the way 
      developers write code. Please research recent 
      trends and statistics.

Response you'll receive: A comprehensive email with:

  • Detailed research findings in HTML format
  • Multiple sources and citations
  • Well-formatted sections and bullet points
  • Original query context included

🚀 Deployment

This val is ready to use as-is. The components are:

  • Email endpoint: Automatically configured by Val Town
  • Cron job: Set to run at configured intervals
  • Blob storage: Managed by Val Town infrastructure

📄 License

This is a personal project hosted on Val Town.

👤 Author

Paul Kinlan (@paulkinlan)


Built with Val Town 🏝️