Skip to main content

Generative Messaging — Technical Documentation

Last updated: February 2026


Table of Contents

  1. Overview
  2. Architecture
  3. Repository Map
  4. Core Flows
  5. Entities & Data Model
  6. API Endpoints
  7. Services & Business Logic
  8. AI Provider Integration
  9. QA Agent System
  10. Configuration
  11. Integration Points

1. Overview

Generative Messaging (AIM — AI Messaging) is Sopro's AI-powered email generation system. It assembles prospect + campaign data into prompts, calls AI providers (OpenAI, Anthropic, DeepSeek, Grok) to generate personalised emails, runs QA agents to validate quality, and stores generated emails for the sending pipeline. The AIM engine lives in the email-template-demo repo (hosted at aim.sopro.io), with integration points in sopro-sodastream, sopro-sodastream-core, and sopromasterdata.


2. Architecture


3. Repository Map

RepositoryLayerKey Files
email-template-demoGeneration ControllerControllers/GenerationController.cs
email-template-demoSuitability ControllerControllers/CompanySuitabilityController.cs
email-template-demoPrompt BuilderServices/PromptBuilder.cs
email-template-demoAI Provider FactoryServices/AIProviderFactory.cs
email-template-demoQA AgentServices/QAAgentService.cs
email-template-demoProvider AdaptersServices/Providers/OpenAI/, Anthropic/, DeepSeek/, Grok/
sopro-sodastreamGPT ControllerControllers/GPTSpindleController.cs
sopro-sodastreamEntitiesgenerative email entities and models
sopro-sodastream-coreHyperRequestServices/HyperRequestService.cs
sopro-sodastream-coreExample RecipientsServices/GenerativeExampleRecipientService.cs
sopromasterdataCompany SuitabilityCompanySuitabilityServices/CompanySuitabilityService.cs
sopromasterdataEndpointManagerShared/EndpointManager/EndpointManagerService.cs

4. Core Flows

4.1 Email Generation Pipeline

4.2 Company Suitability Scoring (via AIM)

4.3 Prompt Assembly


5. Entities & Data Model

GenerativeEmail (sopro-sodastream)

ColumnTypeDescription
Idint (PK)Generated email identifier
CampaignIdint (FK)Campaign reference
ProspectIdlong (FK)Prospect reference
Subjectnvarchar(500)Generated subject line
Bodynvarchar(max)Generated email HTML body
AIProvidernvarchar(50)Provider used (OpenAI, Anthropic, etc.)
QAScoredecimal?Quality assessment score
QAStatusint (enum)Pending, Passed, Failed, Regenerated
EmailTypeint (enum)Initial, Chaser1, Chaser2, Chaser3
GeneratedAtdatetimeGeneration timestamp
ApprovedAtdatetime?QA approval timestamp

CompanySuitabilityResult (sopromasterdata)

ColumnTypeDescription
Idint (PK)Result identifier
CampaignIdint (FK)Campaign being scored for
CompanyIdint (FK)Company being scored
Scoredecimal0-100 suitability score
Reasoningnvarchar(max)AI-generated explanation
Providernvarchar(50)AI provider used
ScoredAtdatetimeScoring timestamp

6. API Endpoints

AIM Service Endpoints (email-template-demo at aim.sopro.io)

MethodEndpointDescription
POST/api/generateGenerate a personalised email
POST/api/generate/chaserGenerate a follow-up chaser email
POST/api/v5/company-suitability-v1Score company suitability for a campaign
GET/api/healthHealth check

Request Payload (/api/generate)

{
"campaignBrief": "...",
"valueProposition": "...",
"prospect": {
"firstName": "John",
"lastName": "Smith",
"jobTitle": "VP Marketing",
"seniority": "VP"
},
"company": {
"name": "Acme Corp",
"industry": "Technology",
"size": "200-500",
"website": "acme.com",
"description": "..."
},
"suitabilityScore": 85,
"suitabilityReasoning": "...",
"style": {
"tone": "professional",
"maxLength": 150,
"provider": "openai"
}
}

7. Services & Business Logic

GenerativeExampleRecipientService (sopro-sodastream-core)

Location: sopro-sodastream-core/Services/GenerativeExampleRecipientService.cs
Size: ~1477 lines
Purpose: Assembles all data needed for email generation — gathers prospect data, company information, campaign brief, suitability score, and example emails into a structured request.

This is the most complex service in the generation pipeline — it handles:

  • Querying prospect and company data
  • Fetching campaign configuration and brief
  • Loading example emails for style reference
  • Structuring the generation request payload
  • Handling generation results and storage

HyperRequestService (sopro-sodastream-core)

Location: sopro-sodastream-core/Services/HyperRequestService.cs
Purpose: HTTP client for calling the AIM service endpoints.

PromptBuilder (email-template-demo)

Location: email-template-demo/Services/PromptBuilder.cs
Purpose: Assembles the structured prompt from the generation request:

MethodDescription
BuildGenerationPrompt()Creates system + user messages for email generation
BuildChaserPrompt()Creates prompt for follow-up chasers
BuildSuitabilityPrompt()Creates prompt for company suitability scoring

AIProviderFactory (email-template-demo)

Location: email-template-demo/Services/AIProviderFactory.cs
Purpose: Factory pattern — selects the appropriate AI provider based on configuration.

public interface IAIProvider
{
Task<GenerationResult> GenerateAsync(PromptMessage[] messages, GenerationOptions options);
}

Implementations: OpenAIProvider, AnthropicProvider, DeepSeekProvider, GrokProvider


8. AI Provider Integration

Provider Configuration

Provider Selection Logic

The provider can be specified per request, or defaults are used per campaign/environment:

  • Production: Primarily OpenAI and Anthropic
  • Testing: DeepSeek or Grok for cost efficiency
  • Fallback: If primary provider fails, factory falls back to secondary

9. QA Agent System

Architecture

The QA agent is a separate AI call that reviews the generated email:

QA Review Criteria

CriterionWeightDescription
RelevanceHighDoes the email match the campaign brief?
AccuracyHighAre company facts correct?
ToneMediumProfessional yet approachable?
LengthMediumAppropriate for the email type?
ComplianceHighNo banned phrases, false claims, or spam triggers?
PersonalisationMediumDoes it reference specific prospect/company details?

10. Configuration

AIM Service (email-template-demo)

{
"AIProviders": {
"OpenAI": { "ApiKey": "...", "DefaultModel": "gpt-4o" },
"Anthropic": { "ApiKey": "...", "DefaultModel": "claude-3-sonnet" },
"DeepSeek": { "ApiKey": "...", "DefaultModel": "deepseek-chat" },
"Grok": { "ApiKey": "...", "DefaultModel": "grok-2" }
},
"QA": {
"Enabled": true,
"PassThreshold": 0.7,
"MaxRegenerations": 2
}
}

EndpointManager in sopromasterdata

{
"EndpointManager": {
"CompanySuitability": {
"Url": "https://aim.sopro.io/api/v5/company-suitability-v1"
}
}
}

Hosting

SettingValue
AIM URLhttps://aim.sopro.io
HostingASP.NET Core (.NET 8)
Repoemail-template-demo

11. Integration Points

Upstream (data flows in)

SourceDataMechanism
sopro-sodastreamCampaign brief, prospect queueDatabase + HTTP
sopro-sodastream-coreAssembled prospect + company dataHTTP to AIM
sopromasterdataCompany suitability scoresHTTP via EndpointManager

Downstream (data flows out)

TargetDataMechanism
sopro-sodastreamGenerated emails (subject + body)Stored in DB
Email SendingApproved email content for deliveryDatabase read
Campaign StatisticsGeneration counts, QA pass ratesDatabase

Cross-Feature Dependencies

FeatureRelationship
Campaign ManagementCampaign brief drives email generation
Company SuitabilitySuitability scores enrich the generation prompt
Email SendingApproved generated emails are delivered by the sending pipeline
Email FindingProspect email addresses needed before sending generated content