A multi-agent chat system where conversations vanish, but digital souls persist. Built with FastAPI and Google's Gemini API.
- Multi-Agent Chat: Create and chat with multiple AI characters simultaneously
- Ephemeral Conversations: Chat sessions automatically expire after a configurable TTL
- Persistent AI Characters: Your AI characters persist across sessions
- Real-time WebSocket: Live chat experience with instant responses
- AI Avatar Generation: Generate unique avatars for your AI characters using Gemini's image generation
- Personality-driven AI: Each AI character has customizable personality traits
- Authentication: Secure JWT-based user authentication
- Scalable Architecture: Built with FastAPI, PostgreSQL, Redis, and Celery
- FastAPI: Modern, fast web framework for building APIs
- PostgreSQL: Primary database for user and AI character data
- Redis: Session management and message caching
- Celery: Background task processing for avatar generation
- Gemini API: Google's AI model for chat and image generation
- WebSocket: Real-time communication between clients and server
ghost_mesh/
โโโ ai_agent/ # AI character management and Gemini integration
โโโ auth/ # Authentication and authorization
โโโ chat/ # Chat session management and WebSocket handling
โโโ db/ # Database configuration and utilities
โโโ entities/ # SQLAlchemy models (User, AICharacter)
โโโ migrations/ # Alembic database migrations
โโโ tasks/ # Celery background tasks
โโโ users/ # User management
โโโ utils/ # Utility functions
โโโ app.py # FastAPI application entry point
โโโ config.py # Configuration settings
โโโ requirements.txt # Python dependencies
- Python 3.11+
- PostgreSQL database
- Redis server
- Google Gemini API key
- AWS S3 bucket (for image storage)
-
Clone the repository
git clone <repository-url> cd ghost_mesh
-
Set up virtual environment
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
cp .env.save .env # Edit .env with your actual configuration -
Set up database
# Run database migrations alembic upgrade head
Create a .env file with the following variables:
# Application SECRET_KEY=your-secret-key ALGORITHM=HS256 ACCESS_TOKEN_EXPIRE_MINUTES=220 # Database DATABASE_URL=postgresql://user:password@host:port/database # Gemini API GEMINI_API_KEY=your-gemini-api-key GEMINI_CHAT_MODEL=gemini-2.5-flash-lite GEMINI_IMG_GEN_MODEL=imagen-4.0-generate-001 # Redis REDIS_URL=redis://localhost:6379 REDIS_CELERY_BROKER=redis://localhost:6379 CHAT_SESSION_TTL=3600 # AWS S3 AWS_ENDPOINT_URL=your-s3-endpoint AWS_ACCESS_KEY_ID=your-access-key AWS_SECRET_ACCESS_KEY=your-secret-key AWS_REGION_NAME=your-region AWS_BUCKET_FOR_IMAGES=your-bucket-name IMAGE_PUBLIC_ACCESS_URL=your-public-url
-
Start the API server
python app.py
-
Start Celery worker (in another terminal)
celery -A celery_app.celery_client worker --pool=threads -l info
- Build and run with Docker Compose
docker-compose up --build
POST /auth/register- Register a new userPOST /auth/login- User login and token generation
POST /ai-character/create-character- Create a new AI characterGET /ai-character/get-character/{id}- Get AI character detailsGET /ai-character/list-character- List user's AI charactersDELETE /ai-character/delete-character- Delete an AI characterPUT /ai-character/update-character- Update AI character
POST /chat/create-session- Create a new chat sessionWebSocket /ws/chat/{session_id}- Real-time chat connection
GET /users/profile- Get user profilePUT /users/update-profile- Update user profile
Users can create AI characters with:
- Name: Unique identifier for the character
- Description: Brief overview of the character
- Personality Traits: Detailed personality that influences AI responses
- Avatar: Auto-generated image based on character description
- Session Creation: Users select AI characters to chat with
- WebSocket Connection: Real-time bidirectional communication
- Message Processing: Messages are stored in Redis with TTL
- AI Responses: Each AI character responds based on their personality
- Session Expiration: Sessions automatically expire after TTL
The system uses Gemini API with:
- System Instructions: Personality-based prompts
- Context Awareness: Full chat history for contextual responses
- Google Search: Enhanced responses with web search capabilities
- Concurrent Processing: Multiple AI characters respond simultaneously
Chat sessions automatically expire based on CHAT_SESSION_TTL (default: 3600 seconds). This ensures conversations remain ephemeral while AI characters persist.
AI characters follow this instruction pattern:
You are [character_name]. Mimic the following personality traits and answer the last message to the user only message no need of behavior, you can also chat with others characters. Personality trait: [personality_traits]. If you want to skip the conversation reply simply with a '.'
Run the test suite:
pytest tests/
The application includes Docker configuration for easy deployment:
- Dockerfile: Multi-stage build for production
- docker-compose.yml: Complete stack with API and Celery worker
- .dockerignore: Optimized container builds
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
- Voice chat integration
- AI character learning from conversations
- Multi-language support
- Advanced personality modeling
- Character relationship mapping
- Export/import character configurations
- Mobile app support
- Database Connection: Ensure PostgreSQL is running and credentials are correct
- Redis Connection: Verify Redis server is accessible
- Gemini API: Check API key quota and model availability
- WebSocket Issues: Verify CORS configuration and firewall settings
Check application logs for debugging:
# Development python app.py # Docker docker-compose logs api docker-compose logs celery
For support and questions:
- Create an issue on GitHub
- Check the troubleshooting section
- Review the API documentation
Ghost Mesh - Where digital souls linger and conversations fade away.