Skip to content

Commit 293adbe

Browse files
Agentic AI update to the system
Agentic AI update to the system
1 parent 8b5272d commit 293adbe

36 files changed

+3366
-209
lines changed

.env.example

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,33 @@ TAG=latest
88

99
# Frontend Configuration
1010
VITE_BACKEND_URL=
11+
1112
# For production, this will be set by Azure App Service
1213

13-
# Backend Configuration - Azure OpenAI
14-
AZURE_OPENAI_ENDPOINT=
15-
AZURE_OPENAI_API_KEY=
16-
OPENAI_API_VERSION=
17-
AZURE_DEPLOYMENT_NAME=
14+
# Backend Configuration - Azure OpenAI (Chat Model)
15+
AZURE_OPENAI_ENDPOINT = ""
16+
AZURE_OPENAI_API_KEY = ""
17+
AZURE_DEPLOYMENT_NAME = ""
18+
AZURE_OPENAI_API_VERSION = ""
19+
20+
# Azure OpenAI Embedding Model Configuration
21+
AZURE_EMBEDDING_MODEL = ""
22+
AZURE_OPENAI_ENDPOINT_EMBED = ""
23+
AZURE_OPENAI_API_KEY_EMBED = ""
24+
AZURE_EMBEDDING_DEPLOYMENT_NAME = ""
25+
AZURE_OPENAI_API_VERSION_EMBED = ""
1826

1927
# Backend Database Variables (used by the application)
20-
DB_USERNAME=
21-
DB_PASSWORD=
22-
DB_NAME=proposalgen
23-
DB_HOST=db
24-
DB_PORT=5432
28+
DB_USERNAME=""
29+
DB_PASSWORD=""
30+
DB_NAME=""
31+
DB_HOST=""
32+
DB_PORT=""
2533

2634
# JWT Secret for authentication
27-
SECRET_KEY=
35+
SECRET_KEY=""
36+
37+
# Azure Blob Container details
38+
AZURE_BLOB_CONNECTION_STRING=""
39+
AZURE_BLOB_KB=""
40+
AZURE_BLOB_UPLOAD=""

.github/workflows/azure-container-webapp.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ env:
3333
DB_HOST: ${{ secrets.DB_HOST }}
3434
DB_PORT: ${{ secrets.DB_PORT }}
3535
SECRET_KEY: ${{ secrets.SECRET_KEY }}
36+
AZURE_BLOB_CONNECTION_STRING: ${{ secrets.AZURE_BLOB_CONNECTION_STRING }}
37+
AZURE_BLOB_KB: ${{ secrets.AZURE_BLOB_KB }}
38+
AZURE_BLOB_UPLOAD: ${{ secrets.AZURE_BLOB_UPLOAD }}
3639

3740
jobs:
3841
build-and-deploy:
@@ -93,6 +96,9 @@ jobs:
9396
-e "s|\${DB_HOST}|${DB_HOST}|g" \
9497
-e "s|\${DB_PORT}|${DB_PORT}|g" \
9598
-e "s|\${SECRET_KEY}|${SECRET_KEY}|g" \
99+
-e "s|\${AZURE_BLOB_CONNECTION_STRING}|${AZURE_BLOB_CONNECTION_STRING}|g" \
100+
-e "s|\${AZURE_BLOB_KB}|${AZURE_BLOB_KB}|g" \
101+
-e "s|\${AZURE_BLOB_UPLOAD}|${AZURE_BLOB_UPLOAD}|g" \
96102
"$DOCKER_COMPOSE_PATH"
97103
98104
echo "→ Final compose file (for debugging):"
@@ -145,6 +151,9 @@ jobs:
145151
DB_NAME="${{ env.DB_NAME }}" \
146152
DB_HOST="${{ env.DB_HOST }}" \
147153
DB_PORT="${{ env.DB_PORT }}" \
154+
AZURE_BLOB_CONNECTION_STRING="${{ env.AZURE_BLOB_CONNECTION_STRING }}" \
155+
AZURE_BLOB_KB="${{ env.AZURE_BLOB_KB }}" \
156+
AZURE_BLOB_UPLOAD="${{ env.AZURE_BLOB_UPLOAD }}" \
148157
SECRET_KEY="${{ env.SECRET_KEY }}"
149158
150159
- name: Deploy Multi-Container App to Azure App Service
@@ -181,4 +190,4 @@ jobs:
181190
--resource-group ${{ env.RESOURCE_GROUP }} \
182191
--name ${{ env.AZURE_WEBAPP_NAME }} \
183192
--query "defaultHostName" -o tsv)
184-
echo "App deployed at: https://$APP_URL"
193+
echo "App deployed at: https://$APP_URL"

README.md

Lines changed: 134 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ migration_pathways/
5555
├── .github/workflows/ # GitHub Actions CI/CD pipelines
5656
├── backend/ # Flask API, AI model integration, database operations
5757
├── frontend/ # React UI
58-
├── docker-compose.yml # Docker container orchestration
59-
├── init-db.sql # Database initialization script
58+
├── migration-azure-docker-compose.yml # Docker container orchestration
59+
├── database-setup.sql # Database initialization script
6060
└── .env.example # Environment variables template
6161
```
6262

@@ -66,81 +66,161 @@ migration_pathways/
6666
- Git
6767
- Azure OpenAI API access (for production)
6868

69-
## Quick Start
69+
## Project Overview
7070

71-
1. **Clone the repository:**
72-
```bash
73-
git clone https://github.com/yourusername/migration_pathways.git
74-
cd migration_pathways
75-
```
71+
This is an AI-powered migration assistance chatbot built for the International Organization for Migration (IOM). It provides verified migration information and personalized pathways to help migrants make safer, informed decisions.
7672

77-
2. **Set up environment variables:**
78-
```bash
79-
cp .env.example .env
80-
# Edit .env file with your settings
81-
```
73+
**Architecture**: Flask backend with React frontend, PostgreSQL database, and enhanced AI system combining RAG (Retrieval-Augmented Generation) with CrewAI multi-agent architecture using Azure OpenAI and Chroma vector database.
8274

83-
3. **Start the application with Docker Compose:**
84-
```bash
85-
docker-compose up -d
86-
```
87-
88-
4. **Access the application:**
89-
- Frontend: http://localhost
90-
- Backend API: http://localhost:8510
91-
92-
## Development Environment
75+
## Development Commands
9376

9477
### Backend Development
95-
9678
```bash
9779
cd backend
9880
python -m venv env
9981
source env/bin/activate # On Windows: env\Scripts\activate
10082
pip install -r requirements.txt
101-
102-
# Set up PostgreSQL locally or use Docker:
103-
docker run --name postgres -e POSTGRES_PASSWORD=your_secure_password -e POSTGRES_USER=iom_uc2_user -e POSTGRES_DB=iom_uc2 -p 5432:5432 -d postgres:14-alpine
104-
105-
# Run the backend server:
106-
python main.py
83+
python main.py # Runs on port 80
10784
```
10885

10986
### Frontend Development
110-
11187
```bash
11288
cd frontend
11389
npm install
114-
npm run dev
90+
npm run dev # Runs on port 8509
91+
npm run build # Production build
92+
npm run lint # ESLint
93+
npm test # Vitest tests
94+
npm run test:ui # Vitest UI
11595
```
11696

117-
## Database Setup
97+
### Testing
98+
```bash
99+
# Backend tests
100+
cd backend
101+
pytest
118102

119-
The PostgreSQL database is automatically initialized with the required tables when using Docker Compose. For manual setup, see the [backend README](backend/README.md).
103+
# CrewAI integration test
104+
cd backend
105+
python test_crew_ai.py
120106

121-
## CI/CD Pipeline
107+
# Frontend tests
108+
cd frontend
109+
npm test
110+
```
122111

123-
This project utilizes GitHub Actions for Continuous Integration and Deployment:
112+
### Docker Development
113+
```bash
114+
# Full stack with Docker Compose
115+
docker-compose -f migration-azure-docker-compose.yml up -d
124116

125-
- **CI Pipeline:** Runs on PR and pushes to main/dev branches
126-
- Lints and tests frontend code
127-
- Lints and tests backend code
128-
- Builds Docker images
117+
# Individual services
118+
docker build -t migration-backend ./backend
119+
docker build -t migration-frontend ./frontend
120+
```
129121

130-
- **CD Pipeline:** Runs on pushes to main branch and tags
131-
- Builds and pushes Docker images to GitHub Container Registry
132-
- Deploys to staging/production environments
122+
## Architecture Details
123+
124+
### Backend (Flask)
125+
- **Main entry**: `backend/main.py` - Flask app with authentication, admin routes, and user management
126+
- **Chat systems**:
127+
- `backend/chat_rag.py` - Original RAG implementation with Azure OpenAI and Chroma
128+
- `backend/chat_crew_ai.py` - Enhanced CrewAI multi-agent system
129+
- **Database**: PostgreSQL with SQLAlchemy ORM, connection via `utility/db_config.py`
130+
- **Authentication**: JWT tokens with httpOnly cookies, role-based access (users/admins)
131+
- **CrewAI Agent System**:
132+
- **Agents**: `backend/crew_ai/agents.py` - 6 specialized migration agents
133+
- Migration Advisor: Primary pathway guidance
134+
- Risk Assessment: Safety and fraud detection
135+
- Documentation Specialist: Legal requirements and paperwork
136+
- Cultural Integration: Adaptation and community support
137+
- Employment Advisor: Job markets and skill recognition
138+
- Resource Coordinator: IOM contacts and NGO connections
139+
- **Tasks**: `backend/crew_ai/tasks.py` - Structured task definitions for agent coordination
140+
- **Tools**: `backend/crew_ai/tools.py` - Vector search, contact lookup, risk assessment tools
141+
- **Orchestration**: `backend/crew_ai/crew.py` - Crew management and execution logic
142+
- **RAG Components**:
143+
- Vector store: Chroma database in `backend/chroma_store/`
144+
- Embeddings: Azure OpenAI embeddings for semantic search
145+
- Knowledge sources: Web scraped content + JSON knowledge base
146+
- Document processing: `utility/embedder.py`, `utility/scraper_and_embedder.py`
147+
148+
### Frontend (React + Vite)
149+
- **Framework**: React 19 with React Router DOM for navigation
150+
- **Build tool**: Vite with SWC for fast compilation
151+
- **Testing**: Vitest + React Testing Library + MSW for API mocking
152+
- **Styling**: CSS modules with responsive design
153+
- **Proxy**: Development proxy `/api``http://localhost:8510` (backend)
154+
155+
### Database Schema
156+
- **users**: User accounts with authentication, preferences, session management
157+
- **admins**: Admin accounts with elevated privileges
158+
- Key fields: email, password (hashed), request_count, active status, security_questions
159+
160+
### Key Features
161+
- **Enhanced Chat Interface**:
162+
- `/api/chat` - Original RAG-based responses
163+
- `/api/chat/crew` - CrewAI multi-agent specialized responses
164+
- `/api/chat/hybrid` - Automatic fallback from CrewAI to RAG
165+
- **Multi-Agent AI System**: 6 specialized agents working collaboratively
166+
- **Intelligent Risk Assessment**: Automated detection of trafficking, fraud, and unsafe migration practices
167+
- **Comprehensive Guidance**: Legal documentation, cultural integration, employment advice
168+
- **Dynamic Resource Coordination**: Contextual IOM office and NGO recommendations
169+
- **Admin Dashboard**: Content management, user administration, URL scraping
170+
- **Authentication**: Secure login/logout with session management
171+
- **Content Management**: Web scraping, document upload, knowledge base updates
172+
- **Preferences**: User source/destination country settings for personalized responses
133173

134174
## Environment Variables
135175

136-
See `.env.example` for the required environment variables.
137-
138-
## Docker Deployment
139-
140-
The application can be deployed using Docker Compose:
141-
142-
```bash
143-
# Production deployment
144-
docker-compose -f docker-compose.yml up -d
145-
```
146-
176+
Required environment variables (see `.env.example`):
177+
- `SECRET_KEY`: JWT signing key
178+
- `DB_*`: PostgreSQL connection details
179+
- `AZURE_OPENAI_*`: Azure OpenAI service credentials for chat model
180+
- `AZURE_*_EMBED`: Azure OpenAI embedding service credentials
181+
- `VITE_BACKEND_URL`: Frontend API endpoint
182+
183+
**CrewAI-specific variables**:
184+
- `AZURE_EMBEDDING_MODEL`: Embedding model name (e.g., text-embedding-ada-002)
185+
- `AZURE_OPENAI_ENDPOINT_EMBED`: Separate endpoint for embeddings (if different)
186+
- `AZURE_OPENAI_API_KEY_EMBED`: API key for embedding service
187+
- `AZURE_EMBEDDING_DEPLOYMENT_NAME`: Deployment name for embedding model
188+
- `AZURE_OPENAI_API_VERSION_EMBED`: API version for embedding service
189+
190+
## Development Workflow
191+
192+
1. **Database Setup**: Run `database-setup.sql` to initialize PostgreSQL
193+
2. **Environment**: Copy `.env.example` to `.env` and configure all Azure OpenAI endpoints
194+
3. **Backend**: Install dependencies including CrewAI, start Flask server on port 80
195+
4. **Frontend**: Install dependencies, start Vite dev server on port 8509
196+
5. **CrewAI Testing**: Run `python test_crew_ai.py` to verify agent system
197+
6. **Testing**: Run pytest (backend) and vitest (frontend) before commits
198+
199+
### CrewAI Development Notes
200+
- **Agent Modifications**: Edit `backend/crew_ai/agents.py` to adjust agent roles and capabilities
201+
- **Task Updates**: Modify `backend/crew_ai/tasks.py` to change agent coordination logic
202+
- **Tool Enhancement**: Add new tools in `backend/crew_ai/tools.py` for expanded functionality
203+
- **Configuration**: Adjust settings in `backend/crew_ai/config.py` for performance tuning
204+
- **Testing Endpoints**:
205+
- GET `/api/chat/crew/status` - Check CrewAI system health
206+
- POST `/api/chat/crew/reset` - Reset user conversation history
207+
- POST `/api/chat/hybrid` - Use intelligent fallback system
208+
209+
## Common Issues
210+
211+
- **CORS**: Frontend dev server proxies API calls through Vite config
212+
- **Database**: Ensure PostgreSQL is running and credentials are correct
213+
- **Azure OpenAI**: Verify both chat and embedding endpoints are configured
214+
- **Chroma**: Vector database persists in `backend/chroma_store/`
215+
- **CrewAI Issues**:
216+
- **Rate Limits**: Azure OpenAI rate limiting may affect agent execution
217+
- **Memory Usage**: Multiple agents can consume significant memory
218+
- **Timeout**: Complex queries may exceed execution time limits
219+
- **Dependencies**: Ensure all CrewAI and LangChain packages are compatible versions
220+
- **Tools Access**: Verify tools have access to vector store and JSON knowledge base
221+
222+
## Deployment
223+
224+
- **Production**: Uses `migration-azure-docker-compose.yml` with nginx proxy
225+
- **Services**: nginx-proxy (port 80) → frontend → backend → PostgreSQL
226+
- **CI/CD**: GitHub Actions workflow in `.github/workflows/`

backend/.env.example

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
## this env file is used to set environment variables for the backend application when running it locally without a Docker container
22
AZURE_OPENAI_ENDPOINT = ""
3-
AZURE_OPENAI_API_VERSION = ""
43
AZURE_OPENAI_API_KEY = ""
54
AZURE_DEPLOYMENT_NAME = ""
5+
AZURE_OPENAI_API_VERSION = ""
66

77
AZURE_EMBEDDING_MODEL = ""
88
AZURE_OPENAI_ENDPOINT_EMBED = ""
@@ -12,9 +12,13 @@ AZURE_OPENAI_API_VERSION_EMBED = ""
1212

1313
DB_USERNAME=""
1414
DB_PASSWORD=""
15-
DB_NAME="postgres"
15+
DB_NAME=""
1616
DB_HOST=""
17-
DB_PORT="5432"
17+
DB_PORT=""
1818

1919
# JWT Secret for authentication
20-
SECRET_KEY=""
20+
SECRET_KEY=""
21+
22+
AZURE_BLOB_CONNECTION_STRING=""
23+
AZURE_BLOB_KB=""
24+
AZURE_BLOB_UPLOAD=""

0 commit comments

Comments
 (0)