Ustaad-AI is an AI-powered service worker discovery platform built for Karachi's informal economy. Users describe their problem in natural language β Roman Urdu, English, or Urdu β and the system finds, ranks, and books the best available local service worker automatically.
The platform runs a 3-agent orchestration pipeline (Intent Parser β Matchmaker β Pricer) backed by a real SQLite database of 500 seeded Karachi service providers. Every agent decision is streamed live to the frontend via Server-Sent Events (SSE) so judges and users can verify the reasoning in real time.
- Roman Urdu / Urdu / English NLP β Gemini parses noisy, multilingual, informal requests into structured intent (service type, location, urgency, time).
- 3-Agent Pipeline β Intent Parser, Matchmaker, and Pricer run sequentially with structured JSON outputs validated by Pydantic schemas.
- 6-Factor Matching Algorithm β Providers ranked by: Travel Time (30%), Rating (20%), Reliability (20%), Price (15%), Cancellation Rate (15%).
- Real Geolocation β Google Maps Geocoding + Distance Matrix API for actual driving distance and travel time, not mock values.
- Dynamic Pricing β Urgency multiplier (1.5Γ if high) + distance fee (50 PKR/km) on top of provider's base rate.
- Live Agent Traces β SSE endpoint streams raw orchestration logs to expandable debug view in the UI.
- Voice Simulator β Inline voice-to-text simulation without blocking the UI thread.
- WhatsApp + Maps Deep Links β One-tap contact and navigation directly from the result card.
- Dark Mode β Full light/dark theme toggle on the Flet frontend.
- Android APK β Built and released via GitHub Actions CI/CD (Flet
flet build apk). - 429 Fallback Handling β All 3 agents have mock fallbacks if Gemini quota is exhausted mid-demo.
User Input (Roman Urdu / English / Urdu)
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend (Uvicorn) β
β β
β ββββββββββββββββββββββββββββββββββββ β
β β UstaadOrchestrator β β
β β β β
β β 1. Intent Parser Agent β β
β β ββ Gemini 2.0 Flash (JSON) β β
β β β β
β β 2. Matchmaker Agent β β
β β ββ Google Maps Geocoding β β
β β ββ SQLite DB Query β β
β β ββ Distance Matrix API β β
β β ββ Gemini 2.0 Flash (Rank) β β
β β β β
β β 3. Pricer Agent β β
β β ββ Gemini 2.0 Flash (JSON) β β
β β β β
β β SSE Trace Queue (asyncio) β β
β ββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββ
β β
βΌ βΌ
POST /api/request GET /api/agent-traces
β β
βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β Flet Frontend (Mobile UI) β
β - Chat interface β
β - Multi-stage loading animation β
β - Expandable SSE debug trace window β
β - WhatsApp + Maps deep links β
βββββββββββββββββββββββββββββββββββββββββββ
| Layer | Technology |
|---|---|
| Frontend | Flet >=0.85.0, <0.91.0 |
| Backend | FastAPI + Uvicorn |
| AI Core | Google Gemini 2.0 Flash (google-genai) |
| Database | SQLite via SQLAlchemy |
| Geolocation | Google Maps API (googlemaps) |
| Deployment | Cloud Run (backend), GitHub Actions (APK) |
- Python 3.11
- A Google Gemini API Key β get one here
- A Google Maps API Key with Geocoding + Distance Matrix enabled β get one here
git clone https://github.com/abdulhayykhan/Ustaad-AI.git
cd Ustaad-AIcp .env.example .envEdit .env:
GEMINI_API_KEY=your_gemini_api_key_here
GOOGLE_MAPS_API_KEY=your_google_maps_api_key_here
DATABASE_URL=sqlite:///./ustaad.db
CORS_ALLOW_ORIGINS=http://localhost:8550,http://127.0.0.1:8550
USTAAD_API_URL=http://localhost:8000pip install -r requirements.txtNote: The package
google-genaiis required (notgoogle-generativeai). Therequirements.txtincludes the correct package.
Populate 500 mock Karachi service providers into the local SQLite DB:
python -m backend.seedExpected output:
Starting database seeding...
Successfully seeded 500 providers to the database.
Open two terminal sessions from the project root:
Terminal 1 β FastAPI Backend:
uvicorn backend.main:app --reloadBackend runs on http://localhost:8000.
Terminal 2 β Flet Frontend:
python -m frontend.main| Method | Endpoint | Description |
|---|---|---|
POST |
/api/request |
Submit natural language service request. Triggers full 3-agent pipeline. |
GET |
/api/agent-traces |
SSE stream of live agent reasoning logs. |
Sample Request:
curl -X POST http://localhost:8000/api/request \
-H "Content-Type: application/json" \
-d '{"text": "Malir Halt mein kal subah AC mechanic chahiye, urgent hai"}'Mujhe kal subah Malir Halt mein AC technician chahiye, AC bilkul cooling nahi kar raha.
Yar Shah Faisal Number 3 mein urgent electrician chahiye, main board se dhuan nikal raha hai!
Sea View apartments ke paas kisi Generator Mechanic ka contact milega? Kal dopahar mein service karwani hai.
Ϊ―ΩΨ΄Ω Ψ§ΩΨ¨Ψ§Ω Ψ¨ΩΨ§Ϊ© 13D Ω
ΫΪΊ ΩΨ§Ψ΄ΩΪ― Ω
Ψ΄ΫΩ Ϊ©Ψ§ ΩΉΫΪ©ΩΫΨ΄Ω ΪΨ§ΫΫΫΫ ΩΎΨ§ΩΫ ΩΫΪ© ΫΩ Ψ±ΫΨ§ ΫΫΫ
Need a plumber tomorrow morning at DHA Phase 6 Khayaban-e-Shahbaz. Kitchen sink completely clogged.
The Matchmaker Agent scores each candidate provider using this weighted formula:
| Factor | Weight | Source |
|---|---|---|
| Travel Time | 30% | Google Maps Distance Matrix |
| Rating | 20% | Provider DB (rating field, 0β5) |
| Reliability Score | 20% | Provider DB (reliability_score, 0β100) |
| Base Rate (Price) | 15% | Provider DB (base_rate_pkr) |
| Cancellation Rate | 15% | Provider DB (cancellation_rate, 0β1) |
Lower travel time, higher rating, higher reliability, lower price, and lower cancellation rate = higher score.
Total = Base Rate
+ (Base Rate Γ 0.5) [if urgency = "high"]
+ (Distance in km Γ 50 PKR)
Example: Base 800 PKR + Urgency 400 PKR + Distance (3.84 km Γ 50) 192 PKR = 1,392 PKR
- Ensure backend is running (
uvicorn backend.main:app --reload). - Launch Flet UI (
python -m frontend.main). - Toggle Dark Mode using the top-right icon.
- Click the Microphone button β watch the simulated voice input populate.
- Hit Send β observe the multi-stage loading animation:
- π€ Ustaad-AI soch raha hai...
- π Aas paas ustaad dhoond raha hai...
- π° Bhau taal tay kar raha hai...
- β Booking final kar raha hai...
- Expand "View AI Agent Reasoning" to see live SSE traces from all 3 agents.
- View the result card: provider name, distance, pricing breakdown.
- Tap "Message Ustaad on WhatsApp" and π Distance links.
Ustaad-AI/
βββ backend/
β βββ agents.py # UstaadOrchestrator + 3 sub-agents
β βββ database.py # SQLAlchemy engine + session config
β βββ main.py # FastAPI app, routes, SSE endpoint
β βββ models.py # Provider + Booking ORM models
β βββ seed.py # 500-provider Karachi DB seeder
β βββ tools.py # Google Maps geocoding + distance tools
βββ frontend/
β βββ main.py # Flet mobile UI
βββ .github/
β βββ workflows/
β βββ build-apk.yml # GitHub Actions APK builder
βββ .env.example
βββ Dockerfile
βββ requirements.txt
βββ sample_prompts.txt
docker build -t ustaad-ai .
docker run -p 8080:8080 --env-file .env ustaad-aiLive backend: https://ustaad-ai-620054685556.europe-west1.run.app
Push to main branch β the workflow in .github/workflows/build-apk.yml automatically builds and uploads the APK artifact. Download from the Releases page.
This project is open-source and available for educational and commercial use under the MIT License.
Made with β€οΈ by Abdul Hayy Khan