Loading...
Loading...
This is a comprehensive multi-agent system for Facebook page management using CrewAI and Google Gemini AI.
# Facebook Gemini AI Agents - Complete Implementation
This is a comprehensive multi-agent system for Facebook page management using CrewAI and Google Gemini AI.
## π Features
### AI Agents
- **Content Creation Agent**: Auto-generates engaging posts, captions, and hashtags
- **Customer Service Agent**: Automated Messenger responses and lead generation
- **Analytics Agent**: Performance monitoring and content optimization
### Capabilities
- β
Intelligent content generation with Gemini AI
- β
Automated customer service with intent recognition
- β
Performance analytics and insights
- β
Facebook API integration (Pages, Messenger, Marketing)
- β
Web dashboard for agent management
- β
RESTful API with comprehensive endpoints
- β
Docker containerization support
- β
Comprehensive testing suite
## π Prerequisites
Before running the application, ensure you have:
1. **Facebook Developer Account** with:
- Facebook App with Page Management permissions
- Page Access Token
- App ID and App Secret
2. **Google Cloud Account** with:
- Gemini API key
- Enabled Generative AI API
3. **Python 3.11+** installed
## π§ Installation
### 1. Clone and Setup
```bash
git clone <repository-url>
cd facebook-gemini-agents
pip install -r requirements.txt
```
### 2. Configure Environment
```bash
cp .env.example .env
# Edit .env with your API credentials
```
### 3. Configure API Keys
Edit `.env` file with your credentials:
```env
# Facebook API
FACEBOOK_APP_ID=your_app_id
FACEBOOK_APP_SECRET=your_app_secret
FACEBOOK_ACCESS_TOKEN=your_access_token
FACEBOOK_PAGE_ID=your_page_id
# Google Gemini
GOOGLE_API_KEY=your_gemini_api_key
```
## π Quick Start
### Run the Application
```bash
# Start the API server
python src/api/main.py
# Or use the CLI
python main.py content-generate --topic "summer vacation ideas"
```
### Access the Web Interface
Open your browser to: `http://localhost:8000/web/`
## π Usage Examples
### Content Generation
```python
from src.agents.content_agent import content_agent
# Generate a Facebook post
post = content_agent.create_post(
topic="summer vacation",
tone="friendly",
length="medium"
)
print(post['content'])
print(post['hashtags'])
```
### Customer Service
```python
from src.agents.customer_service_agent import customer_service_agent
# Handle customer message
result = customer_service_agent.handle_message(
message="I need help with my order",
sender_info={'name': 'John'}
)
print(result['response'])
print(f"Intent: {result['intent']}")
```
### Analytics
```python
from src.agents.analytics_agent import analytics_agent
# Analyze page performance
insights = analytics_agent.analyze_page_performance(
page_id="your_page_id",
date_range="last_30d"
)
print(insights['insights_summary'])
```
## π API Endpoints
### Content Agent
- `POST /api/agents/content/generate` - Generate content
- `POST /api/agents/content/optimize` - Optimize existing content
- `POST /api/agents/content/calendar` - Generate content calendar
### Customer Service Agent
- `POST /api/agents/service/respond` - Handle customer message
- `POST /api/agents/service/quick-reply` - Handle quick reply
- `GET /api/agents/service/metrics` - Get service metrics
### Analytics Agent
- `POST /api/agents/analytics/insights` - Get page insights
- `POST /api/agents/analytics/trending` - Get trending content
- `POST /api/agents/analytics/schedule` - Get posting schedule
### Facebook Integration
- `GET /api/facebook/pages` - List Facebook pages
- `POST /api/facebook/post` - Create Facebook post
- `GET /api/facebook/posts/{page_id}` - Get page posts
## π§ͺ Testing
### Run Tests
```bash
# Run all tests
pytest
# Run specific test file
pytest tests/test_agents.py -v
# Run with coverage
pytest --cov=src tests/
```
### Test Coverage
The test suite includes:
- β
Unit tests for all agents
- β
API endpoint testing
- β
Integration tests
- β
Mock external services
- β
Error handling tests
## π³ Docker Deployment
### Build and Run
```bash
# Build and start services
docker-compose up -d
# Check logs
docker-compose logs -f
# Stop services
docker-compose down
```
### Services
- **app**: Main application (port 8000)
- **redis**: Redis cache (port 6379)
- **nginx**: Reverse proxy (port 80)
## π Project Structure
```
facebook-gemini-agents/
βββ src/
β βββ agents/
β β βββ base_agent.py # Base agent class
β β βββ content_agent.py # Content creation agent
β β βββ customer_service_agent.py # Customer service agent
β β βββ analytics_agent.py # Analytics agent
β βββ config/
β β βββ settings.py # Configuration settings
β βββ tools/
β β βββ facebook_tools.py # Facebook API client
β β βββ gemini_tools.py # Gemini AI tools
β β βββ utils.py # Utility functions
β βββ api/
β β βββ main.py # FastAPI application
β βββ web/
β βββ index.html # Web dashboard
βββ tests/
β βββ test_agents.py # Agent tests
β βββ test_api.py # API tests
βββ requirements.txt # Python dependencies
βββ docker-compose.yml # Docker services
βββ Dockerfile # App container
βββ main.py # CLI entry point
```
## π§ Configuration
### Agent Settings
Configure agent behavior in `src/config/settings.py`:
```python
AGENT_CONFIGS = {
'content_agent': {
'model': 'gemini-pro',
'temperature': 0.7,
'max_tokens': 1000,
},
'customer_service_agent': {
'model': 'gemini-pro',
'temperature': 0.3,
'max_tokens': 500,
},
'analytics_agent': {
'model': 'gemini-pro',
'temperature': 0.1,
'max_tokens': 2000,
}
}
```
### Facebook API Settings
Configure Facebook API endpoints and permissions in the same file.
## π¨ Error Handling
The system includes comprehensive error handling:
- **API Errors**: Graceful handling of Facebook API errors
- **Network Issues**: Retry mechanisms for failed requests
- **Validation**: Input validation for all endpoints
- **Logging**: Detailed logging for debugging
- **Fallback Responses**: Backup responses when AI fails
## π Security
Security measures include:
- **Environment Variables**: All secrets in environment variables
- **Input Sanitization**: Clean user inputs
- **Rate Limiting**: Prevent API abuse
- **Webhook Verification**: Secure Facebook webhooks
- **HTTPS**: SSL/TLS encryption
## π Performance Optimization
- **Caching**: Redis caching for frequently accessed data
- **Async Processing**: Background tasks for heavy operations
- **Connection Pooling**: Efficient database connections
- **Lazy Loading**: Load resources only when needed
## π€ Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## π Support
For support and questions:
- Create an issue in the GitHub repository
- Check the documentation in the `docs/` folder
- Review the API documentation at `http://localhost:8000/docs`
## π Acknowledgments
- **CrewAI** - Multi-agent orchestration framework
- **Google Gemini** - AI model for content generation
- **Facebook** - Social media platform and APIs
- **FastAPI** - Modern web framework
- **Tailwind CSS** - Utility-first CSS framework
---
**Ready to automate your Facebook page management with AI?** π
Start by configuring your environment variables and running the application. The intelligent agents will handle content creation, customer service, and analytics automatically!An AI client and API for WordPress to communicate with any generative AI models of various capabilities using a uniform API. Built on top of the [PHP AI Client](https://github.com/WordPress/php-ai-client), it provides a WordPress-native Prompt Builder, an Admin Settings Screen for credentials, automatic credential wiring, a PSR-compliant HTTP client, and a client-side JavaScript API.
> This file provides instructions for AI agents that read AGENTS.md (GitHub Copilot, Cursor, Windsurf, Cline, Aider, OpenCode, and others).
This document collects ideas and instructions for implementing future improvements. Follow these when adding features or refactoring the code.
> This file must stay **in sync** with `CLAUDE.md`. Whenever you change one, mirror the same change in the other so both tools continue to work correctly.