Message Sequence Agent
Purpose: AI-powered message sequence generation and approval system
Model: Vercel Lead Agent architecture adapted for GTM campaigns
Status: Reference Architecture
Last Updated: 2026-01-26
Overview
Message Sequence Agent is an AI-powered system for generating personalized, multi-step outreach sequences across different GTM campaigns. It uses durable workflows, AI-powered personalization, and human-in-the-loop Slack approval before sending.
This serves as a reference architecture to be adapted to your specific campaigns and workflows.
Key Features
✅ Immediate Response
Returns success to trigger upon campaign initiation
🔄 Durable Workflows
Uses workflow orchestration for reliable multi-step execution
🤖 Deep Research Agent
Conducts comprehensive research on prospects using AI SDK Agent class
📧 Sequence Generation
Generates personalized multi-step sequences with AI SDK generateObject
👤 Human-in-the-Loop
Sends to Slack for human approval before sending sequences
📊 Multi-Campaign Support
Supports multiple campaign types with different sequence strategies
Architecture
Campaign Trigger
↓
start(workflow) ← (Workflow DevKit)
↓
Research Agent ← (AI SDK Agent)
- Prospect research
- Company intelligence
- Personalization signals
↓
Campaign Classifier ← (AI SDK generateObject)
- Identify campaign type
- Select appropriate sequence
- Determine persona
↓
Sequence Generator ← (AI SDK generateObject)
- Generate multi-step messages
- Personalize each touchpoint
- Apply campaign playbook
↓
Slack Approval ← (Slack Bolt + Vercel adapter)
- Display sequence preview
- Approve/Edit/Reject buttons
- Edit in Slack modal
↓
Schedule & Send ← (On approval)
- Queue messages
- Track engagement
- Update CRM
Tech Stack
| Component | Technology |
|---|---|
| Framework | Next.js 16 |
| Durable Execution | Workflow DevKit |
| AI | Vercel AI SDK with AI Gateway |
| Human-in-the-Loop | Slack Bolt + Vercel Slack Bolt adapter |
| Research | Exa.ai, Perplexity API |
| CRM Integration | HubSpot API |
| Database | Vercel Postgres (workflow state) |
Campaign Types
1. Event Follow-Up
- Trigger: Event attendance, booth visit, meeting log
- Segments: Booth Visitor, Panelist, VIP Dinner, Meeting Log, General Attendee
- Sequence: 3-5 touch points over 14 days
- Personalization: Event context, conversation topics, engagement details
2. Mutual Introduction
- Trigger: Intro request from mutual connection
- Segments: Warm intro, cold intro with context
- Sequence: 2-3 touch points over 7 days
- Personalization: Mutual connection, referral context, shared interests
3. Partnership Outreach
- Trigger: Partner rep engagement, co-sell opportunity
- Segments: Cold rep, engaged rep, active deal support
- Sequence: 4-6 touch points over 21 days
- Personalization: Partner context, account research, value props
4. Product Launch
- Trigger: New feature release, product update
- Segments: Active users, churned users, prospects
- Sequence: 3-4 touch points over 10 days
- Personalization: Usage patterns, feature fit, use cases
5. Content Syndication
- Trigger: New blog post, case study, whitepaper
- Segments: By persona, by industry, by engagement history
- Sequence: 2-3 touch points over 7 days
- Personalization: Content relevance, industry fit, pain points
6. Re-engagement
- Trigger: Inactive prospect, stalled deal, churned customer
- Segments: By last engagement type, by stage
- Sequence: 3-5 touch points over 21 days
- Personalization: Last interaction, objections, new value
Workflow Steps
Step 1: Research Agent
Purpose: Gather intelligence for personalization
Inputs:
- Prospect name, email, company
- Campaign trigger context
- Historical engagement data
AI Agent Tools:
searchWeb()- Web search via Exa.aiqueryKnowledgeBase()- Search internal docsfetchCompanyData()- Company intelligenceanalyzeLinkedIn()- LinkedIn profile analysisgetEngagementHistory()- Past interactions
Output:
{
prospect: {
name: string;
title: string;
company: string;
linkedin: string;
};
intelligence: {
companyInfo: string;
recentNews: string[];
painPoints: string[];
competitors: string[];
};
personalization: {
signals: string[];
context: string;
relevance: string;
};
engagementHistory: {
lastContact: Date;
interactions: number;
stage: string;
};
}Step 2: Campaign Classifier
Purpose: Identify campaign type and select sequence strategy
Uses: AI SDK generateObject with schema
Output:
{
campaignType: 'event-follow-up' | 'mutual-intro' | 'partnership' | 'product-launch' | 'content-syndication' | 're-engagement';
segment: string; // Campaign-specific segment
persona: 'executive' | 'practitioner' | 'champion' | 'blocker';
sequenceLength: number; // 2-6 touchpoints
priority: 'high' | 'medium' | 'low';
reasoning: string;
}Step 3: Sequence Generator
Purpose: Generate personalized multi-step sequence
Uses: AI SDK generateObject with campaign playbook context
Inputs:
- Research report
- Campaign classification
- Campaign playbook (from memory)
- Message templates
Output:
{
sequence: [
{
step: 1;
channel: 'email' | 'linkedin' | 'slack';
timing: 'immediate' | 'day-2' | 'day-7' | 'day-14';
subject: string;
body: string;
cta: string;
personalizationNotes: string[];
},
// ... additional steps
];
fallbackSequence: [...]; // If no response
metadata: {
generatedAt: Date;
model: string;
confidence: number;
};
}Step 4: Slack Approval
Purpose: Human review before sending
Slack Message Format (Block Kit):
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "📧 New Sequence: [Campaign Type]"
}
},
{
"type": "section",
"fields": [
{"type": "mrkdwn", "text": "*Prospect:*\n[Name] @ [Company]"},
{"type": "mrkdwn", "text": "*Campaign:*\n[Type]"},
{"type": "mrkdwn", "text": "*Segment:*\n[Segment]"},
{"type": "mrkdwn", "text": "*Steps:*\n[N] touchpoints"}
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Step 1 (Immediate):*\n```\nSubject: [Subject]\n\n[Body Preview]\n```"
}
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {"type": "plain_text", "text": "✅ Approve & Send"},
"style": "primary",
"value": "approve"
},
{
"type": "button",
"text": {"type": "plain_text", "text": "✏️ Edit"},
"value": "edit"
},
{
"type": "button",
"text": {"type": "plain_text", "text": "❌ Reject"},
"style": "danger",
"value": "reject"
}
]
}
]
}Edit Modal: Opens Slack modal to modify sequence before sending
Step 5: Schedule & Send
Purpose: Queue and send approved sequence
Actions:
- Store sequence in CRM (HubSpot)
- Schedule messages based on timing
- Set up engagement tracking
- Monitor responses for triggers
- Update workflow state
Project Structure
message-sequence-agent/
├── app/
│ ├── api/
│ │ ├── trigger/ # Campaign trigger endpoint
│ │ ├── slack/ # Slack webhook handler
│ │ └── webhook/ # CRM/external webhooks
│ └── page.tsx # Dashboard
├── lib/
│ ├── services/
│ │ ├── research.ts # Research agent
│ │ ├── classifier.ts # Campaign classification
│ │ ├── generator.ts # Sequence generation
│ │ ├── sender.ts # Email/message sending
│ │ └── crm.ts # CRM integration
│ ├── slack.ts # Slack integration
│ ├── types.ts # TypeScript schemas
│ └── playbooks/ # Campaign playbooks (imported)
│ ├── event-follow-up.ts
│ ├── mutual-intro.ts
│ ├── partnership.ts
│ └── ...
├── workflows/
│ └── sequence/
│ ├── index.ts # Main workflow
│ └── steps.ts # Workflow steps
└── memory/ # Campaign playbooks (markdown)
├── event-follow-up-playbook.md
├── mutual-intro-playbook.md
├── partnership-playbook.md
└── ...
Configuration
Environment Variables
# Vercel AI Gateway
AI_GATEWAY_API_KEY=xxx
# Slack Bot
SLACK_BOT_TOKEN=xoxb-xxx
SLACK_SIGNING_SECRET=xxx
SLACK_CHANNEL_ID=xxx
# Research APIs
EXA_API_KEY=xxx
PERPLEXITY_API_KEY=xxx
# CRM
HUBSPOT_API_KEY=xxx
# Database
POSTGRES_URL=xxxKey AI Prompts
Research Agent System Prompt
const RESEARCH_AGENT_PROMPT = `
You are a GTM research agent for Brainforge, an embedded data & analytics consultancy.
Your job is to research prospects and identify personalization signals for outreach.
Focus on:
1. Company intelligence (stage, funding, tech stack, recent news)
2. Prospect background (role, tenure, previous companies)
3. Pain points (data infrastructure, analytics, team gaps)
4. Personalization opportunities (mutual connections, shared interests, relevant content)
Be thorough but concise. Prioritize actionable insights over general information.
`;Campaign Classifier Prompt
const CLASSIFIER_PROMPT = `
Classify this campaign based on the trigger context and research report.
Campaign Types:
- event-follow-up: Post-event outreach (conferences, meetings, dinners)
- mutual-intro: Warm introduction from mutual connection
- partnership: Partner rep engagement or co-sell
- product-launch: New feature announcement
- content-syndication: Blog/case study sharing
- re-engagement: Reactivate inactive prospect/customer
Segments vary by campaign type. Use the research report to determine the most relevant segment.
Persona Types:
- executive: C-level, VPs (focus on ROI, outcomes, strategic value)
- practitioner: Engineers, analysts (focus on technical depth, use cases)
- champion: Internal advocate (focus on enablement, success stories)
- blocker: Skeptical or resistant (focus on risk mitigation, proof points)
Select sequence length (2-6 steps) based on:
- Engagement history (more history = shorter sequence)
- Persona (executives prefer shorter)
- Campaign type (events need faster follow-up)
`;Sequence Generator Prompt
const GENERATOR_PROMPT = `
Generate a personalized, multi-step outreach sequence using the campaign playbook.
Guidelines:
1. Apply playbook structure and messaging principles
2. Use research insights for personalization (not generic)
3. Match persona tone and style
4. Include specific CTAs for each step
5. Follow timing recommendations from playbook
6. Add personalization notes for human reviewer
Remember: Not "Great to meet you!" — narrative-based messaging with specific context.
`;Extensibility
Adding New Campaign Types
-
Create playbook markdown in
memory/# [Campaign Name] Playbook ## Overview ## Segmentation Strategy ## Persona-Based Messaging ## Multi-Step Sequences ## Examples -
Add campaign type to
lib/types.tsexport type CampaignType = | 'event-follow-up' | 'my-new-campaign'; -
Import playbook to
lib/playbooks/my-new-campaign.tsimport playbookMd from '@/memory/my-new-campaign-playbook.md'; export const playbookContext = playbookMd; -
Update classifier to recognize new campaign type
-
Test with sample triggers
Adding New Sequence Steps
Modify the sequence schema in lib/types.ts:
export const sequenceStepSchema = z.object({
step: z.number(),
channel: z.enum(['email', 'linkedin', 'slack', 'phone']),
timing: z.string(),
subject: z.string().optional(),
body: z.string(),
cta: z.string(),
attachments: z.array(z.string()).optional(),
personalizationNotes: z.array(z.string()),
});Adding New Research Tools
Add tools to the research agent in lib/services/research.ts:
const agent = new Agent({
model: openai('gpt-4'),
tools: {
searchWeb,
queryKnowledgeBase,
fetchCompanyData,
analyzeLinkedIn,
getEngagementHistory,
// Add new tool here
myCustomTool: tool({
description: 'Description for AI',
parameters: z.object({ ... }),
execute: async ({ params }) => {
// Implementation
},
}),
},
});Human-in-the-Loop Best Practices
Approval Workflow
-
Always show full context in Slack message
- Prospect details
- Campaign type and reasoning
- Full sequence preview (or first 2 steps)
-
Make editing easy
- Open modal with editable fields
- Preserve formatting
- Save edits before sending
-
Track approval metrics
- Approval rate by campaign type
- Common edits/rejections
- Use feedback to improve prompts
-
Timeout handling
- Auto-reject after 24 hours
- Send reminder after 4 hours
- Allow manual trigger later
Quality Control
- Review rejection patterns to improve generation
- A/B test different prompts and templates
- Monitor response rates by campaign and segment
- Iterate on playbooks based on what works
Success Metrics
Generation Quality
- Approval Rate: Target 80%+ on first generation
- Edit Rate: <30% require significant edits
- Rejection Rate: <10% rejected outright
Sequence Performance
- Open Rate: Target 40-50% on initial email
- Response Rate: Target 15-20% across sequence
- Meeting Booked: Target 8-12% conversion
- Opt-out Rate: <2%
Efficiency
- Time to Generate: <2 minutes end-to-end
- Human Review Time: <3 minutes per sequence
- Sequences/Week: Target 50-100 sequences
Related Documentation
License
Reference architecture for internal use.