A conversational AI agent for WhatsApp, providing helpful support and explanations.
Wizard-Agent is designed to enhance WhatsApp interactions by providing users with AI-powered assistance. It focuses on explaining features, answering questions, and guiding users on how to utilize various services, without performing the actions themselves.
- Key Features ✨
- Technology Stack 🛠️
- Getting Started 🚀
- Usage Examples 💡
- Project Structure 📁
- Contributing 🤝
- Deployment 🚀
- API Documentation 📚
- Roadmap 🗺️
- Support & Contact 💬
- License 📄
- Acknowledgments 🙏
- Multi-Language Support: Communicates with users in their preferred language, detected automatically.
- Context-Aware Conversations: Remembers previous conversations to provide more relevant and personalized responses.
- Sticker Creation Guidance: Explains how users can turn images into custom stickers within WhatsApp. (Note: The service only explains how, it does not perform the sticker creation itself.)
- Media Download Support (Explanation): Guides users on how to download content from various platforms like Facebook, Instagram, TikTok, YouTube, and Twitter. (Note: The service only explains how, it does not perform the downloads itself.)
- Engaging and Friendly Personality: Designed to be a helpful and supportive companion, providing clear and easy-to-understand guidance.
- Languages:
- Python
- Frameworks:
- FastAPI
- SQLAlchemy
- Tools:
- Uvicorn
- Docker
- Alembic
- Services:
- OpenRouter API
- PostgreSQL
Follow these steps to get Wizard-Agent up and running on your local machine or server.
- Python 3.11 or higher
- Docker (optional, for containerized deployment)
- An OpenRouter API key (required for AI response generation)
- PostgreSQL database instance
- Clone the repository:
git clone https://github.com/gitnasr/Wizard-Agent.git
cd Wizard-Agent- Create a virtual environment (recommended):
python3 -m venv venv
source venv/bin/activate- Install the required Python packages, make sure you are in the root directory of the project:
pip install -r requirements.txt-
Set up environment variables:
- Create a
.envfile in the project root directory, based on the.env.exampleprovided (TODO: Add .env.example to the repo for clarity). Or you can set the env variables through your system/Hosting provider. - Add the following variables, replacing the placeholders with your actual values:
- Create a
OPENROUTER_API_KEY=<YOUR_OPENROUTER_API_KEY>
OPENROUTER_API_URL=https://openrouter.ai/api/v1/chat/completions
DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/whatsapp_wizard # Or your own db URL
PORT=8000
HOST=0.0.0.0
- Configure the database:
Make sure the database you specified in the DATABASE_URL variable is available and running.
You will also need to run the database initialization:
# Run this code snippet in your python interpreter to initialize the database
from database import ConversationDB
import asyncio
async def initialize_database():
db = ConversationDB()
await db.init_db()
asyncio.run(initialize_database())- Start the FastAPI application using Uvicorn:
python main.pyAlternatively, you can run using Uvicorn directly:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload- Access the API documentation at
http://localhost:8000/docs(or the appropriate host and port if you've configured them differently).
The Wizard-Agent is designed to be integrated with a WhatsApp messaging platform. Here are some example scenarios
- Receiving a Message:
The
/webhookendpoint receives incoming messages from WhatsApp. The expected JSON payload structure is:
{
"message": {
"text": "Hello, how can I download tiktok videos?"
},
"user": {
"id": "user123"
}
}-
Processing the Message: The agent processes the message, detects the language (if not already provided), and generates a response using the OpenRouter API.
-
Sending a Response: The agent provides an appropriate response back to the user via the WhatsApp platform. The response might look something like:
{
"response": "Hello! I am here to help. To download TikTok videos, ..."
}Wizard-Agent/
├── .github/workflows/ # GitHub Actions workflows for CI/CD
├── .dockerignore # Specifies intentionally untracked files that Git should ignore
├── Dockerfile # Docker configuration file
├── README.md # This file
├── database.py # Database interaction logic (SQLAlchemy models, CRUD operations)
├── database_config.py # Database configuration (SQLAlchemy setup)
├── docker-compose.yml # Docker Compose file to run services
├── main.py # Main application file. Contains FastAPI endpoints and application logic
├── requirements.txt # List of Python dependencies
Contributions are welcome! Please follow these guidelines:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and write tests.
- Submit a pull request.
To set up your development environment:
- Follow the Installation instructions.
- Install development dependencies (e.g., linters, formatters) .
- Configure your editor for linting and formatting.
If you find a bug or have a feature request, please open an issue on GitHub.
To deploy Wizard-Agent to production:
- Build the Docker image:
docker build -t wizard-agent .- Push the image to a container registry (e.g., Docker Hub):
docker tag wizard-agent:latest <your_dockerhub_username>/wizard-agent:latest
docker push <your_dockerhub_username>/wizard-agent:latest-
Deploy the container to your preferred hosting platform (e.g., AWS, Google Cloud, Azure).
-
Configure environment variables in your hosting environment.
-
Ensure that the application can access the PostgreSQL database.
Detailed API documentation is available at:
http://localhost:8000/docs
Key endpoints:
/webhook(POST): Handles incoming messages from the WhatsApp platform.
- Implement context summarization to handle long conversations more effectively.
- Add more robust error handling and logging.
- Develop comprehensive unit and integration tests.
- Explore more advanced AI models for improved response quality.
If you have questions or need help, please:
- Open an issue on GitHub: https://github.com/gitnasr/Wizard-Agent/issues
- Contact me through my GitHub profile: https://github.com/gitnasr
This project is licensed under the MIT License - see the LICENSE file for details.
- The Wizard-Agent uses the OpenRouter API to generate AI responses, making it possible to easly use multiple LLMs.
- Thanks to the FastAPI and SQLAlchemy communities for providing excellent tools for building web applications and interacting with databases.