An advanced AI-powered educational chat system built with CrewAI and FastAPI, featuring intelligent Subject Matter Expert (SME) agents, web search capabilities, and comprehensive PostgreSQL persistence for educational chatrooms.
- Subject Matter Expert (SME) Agents: Specialized AI agents for different subjects (Python, JavaScript, DSA, etc.)
- Web Search Agent: Real-time web research and information gathering using DuckDuckGo
- Enhanced RAG System: Combines vector database, web search, and knowledge base for comprehensive responses
- Educational Chatrooms: Subject-specific learning environments with persistent chat history
- PostgreSQL Integration: Full database persistence for chatrooms, messages, and users
- Vector Database (Qdrant): Semantic search and knowledge retrieval capabilities
- Alembic Migrations: Database schema management and versioning
- Docker Compose: Easy setup with PostgreSQL, Redis, pgAdmin, and Qdrant
- Real-time Web Search: DuckDuckGo integration for current information
- Knowledge Base: Vector-based semantic search for educational content
- Source Citations: Proper attribution and credibility assessment
- Current Information: Always up-to-date responses with web research
- Lesson Plan Generation: AI-generated comprehensive lesson plans with web research
- Practice Exercises: Interactive learning materials (coming soon)
- Subject-Specific Chatrooms: Dedicated learning environments for different topics
- Chat History: Persistent conversation history with full message tracking
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β FastAPI β β CrewAI Agents β β PostgreSQL β
β Web Server βββββΊβ - SME Agents βββββΊβ Database β
β β β - Web Search β β β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Educational β β Enhanced RAG β β Qdrant β
β Chatrooms β β System β β Vector DB β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
- Python 3.11 or higher
- Google Gemini API key
- Docker and Docker Compose (for database services)
- UV package manager (recommended) or pip
git clone <your-repo-url>
cd vidya-chat-agentcp config.example .env
# Edit .env and add your configuration# Using UV (recommended)
uv sync
# Or using pip
pip install -e .# Start PostgreSQL, Redis, pgAdmin, and Qdrant
docker-compose up -d
# Run database migrations
uv run alembic upgrade head# Required: Google Gemini API key
export GEMINI_API_KEY="your_gemini_api_key_here"
# Optional: Additional configuration
export GEMINI_MODEL="gemini/gemini-1.5-flash"
export GEMINI_TEMPERATURE="0.7"Create a .env file with the following variables:
# Required
GEMINI_API_KEY=your_gemini_api_key_here
# Database Configuration
DATABASE_URL=postgresql+asyncpg://postgres:password@localhost:5432/vidya_chat_agent
POSTGRES_PASSWORD=password
POSTGRES_DB=vidya_chat_agent
# Vector Database (Qdrant)
QDRANT_API_URL=http://localhost:6333
QDRANT_COLLECTION=vidya_knowledge
# Optional
GEMINI_MODEL=gemini/gemini-1.5-flash
GEMINI_TEMPERATURE=0.7
HOST=0.0.0.0
PORT=8000
DEBUG=False
AGENT_VERBOSE=True# Start the application
uv run python main.py# Using uvicorn directly
uvicorn src.vidya_chat_agent.api:app --host 0.0.0.0 --port 8000 --reload
# Using UV run
uv run uvicorn src.vidya_chat_agent.api:app --host 0.0.0.0 --port 8000 --reloadThe server will be available at http://localhost:8000
GET /- API information and welcome messageGET /health- Health check and system statusPOST /chat- Main chat endpoint for user queries
GET /educational/subjects- Get available subjectsGET /educational/chatrooms- List all chatroomsPOST /educational/chatrooms- Create a new chatroomGET /educational/chatrooms/{room_id}- Get chatroom informationPOST /educational/chatrooms/{room_id}/chat- Send message to chatroomGET /educational/chatrooms/{room_id}/history- Get chat historyPOST /educational/chatrooms/{room_id}/lesson-plan- Generate lesson planDELETE /educational/chatrooms/{room_id}- Delete chatroom
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
curl -X POST "http://localhost:8000/educational/chatrooms" \
-H "Content-Type: application/json" \
-d '{
"subject": "python",
"title": "Python Learning Session",
"description": "Learn Python programming with AI assistance",
"owner_id": "user123",
"enable_rag": true
}'curl -X POST "http://localhost:8000/educational/chatrooms/python_abc123/chat" \
-H "Content-Type: application/json" \
-d '{
"message": "What are Python decorators?",
"user_id": "student456"
}'curl -X POST "http://localhost:8000/educational/chatrooms/python_abc123/lesson-plan" \
-H "Content-Type: application/json" \
-d '{
"topic": "Python Lists",
"difficulty": "beginner"
}'curl "http://localhost:8000/educational/chatrooms/python_abc123/history"id(UUID) - Primary keyusername(String) - Unique usernameemail(String) - User emailcreated_at(DateTime) - Account creation timeis_active(Boolean) - Account status
id(UUID) - Primary keyroom_id(String) - Unique room identifiersubject(String) - Subject/topic (python, javascript, etc.)title(String) - Chatroom titledescription(Text) - Chatroom descriptionowner_id(UUID) - User who created the chatroomenable_rag(Boolean) - RAG capabilities enabledcreated_at(DateTime) - Creation time
id(UUID) - Primary keychatroom_id(UUID) - Reference to chatroomuser_id(UUID) - Reference to user (optional)message(Text) - User's messageresponse(Text) - AI agent's responsemessage_type(String) - Type of message (chat, lesson_plan, etc.)message_metadata(JSON) - Additional metadatacreated_at(DateTime) - Message timestamp
vidya-chat-agent/
βββ src/
β βββ vidya_chat_agent/
β βββ __init__.py
β βββ agents.py # Basic CrewAI agents
β βββ api.py # Main FastAPI application
β βββ config.py # Configuration management
β βββ database.py # Database models and configuration
β βββ educational_api.py # Educational chatroom endpoints
β βββ enhanced_rag.py # Enhanced RAG system
β βββ sme_agents.py # Subject Matter Expert agents
β βββ vector_store.py # Qdrant vector database integration
β βββ web_search.py # Web search engine
β βββ web_search_agent.py # Web search CrewAI agent
βββ migrations/ # Alembic database migrations
βββ docker-compose.yml # Docker services configuration
βββ main.py # Application entry point
βββ pyproject.toml # Project configuration
βββ README.md
To add support for new subjects, modify the get_available_subjects method in src/vidya_chat_agent/sme_agents.py:
# Add new subjects to the default list
subjects = ["python", "javascript", "dsa", "mathematics", "science", "programming", "your_new_subject"]Modify the SubjectMatterExpert class in src/vidya_chat_agent/sme_agents.py to customize agent behavior:
class SubjectMatterExpert:
def __init__(self, subject: str, expertise_level: str = "expert", enable_rag: bool = True):
# Customize agent initialization
self.subject = subject.lower()
self.expertise_level = expertise_level
self.enable_rag = enable_ragcurl http://localhost:8000/health# List available subjects
curl http://localhost:8000/educational/subjects
# List chatrooms
curl http://localhost:8000/educational/chatrooms
# Test chat functionality
curl -X POST "http://localhost:8000/educational/chatrooms/python_abc123/chat" \
-H "Content-Type: application/json" \
-d '{"message": "Hello, can you help me learn Python?", "user_id": "test_user"}'# Check database connection
docker exec -it vidya_chat_postgres psql -U postgres -d vidya_chat_agent -c "SELECT COUNT(*) FROM chatrooms;"
# Check chat messages
docker exec -it vidya_chat_postgres psql -U postgres -d vidya_chat_agent -c "SELECT COUNT(*) FROM chat_messages;"-
Database Connection Error:
- Ensure Docker services are running:
docker-compose up -d - Check database URL in
.envfile - Verify PostgreSQL is accessible on port 5432
- Ensure Docker services are running:
-
Gemini API Key Error:
- Ensure
GEMINI_API_KEYis set in your environment - Check that the API key is valid and has sufficient credits
- Ensure
-
Web Search Not Working:
- Verify DuckDuckGo tool is properly initialized
- Check internet connectivity
- Review web search agent logs
-
Vector Database Issues:
- Ensure Qdrant is running:
docker-compose ps - Check Qdrant API URL in configuration
- Verify collection exists
- Ensure Qdrant is running:
-
Migration Errors:
- Run migrations:
uv run alembic upgrade head - Check database schema:
docker exec -it vidya_chat_postgres psql -U postgres -d vidya_chat_agent -c "\d"
- Run migrations:
Enable debug mode for more verbose logging:
export DEBUG=true
export AGENT_VERBOSE=true
uv run python main.py- CrewAI: Multi-agent AI framework
- FastAPI: Modern web framework for building APIs
- LangChain: Framework for developing applications with LLMs
- Google Gemini: Access to Gemini models
- SQLAlchemy: Python SQL toolkit and ORM
- Alembic: Database migration tool
- Pydantic: Data validation using Python type annotations
- Uvicorn: ASGI server implementation
- PostgreSQL: Primary database
- asyncpg: Async PostgreSQL driver
- Qdrant: Vector database for semantic search
- Redis: Caching (optional)
- DuckDuckGo: Web search capabilities
- requests: HTTP client for API calls
- sentence-transformers: Text embeddings
This project is optimized for UV, the fast Python package manager:
- Faster: 10-100x faster than pip
- Reliable: Deterministic dependency resolution
- Modern: Native support for pyproject.toml
- Simple:
uv syncinstalls everything you need
The project includes Docker Compose configuration for easy development:
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down
# Services included:
# - PostgreSQL (port 5432)
# - Redis (port 6379)
# - pgAdmin (port 5050)
# - Qdrant (port 6333)- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Update documentation
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with CrewAI
- Powered by FastAPI
- AI capabilities provided by Google Gemini
- Vector database by Qdrant
- Database management with SQLAlchemy
For support and questions:
- Open an issue on GitHub
- Check the API documentation at
/docs - Review the troubleshooting section above
- Check the database status with Docker Compose
- User authentication and authorization
- Student progress tracking
- Practice exercise generation
- Multi-language support
- Mobile app integration
- Advanced analytics and reporting
- Integration with learning management systems