Skip to main content

Overview

The AI Workflows component leverages Kestra orchestration to run automated scripts that generate insights, forecasts, and intelligence using AI models from OpenAI and Google Gemini.

Technology Stack

Node.js

JavaScript runtime for script execution

OpenAI

GPT models for text generation and analysis

Google Gemini

Advanced AI for multi-modal insights

Puppeteer

Web automation and crawling

Key Capabilities

AI-Powered Insights

Generate predictions for future sales using historical data and AI models:
  • Time Series Analysis: Trend identification and seasonality
  • Multi-variate Predictions: Factor in marketing, inventory, pricing
  • Confidence Intervals: Probabilistic forecasts with uncertainty
  • Brand-specific Models: Customized for each brand’s patterns
Output: Daily/weekly/monthly forecast reports

Web Crawling & Intelligence

Monitor competitor prices across the web:
  • Automated price scraping from competitor sites
  • Price change detection and alerting
  • Historical price tracking
  • Margin impact analysis
Frequency: Daily crawls for key products
Track product availability across channels:
  • Stock status monitoring
  • Out-of-stock duration tracking
  • Multi-marketplace availability
  • Fulfillment speed comparison
Use Case: Identify stock-out opportunities
Aggregate and analyze customer reviews:
  • Sentiment analysis across platforms
  • Feature extraction from reviews
  • Competitive review comparison
  • Product improvement insights
AI Models: GPT-4 for sentiment, Gemini for summarization

Script Architecture

Kestra Workflows

Scripts are organized as Kestra workflows:

Script Organization

AI Integration

OpenAI Integration

1

Initialize Client

2

Generate Insights

3

Process Results

Google Gemini Integration

Gemini’s multi-modal capabilities allow analysis of charts, images, and text together for richer insights.

Data Access

BigQuery Integration

Scripts access BigQuery for historical data:

PostgreSQL Access

For operational data stored in Postgres:

Web Crawling

Puppeteer Automation

Always respect robots.txt and implement rate limiting to avoid overloading target sites.

Anti-Bot Evasion

Scheduling & Orchestration

Kestra Schedules

Run every day at specific times:
  • Sales forecasts (6 AM)
  • Daily summary reports (7 AM)
  • Price monitoring (8 AM)

Output & Distribution

Report Generation

AI-generated reports are distributed via:

Email

Automated email delivery using SendGrid or AWS SES

Dashboard

Reports saved to BigQuery and displayed in frontend

Slack

Critical alerts and summaries posted to Slack

API

Insights exposed via REST API for integrations

Storage

  • Reports: Stored in BigQuery insights dataset
  • Forecasts: Saved to forecasts table with confidence intervals
  • Screenshots: Uploaded to Google Cloud Storage
  • Logs: Kestra execution logs retained for 90 days

Monitoring & Alerting

Execution Monitoring

Track workflow execution:
  • Success rate: Percentage of successful runs
  • Duration: Average and P95 execution time
  • Resource usage: CPU, memory, API credits
  • Error rates: Failed tasks and reasons

Alerts

Automated alerts for:
  • Workflow failures or timeouts
  • API quota exceeded (OpenAI, Gemini)
  • Anomalous insights detected
  • Price changes exceeding thresholds

Cost Management

AI API Costs

Monthly AI API spending is monitored and budgeted:
  • OpenAI: ~$500/month (GPT-4 Turbo)
  • Google Gemini: ~$200/month (Gemini Pro)
  • Total: ~$700/month for AI services

Optimization Strategies

  • Use GPT-3.5 for simple tasks
  • Batch API requests when possible
  • Cache AI responses for repeated queries
  • Implement token limits per request

Next Steps

Architecture

Explore workflow architecture

AI Services

Learn about AI model integration

Development Guide

Build custom automation scripts

Forecasting Engine

Understand forecasting algorithms