AI-powered marketing campaign generation using CrewAI and Groq
Create complete, research-backed marketing campaigns in minutes. Four specialized AI agents work together sequentially to produce market research, compelling copy, visual direction, and an executive brief—all from a single product description.
- 🔍 Research Agent — Analyzes market trends, competitive landscape, and audience personas
- ✍️ Copywriter Agent — Generates campaign taglines, channel-specific copy, email subjects, and hashtags
- 🎨 Art Director Agent — Creates visual direction, mood descriptions, and image generation prompts
- 📋 Manager Agent — Synthesizes all outputs into a cohesive executive brief with KPIs and implementation timeline
- 📦 Multi-Format Output — Saves campaigns as Markdown briefs and structured JSON
- ⚡ Free LLM Provider — Uses Groq's fast API with generous free-tier limits
- Python 3.11+
- Groq API Key (free tier: console.groq.com)
- Serper API Key (optional, for live trend research)
# Create virtual environment
py -3.11 -m venv .venv
# Activate
.\.venv\Scripts\Activate.ps1
# Install dependencies
pip install -e ".[dev]"# Copy template
cp .env.example .envEdit .env and add your API keys:
GROQ_API_KEY=gsk_your_groq_api_key_here
GROQ_MODEL=llama-3.3-70b-versatile
GROQ_TEMPERATURE=0.7
GROQ_MAX_TOKENS=1400
# Optional: auto-retry on Groq TPM rate limits
GROQ_RATE_LIMIT_RETRIES=3
GROQ_RETRY_BASE_SECONDS=8
GROQ_RETRY_MAX_SECONDS=45
# Optional: for live market research
SERPER_API_KEY=your_serper_api_key_here# Demo with pre-configured product
python -m src.main --demo
# Interactive mode (enter your own product)
python -m src.mainOutputs saved to: src/output/{product_name}_{timestamp}.{md,json}
Want to see the result before running it? A complete campaign brief from a real run (AeroFlow Pro smart air purifier) is committed at examples/sample_campaign.md with the structured JSON at examples/sample_campaign.json.
multi_agent_campaign_creator/
├── src/
│ ├── agents/
│ │ ├── base_agent.py # BaseAgent class + get_llm() factory
│ │ ├── research_agent.py # Market research specialist
│ │ ├── copywriter_agent.py # Copy & messaging specialist
│ │ ├── art_director_agent.py # Visual direction specialist
│ │ └── manager_agent.py # Campaign strategy & rollout
│ │
│ ├── tools/
│ │ ├── trend_research_tool.py # Market trends (live or simulated)
│ │ ├── competitor_analysis_tool.py # Competitive landscape
│ │ ├── copy_evaluation_tool.py # Copy quality scoring
│ │ └── image_prompt_tool.py # DALL-E & Stable Diffusion prompts
│ │
│ ├── models/
│ │ └── campaign_models.py # Pydantic models (CampaignRequest, CopyPackage, etc.)
│ │
│ ├── tasks/
│ │ └── campaign_tasks.py # Task factory for CrewAI integration
│ │
│ ├── workflow/
│ │ └── crew_workflow.py # CampaignCrew orchestrator
│ │
│ ├── config.py # Settings & environment loading
│ ├── main.py # CLI entry point
│ └── __init__.py
│
├── tests/
│ ├── test_agents.py # Agent initialization & execution
│ ├── test_tools.py # Tool output validation
│ ├── test_workflow.py # Workflow & task wiring
│ ├── conftest.py # Pytest fixtures
│ └── __init__.py
│
├── output/ # Generated campaign outputs
├── .env.example # Environment template
├── pyproject.toml # Project metadata & dependencies
├── README.md # This file
└── .gitignore # Git ignore patterns
User Input (CampaignRequest)
↓
[Research Agent] → Market Research Output
↓
[Copywriter Agent] (uses Research context) → Copy Package
↓
[Art Director Agent] (uses Research + Copy context) → Visual Direction
↓
[Manager Agent] (uses all prior outputs) → Final Campaign Brief
↓
Save to: markdown + JSON
Each agent:
- Receives context from prior agents via CrewAI's task dependencies
- Has access to specialized tools
- Uses Groq's fast LLM (llama-3.3-70b-versatile by default)
- Input:
CampaignRequest— product name, audience, goals, channels, brand voice - Output:
CampaignBrief— Full campaign with research, copy, visuals, strategy, and KPIs
The same four agents can be driven by a LangGraph state machine instead of CrewAI's internal sequencer. This separates control flow from execution the way production agentic systems do:
- LangGraph owns the control flow — which agent runs next, how state is threaded between stages, and where the pipeline halts on failure.
- CrewAI owns the execution — each graph node runs one CrewAI
Agentinside a single-taskCrew.
[Research] → [Copywriter] → [Art Director] → [Manager] → [END]
│ │ │
(error) (error) (error) ──────────────→ [END]
Each stage records its output (or an error) into a shared CampaignState. A
conditional edge (should_continue) advances to the next agent on success or
routes straight to END if any stage failed, so a provider outage halts the
run cleanly instead of cascading.
Run it with the --langgraph flag:
python -m src.main --demo --langgraphImplementation: src/workflow/langgraph_workflow.py.
The default CrewAI-sequenced runner remains the standard path.
| Variable | Required | Description |
|---|---|---|
GROQ_API_KEY |
✅ Yes | Your Groq API key from console.groq.com |
GROQ_MODEL |
LLM model name (default: llama-3.3-70b-versatile) |
|
GROQ_TEMPERATURE |
LLM temperature: 0-1 (default: 0.7, higher = more creative) | |
GROQ_MAX_TOKENS |
Token cap per LLM call (default: 1400) |
|
GROQ_RATE_LIMIT_RETRIES |
Retry count for Groq 429 / rate_limit_exceeded errors (default: 3) |
|
GROQ_RETRY_BASE_SECONDS |
Base seconds for exponential fallback backoff (default: 8) |
|
GROQ_RETRY_MAX_SECONDS |
Maximum wait per retry attempt (default: 45) |
|
SERPER_API_KEY |
❌ No | For live Google Trends; tools use deterministic simulation if not set |
OUTPUT_DIR |
❌ No | Directory for campaign outputs (default: src/output) |
python -m src.main --demoPreset product: AeroFlow Pro (AI-powered air purifier)
Output:
- Research on market trends (indoor air quality, smart home adoption, wellness)
- Competitor analysis (Dyson, Levoit, Molekule)
- Channel-specific copy (social media, email, display ads, influencer)
- Visual direction with image prompts
- 30-day implementation timeline
python -m src.mainYou'll be prompted for:
- Product name → "Smart Water Bottle"
- Description → "Tracks hydration with app integration"
- Target audience → "Fitness enthusiasts, health-conscious millennials"
- Campaign goals → "10k units in Q1, 3% engagement rate"
- Channels → social_media, email, influencer, content_marketing
- Brand voice → professional, casual, playful, luxury, etc.
- Additional context → Competitors, launch timeline, budget constraints
Run the test suite (25 tests, ~2-3 seconds):
# All tests
pytest tests/ -v
# Specific test file
pytest tests/test_agents.py -v
# With coverage
pytest tests/ --cov=src --cov-report=htmlTest Coverage:
- ✅ Agent initialization and basic execution
- ✅ Tool output validation (trends, competitor analysis, copy scoring)
- ✅ Task factory and CrewAI wiring
- ✅ Workflow integration
Groq free tier: 12,000 tokens per minute (TPM)
Solution:
- Wait and retry (the app now auto-retries up to
GROQ_RATE_LIMIT_RETRIEStimes) - Upgrade to Groq Dev Tier for higher limits
- Use a different model (try
gemma2-9b-itfor faster/smaller outputs) - Lower
GROQ_MAX_TOKENS(e.g.,900) to reduce TPM pressure
Error: GROQ_API_KEY not found in environment
Solution:
echo "GROQ_API_KEY=your_key_here" >> .envModuleNotFoundError: No module named 'crewai'
Solution:
pip install -e ".[dev]"
pip install --upgrade crewai langchain-groq litellmIf tools return deterministic placeholders instead of live data, set SERPER_API_KEY in .env:
SERPER_API_KEY=your_serper_api_keyGet free API key: serper.dev
| Agent | Role | Temperature | Tools |
|---|---|---|---|
| Research | Senior Market Research Analyst | 0.3 (analytical) | TrendResearchTool, CompetitorAnalysisTool |
| Copywriter | Senior Creative Copywriter | 0.7 (creative) | CopyEvaluationTool |
| Art Director | Senior Art Director | 0.6 (balanced) | ImagePromptGeneratorTool |
| Manager | Campaign Strategy Lead | 0.4 (strategic) | None |
CampaignRequest— User input (product, audience, goals, channels, tone)CampaignBrief— Final output (research, copy, visuals, strategy)MarketResearch— Trends, competitors, personas, opportunitiesCopyPackage— Tagline, elevator pitch, channel copy, email subjects, hashtagsVisualDirection— Brand identity, key visuals, image prompts
Contributions welcome! Areas for enhancement:
- Retry logic with exponential backoff for rate limits
- Support for additional LLM providers (Claude, OpenAI, Mistral)
- Web UI for campaign builder
- A/B testing framework for copy variants
- Integration with Canva/Figma for asset generation
- Database storage for campaign history
MIT
Questions or Issues? Check the Troubleshooting section or review test files for usage examples.