Grand Diomande Research · Full HTML Reader

Sales Agent Architecture — V1 through V2

The Market Sweep Agent is an automated sales pipeline that discovers coffee shops across US markets, enriches contact information, generates AI-personalized emails, and tracks responses — all from a single dashboard.

Agents That Account for Themselves architecture technical paper candidate score 30 .md

Full Public Reader

Sales Agent Architecture — V1 through V2

System Overview

The Market Sweep Agent is an automated sales pipeline that discovers coffee shops across US markets, enriches contact information, generates AI-personalized emails, and tracks responses — all from a single dashboard.

┌─────────────────────────────────────────────────────────────────────────┐
│                        Market Sweep Pipeline                            │
│                                                                         │
│  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────┐  ┌──────────┐ │
│  │ Discovery │→│ Enrichment│→│  Import   │→│AI Generate│→│   Email   │ │
│  │ (SerpAPI) │  │(Scraping) │  │  (CRM)   │  │(GPT-4o-m)│  │ (Resend) │ │
│  └──────────┘  └──────────┘  └──────────┘  └──────────┘  └──────────┘ │
│       ↓              ↓              ↓              ↓              ↓     │
│  sweep_prospects  +email,IG   inbound_leads  +ai_body    email_outreach│
│                   +snippet    +accounts      +variants                  │
│                   +vibe       +locations      +vibe                     │
└─────────────────────────────────────────────────────────────────────────┘

Edge Functions

FunctionPurposeAPI UsedCost
`market-sweep-search`SerpAPI multi-query discoverySerpAPI~$1.60/city
`market-sweep-enrich`Website scraping: emails, IG, snippet, vibeNone$0
`market-sweep-import`Promote prospects to CRM leads + create accountsNone$0
`market-sweep-ai-generate`GPT-4o-mini personalized email generationOpenAI~$0.002/email
`market-sweep-email`Send via Resend, prefer AI content, A/B variantsResendFree tier
`market-sweep-followup`Follow-up sequences (max 2 per prospect)ResendFree tier
`market-sweep-classify`GPT-4o-mini response classificationOpenAI~$0.001/classify
`background-sweep`Google Maps Places continuous market discoveryGoogle MapsUsage-based

Database Schema

Core Tables (V1)

  • `market_sweeps` — Tracks each city sweep operation with status progression
  • `sweep_prospects` — Staging table for discovered cafes before lead import
  • `inbound_leads` — CRM leads with zone classification and pipeline tracking
  • `email_outreach` — Email send logs with sweep linking

V2 Additions

  • `accounts` — Business entities with place_id dedup, Google Maps data, vibe, stage tracking
  • `locations` — Physical addresses linked to accounts (multi-location support)
  • `account_contacts` — Multiple contacts per business with role classification
  • `sweep_queue` — Background sweep rotation through 22 markets

V2 Column Additions on `sweep_prospects`

ColumnTypePurpose
`ai_subject`textGPT-4o-mini generated subject line
`ai_body`textGPT-4o-mini generated email body
`subject_variants`jsonb3 A/B subject line variants
`selected_variant`intWhich variant was sent
`ai_generation_model`textModel identifier (gpt-4o-mini)
`cafe_vibe`texthipster/minimalist/brunch-heavy/craft-focused/neighborhood
`website_snippet`textFirst 500 chars of website for AI context
`response_type`textinterested/not_now/unsubscribe/wrong_contact
`qualification_tier`texthot/warm/cold based on response
`account_id`uuidLink to accounts table

AI Email Generation Flow

1. Enrichment scrapes website → extracts snippet + classifies vibe
2. GPT-4o-mini receives: cafe name, city, rating, reviews, vibe, snippet, IG handle
3. Returns JSON: { subject, body, subject_variants[3], vibe }
4. Email function picks random variant for A/B testing
5. After response, classify function categorizes → sets qualification_tier

System Prompt

> "You are a sales copywriter for Koji, a premium fresh oat milk brand. Write warm, concise intro emails that feel personal — not templated. Reference specific details about the cafe."

Vibe Classification Keywords

VibeKeywords
hipstervinyl, vintage, artisan, latte art, pour over, single origin
minimalistminimal, clean, modern, scandinavian, zen, matcha
brunch-heavybrunch, avocado toast, mimosa, eggs benedict, pancakes
craft-focusedroast, cupping, extraction, barista, v60, chemex, specialty
neighborhoodcommunity, local, family, cozy, welcoming, regulars

Background Sweep (Google Maps Places)

Continuous discovery across 22 US markets:

1. Queue rotation: Each call processes one city + one query type
2. 7 search queries: cafe, coffee shop, coffee roaster, espresso bar, brunch restaurant, bakery cafe, tea house
3. Mega-chain filter: Excludes Starbucks, Dunkin, McDonald's, etc.
4. Chain detection: Flags Blue Bottle, Intelligentsia, etc. as chains
5. Upsert by place_id: Updates existing accounts, creates new ones
6. Multi-location: Chains get separate location entries under same account

22 US Markets

Philadelphia, Pittsburgh, New York, Brooklyn, Los Angeles, San Francisco, Chicago, Seattle, Portland, Austin, Denver, Nashville, Miami, Boston, Washington DC, Atlanta, Minneapolis, San Diego, Detroit, Charlotte, Richmond, New Orleans

Prerequisites

  • `OPENAI_API_KEY` — Set in Supabase Edge Function secrets
  • `GOOGLE_MAPS_API_KEY` — Places API enabled
  • `RESEND_API_KEY` — Email sending
  • `SERPAPI_API_KEY` — Search discovery

Cost Summary (per city sweep)

ComponentCost
SerpAPI discovery~$1.60
Website enrichment$0.00
AI email generation (50 prospects)~$0.10
Response classification~$0.01
Email sending (Resend free tier)$0.00
Total per city~$1.71

Promotion Decision

Promote into a technical note or architecture paper with implementation anchors.

Source Anchor

milkmendelivery/docs/SALES-AGENT-ARCHITECTURE.md

Detected Structure

Method · Architecture