Hybrid n8n + LangGraph Approach - Production-ready AI-powered social media automation
A sophisticated multi-agent system that automates social media content creation, scheduling, and publishing using 7 specialized AI agents working in harmony. Built with the recommended Hybrid n8n + LangGraph architecture for maximum flexibility and speed.
π₯ Dive deeper into this game-changing technology by watching the full video: https://www.youtube.com/watch?v=nfNMl9xLnLw
- β Fast Development: 3-4 weeks vs 2-3 months for pure code
- β Visual Workflows: n8n provides intuitive workflow management
- β Powerful AI: LangGraph handles complex agent reasoning
- β Cost-Effective: ~$80-375/month vs $19,900 RUB/month alternatives
- β Production-Ready: Scalable, maintainable, and extensible
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β n8n Workflows β
β (Orchestration, Scheduling, API Integrations, Triggers) β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β HTTP/Webhooks
ββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend (Port 8000) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β LangGraph Agent Orchestration β β
β β ββββββββββββ ββββββββββββ ββββββββββββ β β
β β βResearcherββ β Marketer ββ βCopywriterββ ... β β
β β ββββββββββββ ββββββββββββ ββββββββββββ β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββ
β PostgreSQL Database β
β (Business Info, Research, Content, Analytics) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- π AI Researcher - Market research, trend analysis, competitor audit
- π AI Marketer - Content strategy, SMM goals, content planning
- βοΈ AI Copywriter - Text generation, variations, A/B testing ideas
- π¨ AI Designer - Visual content, layouts, image generation (DALL-E)
- β AI Moderator - Fact-checking, brand consistency, approval workflow
- π AI Scheduler - Automatic publication via platform APIs
- π AI Analytical - Metrics collection, pattern analysis, ROI/KPI
For a faster setup, see QUICKSTART.md - Get running in 5 minutes!
- Python 3.9+
- Docker & Docker Compose (for n8n and PostgreSQL)
- OpenAI API key
- Platform API credentials (Telegram, VK, etc.)
cd multi_agent_social_media_automation
# Install Python dependencies
pip install -r requirements.txt
# Copy environment template
cp .env.example .env
# Edit .env with your API keys# Start PostgreSQL and n8n
docker-compose up -d
# Wait for services to be ready (30 seconds)# Run database migrations
psql -h localhost -U postgres -d social_media < database/schema.sql
# Or use Python script
python scripts/init_database.py# Start FastAPI backend
uvicorn api.main:app --reload --port 8000- Open http://localhost:5678
- Import workflows from
n8n_workflows/directory - Configure environment variables in n8n settings
- Test each workflow individually
# Trigger via API
curl -X POST http://localhost:8000/api/v1/trigger/researcher
# Or use n8n's manual triggermulti_agent_social_media_automation/
βββ README.md # This file
βββ docker-compose.yml # Docker services (n8n, PostgreSQL)
βββ requirements.txt # Python dependencies
βββ .env.example # Environment variables template
β
βββ langgraph_agents/ # LangGraph agent implementations
β βββ __init__.py
β βββ researcher.py # AI Researcher agent
β βββ marketer.py # AI Marketer agent
β βββ copywriter.py # AI Copywriter agent
β βββ designer.py # AI Designer agent
β βββ moderator.py # AI Moderator agent
β βββ scheduler.py # AI Scheduler agent
β βββ analytical.py # AI Analytical agent
β βββ workflow.py # LangGraph state graph orchestration
β
βββ api/ # FastAPI backend
β βββ __init__.py
β βββ main.py # FastAPI app & routes
β βββ webhooks.py # Webhook endpoints for n8n
β
βββ n8n_workflows/ # n8n workflow JSON files
β βββ 01_ai_researcher.json
β βββ 02_ai_marketer.json
β βββ 03_ai_copywriter.json
β βββ 04_ai_designer.json
β βββ 05_ai_moderator.json
β βββ 06_ai_scheduler.json
β βββ 07_ai_analytical.json
β
βββ database/ # Database schema & migrations
β βββ schema.sql # PostgreSQL schema
β βββ migrations/ # Database migration scripts
β
βββ config/ # Configuration files
β βββ __init__.py
β βββ settings.py # App settings & constants
β
βββ scripts/ # Utility scripts
βββ init_database.py # Database initialization
βββ test_agents.py # Test individual agents
Create a .env file:
# OpenAI API
OPENAI_API_KEY=sk-...
# Database
DATABASE_URL=postgresql://postgres:password@localhost:5432/social_media
# Platform Credentials
TELEGRAM_BOT_TOKEN=...
TELEGRAM_CHAT_ID=...
VK_ACCESS_TOKEN=...
VK_GROUP_ID=...
# n8n
N8N_BASIC_AUTH_USER=admin
N8N_BASIC_AUTH_PASSWORD=yourpassword
N8N_ENCRYPTION_KEY=your-encryption-key
# API
API_HOST=0.0.0.0
API_PORT=8000- Access n8n: http://localhost:5678
- Set Credentials: Go to Settings β Credentials
- Import Workflows: Use the JSON files in
n8n_workflows/ - Configure Webhooks: Update webhook URLs to point to your API
1. Schedule Trigger (n8n)
β
2. AI Researcher (LangGraph via API)
β Research market trends & competitors
β Save to database
β
3. AI Marketer (LangGraph via API)
β Create content strategy
β Define themes & goals
β
4. AI Copywriter (LangGraph via API)
β Generate text content
β Create variations for A/B testing
β
5. AI Designer (n8n OpenAI node)
β Generate images with DALL-E
β Process & optimize images
β
6. AI Moderator (LangGraph via API)
β Review content quality
β Check brand guidelines
β Decision: Approve/Reject
β
7a. If Approved β AI Scheduler (n8n)
β Publish to platforms
β Save published post
β
7b. If Rejected β Loop back to Copywriter
β
8. AI Analytical (LangGraph via API)
β Collect metrics after 24h
β Analyze performance
β Generate recommendations
β Update strategy (feedback loop)
# Trigger AI Researcher
POST /api/v1/agents/researcher
Body: { "business_id": 1 }
# Trigger AI Marketer
POST /api/v1/agents/marketer
Body: { "research_id": 123 }
# Trigger AI Copywriter
POST /api/v1/agents/copywriter
Body: { "strategy_id": 456, "platform": "telegram", "theme": "business_tips" }
# Trigger AI Designer
POST /api/v1/agents/designer
Body: { "content_text": "...", "style": "modern" }
# Trigger AI Moderator
POST /api/v1/agents/moderator
Body: { "content_id": 789, "brand_guidelines": "..." }
# Trigger AI Scheduler
POST /api/v1/agents/scheduler
Body: { "content_id": 789, "platform": "telegram", "scheduled_time": "2024-01-01T10:00:00" }
# Trigger AI Analytical
POST /api/v1/agents/analytical
Body: { "post_id": 101112 }# Receive webhook from n8n
POST /webhook/content-approved
POST /webhook/content-rejected
POST /webhook/post-published
POST /webhook/analytics-readyGET /health
GET /api/v1/status
GET /api/v1/agents/status# Test Researcher
python scripts/test_agents.py --agent researcher
# Test Full Workflow
python scripts/test_agents.py --workflow full# Using curl
curl -X POST http://localhost:8000/api/v1/agents/researcher \
-H "Content-Type: application/json" \
-d '{"business_id": 1}'
# Using Python
python scripts/test_api.py- Open n8n UI
- Click "Execute Workflow" on any workflow
- Check execution logs
- Verify database entries
Key tables:
business_info- Company/business informationresearch_data- Market research resultscontent_strategy- Marketing strategiesgenerated_content- Generated posts (draft/approved/rejected)published_posts- Published contentanalytics- Performance metricsrecommendations- AI-generated recommendations
See database/schema.sql for full schema.
- Create agent file in
langgraph_agents/:
# langgraph_agents/new_agent.py
from langgraph.graph import StateGraph
from typing import TypedDict
class AgentState(TypedDict):
input_data: str
output_data: str
def new_agent_node(state: AgentState) -> AgentState:
# Your agent logic here
return state- Add to workflow in
langgraph_agents/workflow.py - Create API endpoint in
api/main.py - Create n8n workflow in
n8n_workflows/
- Create adapter (reuse from
social_media_automation/platform_adapters/) - Add to scheduler in
langgraph_agents/scheduler.py - Update n8n workflow
06_ai_scheduler.json
- Use managed PostgreSQL (AWS RDS, DigitalOcean, etc.)
- Deploy FastAPI (Gunicorn + Nginx, or Docker)
- Deploy n8n (Docker, or n8n Cloud)
- Set up monitoring (Prometheus, Grafana)
- Configure backups (Database + n8n workflows)
# Build and run
docker-compose -f docker-compose.prod.yml up -d
# View logs
docker-compose logs -f.env.development- Local development.env.staging- Staging environment.env.production- Production environment
- Performance Reports:
/api/v1/analytics/report - Agent Metrics: Track execution times, success rates
- Content Performance: Engagement rates, top posts
- Cost Tracking: API usage, costs per post
- Application Logs:
logs/app.log - Agent Logs:
logs/agents.log - API Logs: FastAPI automatic logging
Configure alerts for:
- Failed agent executions
- High API costs
- Low engagement rates
- Database connection issues
Monthly Costs (Estimated):
- n8n: $0 (self-hosted) or $20 (cloud)
- OpenAI API: $50-200 (depending on volume)
- DALL-E: $20-100 (image generation)
- PostgreSQL: $0-25 (self-hosted or managed)
- Server/Hosting: $10-50 (VPS)
Total: ~$80-375/month
Cost per Post:
- Text only: ~$0.03-0.06 (GPT-4)
- With image: ~$0.07-0.14 (GPT-4 + DALL-E)
n8n not starting:
# Check Docker logs
docker-compose logs n8n
# Verify port 5678 is available
netstat -an | grep 5678Database connection errors:
# Test connection
psql -h localhost -U postgres -d social_media
# Check DATABASE_URL in .envAPI not responding:
# Check if FastAPI is running
curl http://localhost:8000/health
# Check logs
tail -f logs/app.logAgent execution failures:
- Check OpenAI API key
- Verify database has required data
- Check agent logs in
logs/agents.log
- Development Approaches - Detailed comparison
- n8n Implementation Guide - n8n setup
- API Reference - Full API docs
- Agent Details - Agent specifications
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is provided as-is for educational and commercial use.
- Issues: Open a GitHub issue
- Questions: Check documentation or open a discussion
- Commercial Support: Contact for enterprise support
Ready to automate your social media? Start with the Quick Start guide above! π