AI-Powered Marketing Campaign Generator & Budget Allocator
💡 The Spark
We've all been there - staring at a spreadsheet of customer segments, trying to figure out which ones deserve our marketing budget. Should we target the high-value but risky churners? Or play it safe with the stable, engaged customers? And then there's the content generation part - writing personalized emails, SMS messages, and push notifications for hundreds of different customer groups. It's exhausting.
During one of our late-night brainstorming sessions (fueled by way too much coffee), we realized: what if AI could do the heavy lifting? Not just generate content, but actually think about budget allocation strategy? That's when this project was born.
🎯 What We Built
We created a two-agent system that takes customer segmentation data and transforms it into a complete, ready-to-send marketing campaign with intelligent budget allocation:
Agent 1: Content Generation Agent
- Takes 250 customer segments with rich behavioral data (CLV, churn risk, preferences, purchase history)
- Generates personalized content across 3 channels (email, SMS, push notifications)
- Creates 2 A/B testing variations per segment/channel combo
- Output: 1,500 unique, personalized content pieces
Agent 2: Budget Allocation Agent
- Analyzes all generated content with segment characteristics
- Uses AI reasoning to strategically distribute marketing budget
- Considers ROI potential, reach, confidence scores, and business goals
- Provides transparent reasoning for every allocation decision
Full-Stack Dashboard
- React.js frontend for campaign management
- Real-time progress tracking during content generation
- Interactive budget allocation with customizable strategies
- Preview content in realistic mockups (email client, SMS bubbles, push notifications)
- Stage and simulate campaign sends
🛠️ How We Built It
The Architecture Challenge
Initially, we thought we'd need AWS Bedrock Agents with Knowledge Bases - you know, the fancy setup with OpenSearch Serverless and all that. But here's where reality hit us: we only had API keys, no admin permissions to create IAM roles or complex infrastructure.
Our "aha" moment: Why not just use direct Bedrock API calls? Turns out, it's actually better for our use case:
- No complex infrastructure setup
- Faster execution (no agent reasoning overhead)
- Full control over prompts
- Lower costs (no OpenSearch fees)
So we built everything around bedrock-runtime.invoke_model() - simple, effective, and it works with just API keys.
The Content Generation Engine
This was probably our biggest technical challenge. Generating 1,500 content items sequentially would take hours. We needed parallelization, but AWS Bedrock calls are I/O-bound and need careful thread management.
Here's what we did:
# Key implementation details:
- ThreadPoolExecutor for concurrent Bedrock API calls
- One Bedrock client per thread (thread-local storage)
- Thread-safe locks for shared resources (content list, cost tracking)
- Configurable worker count (we found 10-15 workers optimal)
The results? 5-10x speedup. What took 100 minutes sequentially now takes 20 minutes. For a hackathon deadline, that was a game-changer.
We also implemented:
- Campaign tracking - Each generation run gets a unique ID, so you can run multiple campaigns
- Rich prompt engineering - We embed segment characteristics, product data, and marketing best practices directly into prompts (no separate Knowledge Base needed!)
- Real-time progress monitoring - Live progress updates with success/failure tracking
- Cost tracking - Token usage and estimated AWS costs per campaign
The Budget Allocation Agent
This is where things got interesting. We didn't want just a simple "sort by CLV and allocate top-down" algorithm. We wanted the AI to actually reason about allocation strategy.
We use Amazon Nova Pro (or Claude) with a carefully crafted prompt that includes:
- All segment data (CLV, churn risk, conversion rates, engagement metrics)
- Generated content for each segment
- Budget constraints and business goals
- Channel cost structures
The model responds with:
- Strategic reasoning (in plain English, not just numbers)
- Detailed allocation per segment/channel
- Expected ROI calculations
- Confidence scores
The clever part: We calculate ROI using realistic formulas based on:
- Channel-specific open/engagement rates
- Segment conversion history
- Customer lifetime value
- Campaign-specific factors
The AI sees these calculations and uses them to make strategic decisions. It's like having a marketing analyst who can process hundreds of segments instantly.
The Frontend Experience
We built a React dashboard that makes the whole workflow intuitive:
- Campaign Creation - Start content generation with a campaign name
- Progress Tracking - Real-time status updates with progress bars
- Campaign Overview - Browse all generated campaigns, see costs and metrics
- Budget Allocation - Interactive form with strategy selection, budget input, and ROI thresholds
- Results Visualization - Charts, tables, and AI reasoning display
- Content Preview - See actual emails/SMS/push in realistic mockups
- Staging & Sending - Filter items, stage for sending, simulate or send for real
The polling mechanism was fun to implement - we hit the status endpoint every 5 seconds during generation, updating the UI with live progress. It feels snappy and gives users confidence that things are actually happening.
🧗 Challenges We Faced
1. The Permission Problem
Challenge: We wanted to use Bedrock Agents but didn't have IAM permissions. Solution: Pivoted to direct API calls. Turns out this was actually better - simpler, faster, and more transparent.
2. The Speed Problem
Challenge: Sequential content generation was painfully slow. Solution: Implemented parallel execution with ThreadPoolExecutor. Lots of debugging around thread safety and proper error handling.
3. The "What's Realistic?" Problem
Challenge: How do we calculate ROI without actual campaign performance data? Solution: We researched industry benchmarks and built a realistic simulation model. Email open rates around 20%, SMS at 98%, push at 10% engagement - based on real marketing data.
4. The Prompt Engineering Marathon
Challenge: Getting consistent, high-quality content from the AI. Solution: Lots of iteration. We learned that being very specific helps - exact character counts, clear structure requirements, JSON output format. Our prompts are now 500+ tokens but produce reliable results.
5. The "Too Much Data" Problem
Challenge: Displaying 1,500 content items in a UI without overwhelming users. Solution: Heavy use of filtering, pagination, and preview samples. Show the most important info upfront, let users drill down when needed.
6. The Integration Dance
Challenge: Keeping frontend and backend in sync during active development. Solution: FastAPI's automatic OpenAPI docs were a lifesaver. We could test endpoints immediately and see exact request/response formats.
📚 What We Learned
Technical Lessons:
- Sometimes the "simpler" solution is actually better (direct API vs. agents)
- Parallel I/O operations need careful thread safety management
- Good prompts are like good code - specific, structured, with clear requirements
- Real-time updates make UIs feel way more responsive (even if it's just polling)
- FastAPI + React is a solid combo for rapid prototyping
Non-Technical Lessons:
- Start simple, add complexity only when needed
- Test with real-ish data early - synthetic data helped us catch issues
- Document as you go (our API guide saved us so much time)
- When stuck, sometimes you just need to talk it through with the team (rubber duck debugging works!)
The "Wow" Moments:
- Seeing the first parallel generation complete in 2 minutes instead of 15
- When the budget allocation AI explained its reasoning better than we could
- That moment when the preview content actually looked like real marketing emails
- Realizing our cost tracking showed we were spending way less than expected
🚀 What's Next?
If we had more time (don't we all say that?), here's what we'd love to add:
- A/B Test Winner Selection - Automatically pick the better performing variation
- Historical Performance Tracking - Store actual campaign results and improve allocations over time
- ESP Integration - Connect to SendGrid, Twilio, etc. for actual sending
- Multi-Campaign Comparison - See how different strategies performed
- Dynamic Budget Reallocation - Adjust budget mid-campaign based on performance
- More Channels - WhatsApp, Instagram DMs, in-app messages
🎉 The Takeaway
Building this was a blast. We went from "wouldn't it be cool if..." to a working system that actually generates personalized content and allocates budget intelligently. Sure, there were moments of frustration (thread safety bugs at 2 AM, anyone?), but seeing it all come together was incredibly satisfying.
Thanks for checking out our project! We're proud of what we built and learned a ton along the way.
Tech Stack:
- Backend: Python, FastAPI, boto3, ThreadPoolExecutor
- AI: AWS Bedrock (Amazon Nova Pro, Claude 3.5 Sonnet)
- Frontend: React.js, Recharts, TailwindCSS
- Storage: Local JSON files (easily switchable to DynamoDB)
- API: REST with OpenAPI documentation
Team: Three developers with too much coffee
Built With
- amazon-web-services
- boto3
- fastapi
- python
- react
- tailwindcss
Log in or sign up for Devpost to join the conversation.