Agents/Agent Types
Delivery Agent
ID: delivery
Purpose
Deliver approved newsletters via email and update web dashboard, track delivery status.
Inputs
interface DeliveryInput {
userTickerId: number; // Required: Foreign key to the UserTicker table
jobId?: string; // Optional: Job ID for tracking this run
}Configurations
Configuration is stored in AgentConfig with identifier delivery and the following structure:
{
email: {
provider: 'resend' | 'sendgrid',
apiKey: string,
fromAddress: string,
fromName: string,
replyTo: string,
templates: {
daily: 'templates/email-daily.html',
weekly: 'templates/email-weekly.html'
},
retry: {
maxAttempts: 3,
backoff: 'exponential',
delay: 1000
},
tracking: {
openTracking: true,
clickTracking: true,
unsubscribeLink: true
},
feedback: {
enabled: true,
buttonTypes: ['like' | 'dislike' | 'useful' | 'irrelevant' | 'custom'],
customButtons?: Array<{ label: string, value: string, icon?: string }>,
placement: 'inline' | 'bottom' | 'both',
style: 'buttons' | 'icons' | 'text-links'
}
},
dashboard: {
updateEndpoint: string,
cacheStrategy: 'cache-first' | 'network-first',
notificationEnabled: true
},
rateLimiting: {
emailsPerMinute: 100,
batchSize: 50
}
}Outputs
{
agentId: 'delivery',
agentVersion: string, // Semantic version (e.g., "1.2.3") of the agent that generated this output
userTickerId: number,
jobId: string,
timestamp: Date,
executionTime: number,
delivery: {
email: {
status: 'sent' | 'failed' | 'bounced' | 'pending',
email: string,
messageId?: string,
error?: string,
deliveredAt?: Date
},
dashboard: {
updated: boolean,
publishedAt: Date,
url: string
}
},
metadata: {
deliveryTime: number,
errors: Array<{ type: string, message: string }>
}
}Process
-
Initialize: Load email config
-
Read Data: Query database for approved newsletter and user information
-
Email Delivery (if enabled):
- Personalization: Newsletter is already personalized for the user (from Content Generation Agent)
- Template Rendering: Render HTML email with newsletter content
- Feedback Buttons: Embed interactive feedback buttons in each newsletter section
- Each section includes feedback buttons (Like/Dislike, Useful/Irrelevant, or custom options)
- Buttons link to feedback API endpoints with section identifiers
- Feedback is tracked per section and per user
- Sending: Send email to the user (respect rate limits)
- Tracking: Add tracking pixels and links
- Error Handling: Retry failed sends with exponential backoff
- Status Tracking: Record delivery status for the recipient
-
Dashboard Update (if enabled):
- Save newsletter to database
- Update user's newsletter feed
- Interactive Feedback: Render feedback buttons in dashboard view
- Each section displays feedback buttons
- Real-time feedback submission via API
- Visual feedback confirmation after submission
- Invalidate cache if needed
- Send notification (if enabled)
-
Delivery Tracking:
- Record delivery attempts and results
- Update newsletter status in database
- Log metrics for Learning Agent
- Track feedback button impressions and clicks
-
Return: Delivery results