An AI chatbot project built with FastAPI, LangChain, and other modern technologies. This project focuses on creating an intelligent chatbot capable of handling various tasks through specialized agents.
├── src/
│ ├── agents/ # Specialized agents
│ ├── api/ # API endpoints
│ ├── config/ # Configuration
│ ├── static/ # Static files
│ ├── test/ # Unit tests
│ ├── tools/ # Support tools
│ ├── utils/ # Utilities
│ └── main.py # Entry point
├── docker-compose.yml
├── Dockerfile
├── nginx.conf
├── requirements.txt
└── README.md
- 🤖 AI/ML: LangChain, LangGraph, TensorFlow, PyTorch, HuggingFace, SpaCy, Sentence Transformers, MCP, OpenCV
- 🌐 APIs: Together API, Gemini API, Google API
- ⚙️ Backend: FastAPI, Nginx, Docker, PostgreSQL
The chatbot is built on a Multi-Agent architecture, where each agent handles a specific role. Below are the details of the main agents in the system:
- Role: Base class for all agents in the system
- Functions:
- Initialize agent and manage tools
- Integration with Google Generative AI (gemini-2.0-flash)
- Build and manage state graph for processing flow within each agent
- Coordinate processing flow between agents
- Role: Analyze and route requests to appropriate agents
- Assignment Logic:
- Writer: Simple requests (expression, rewriting, explanation)
- Analyst: Complex requests (reasoning, analysis, problem-solving)
- Coder: Programming-related requests, code, debugging
- Planner: Planning and process requests
- Search: Information lookup
- Tool: External tool usage (API, file ops)
- Vision: Image processing and OCR
- Role: Deep analysis of user requests
- Functions:
- Clarify and structure requests
- Identify goals and expected outcomes
- Analyze feasibility
- Propose solution approaches
- Role: Information search and synthesis
- Functions:
- Search information from web or knowledge base
- Filter and return relevant results
- Cite information sources
- No speculation, only data-based responses
- Role: Handle programming-related issues
- Functions:
- Write and edit code
- Debug errors
- Performance optimization
- Technical solution consulting
- Role: Planning and strategy
- Functions:
- Create detailed plans
- Break down tasks into steps
- Estimate time and resources
- Track progress
- Role: Memory and context management
- Functions:
- Store important information
- Maintain conversation context
- Retrieve relevant information
- Manage interaction history
- Summarize context when it becomes too long
- Role: Content creation and editing
- Functions:
- Write text based on requirements
- Edit and optimize content
- Create summary reports
- Clear idea expression
- Role: External tool management and usage
- Functions:
- Integration with external APIs
- File system operations
- Service connections (Gmail, Drive)
- System task processing
- Role: Image-related task processing
- Functions:
- Image analysis
- Text recognition (OCR)
- Image processing and editing
- Image generation and adjustment
-
Initialization:
- All requests start from
MemoryAgent
MemoryAgent
stores context and summarizes if context is too long forAssignerAgent
- All requests start from
-
Task Assignment:
AssignerAgent
analyzes request and determines appropriate agent- Based on request type, routes to one of the agents:
- Analyst (complex analysis)
- Writer (simple tasks)
- Coder (code-related)
- Planner (planning)
- Search (information lookup)
- Tool (tool usage)
- Vision (image processing)
-
Specialized Processing:
- Each agent processes according to its expertise
AnalystAgent
transfers results toSupervisorAgent
after analysisSupervisorAgent
decides which agent to route to and if user intervention is needed:- Routes to
CalculatorAgent
if calculations needed - Or routes to
WriterAgent
for response
- Routes to
-
Process Completion:
- All agents transfer final results to
WriterAgent
WriterAgent
formats and returns final response
- All agents transfer final results to
-
Modular and Extensible:
- Each agent operates independently
- Easy to add new agents
- No impact on other agents during upgrades
-
Specialization:
- Each agent focuses on specific tasks
- Optimization for each task type
- Easy to improve individual aspects
-
Processing Flexibility:
- Adjustable processing flow based on requirements
- Supports parallel processing when needed
- Easy to add new processing steps
-
Efficient State Management:
- Uses StateGraph for flow management
- Stores and tracks processing progress
- Easy debugging and troubleshooting
- Python 3.12+
- Docker and Docker Compose
- Nginx (for production)
- Clone repository:
git clone https://github.com/trongdung143/chatbot.git
cd chatbot
- Create virtual environment and install dependencies:
python -m venv venv
source venv/bin/activate # Linux/Mac
.\venv\Scripts\activate # Windows
pip install -r requirements.txt
- Configure environment:
- Create
.env
file from template and update environment variables
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000
docker-compose up -d
Application will be available at: http://localhost:8000