Hackathon Project โ An intelligent service marketplace for Pakistan's informal economy, powered by a multi-agent AI orchestration engine.
KhidmatApp connects users with local service providers (AC technicians, electricians, plumbers, beauticians) through a conversational AI interface that understands Roman Urdu, English, and code-switched input. Behind the scenes, a swarm of specialized AI agents handles everything from intent parsing to dynamic pricing to dispute resolution.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ React Native (Expo) โ
โ ChatInput โ ProviderList โ Pricing โ Booking โ โ
โ LiveTracking โ Feedback โ Dispute โ
โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ REST API (fetch)
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Express.js Gateway (port 5000) โ
โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ Intent Agent โโโ Matching โโโ Pricing โ โ
โ โ (Gemini NLP) โ โ Agent โ โ Agent โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโโผโโโโโโโโ โโโโโโผโโโโโโ โโโโโโโโผโโโโโโโ โ
โ โ Booking Agent โ โ Follow-upโ โ Dispute โ โ
โ โ (Double-book โ โ Agent โ โ Agent โ โ
โ โ prevention) โ โ (Timelineโ โ (Decision โ โ
โ โโโโโโโโโโโโโโโโโ โ sim) โ โ tree) โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Cloud Firestore + Google Maps API โ
โ Collections: providers, bookings, notifications, โ
โ agent_logs โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Method | Endpoint | Agent | Description |
|---|---|---|---|
POST |
/api/parse-intent |
Intent Agent | Parses Roman Urdu/English input into structured JSON via Gemini 2.5 Flash |
POST |
/api/match-providers |
Matching Agent | Ranks providers using a weighted 6-factor scoring algorithm |
POST |
/api/calculate-price |
Pricing Agent | Computes dynamic pricing with 7 factors (base, distance, urgency, complexity, surge, loyalty, budget) |
POST |
/api/book-service |
Booking Agent | Handles booking transactions with double-booking prevention |
POST |
/api/simulate-followup |
Follow-up Agent | Simulates post-booking timeline notifications |
POST |
/api/submit-feedback |
Follow-up Agent | Submits star rating + comment; updates rolling average |
POST |
/api/file-dispute |
Dispute Agent | Processes disputes through a severity-based decision tree |
The Matching Agent scores every available provider using a composite weighted formula:
| Factor | Weight | Description |
|---|---|---|
| Rating | 25% | Normalized provider rating (1โ5 โ 0โ1) |
| Availability | 20% | Exact time-slot match = 1.0, partial = 0.5, none = 0.0 |
| Distance | 20% | Google Maps API driving distance, capped at 20 km (closer = higher score) |
| Specialization | 15% | Exact skill match vs. general provider |
| On-Time Reliability | 15% | Historical punctuality score (0โ1) |
| Review Recency | 5% | Exponential decay โ recent reviews weighted more |
Formula:
score = (rating ร 0.25) + (availability ร 0.20) + (distance ร 0.20) +
(specialization ร 0.15) + (onTime ร 0.15) + (recency ร 0.05)
Providers are sorted descending by score. The top recommendation includes a reasoning trace explaining why it beat the runner-up (e.g., "Selected despite being 1.8km farther due to 31% higher reliability").
{
"id": "prov_ac_001",
"name": "Ali AC Services (G-13)",
"service_types": ["AC technician"],
"location": { "lat": 33.6442, "lng": 72.9918, "area": "G-13" },
"rating": 4.5,
"on_time_score": 0.96,
"cancellation_rate": 0.02,
"price_per_hour": 2500,
"specializations": ["Inverter AC Fix", "Split AC Maintenance", "Gas Charging"],
"availability_slots": ["09:00-12:00", "13:00-16:00", "17:00-20:00"],
"risk_score": "low"
}The service lifecycle is orchestrated as a state machine with 7 states:
INTENT_PARSING โ PROVIDER_MATCHING โ PRICING โ BOOKING โ
LIVE_TRACKING โ FEEDBACK โ DISPUTE_RESOLUTION (optional)
Each transition is driven by the API response of the previous state:
- If
confidence_score < 0.70โ loop back toINTENT_PARSINGwith a clarification question - If
ranked_listis empty โ fallback to broadening the search radius - If
conflict: trueon booking โ suggest alternative time slots - If dispute
severity === "serious"โ escalate to human support, freeze funds
All transitions emit structured reasoning traces to console.log and Firestore agent_logs.
| Factor | Formula | Example |
|---|---|---|
| Base Price | provider.price_per_hour ร hours |
2500 ร 2 = 5000 PKR |
| Distance Cost | max(0, km - 3) ร 20 |
5 km โ 40 PKR |
| Urgency | ร 1.0 / 1.2 / 1.5 |
Same-day = ร1.2 |
| Complexity | ร 1.0 / 1.3 / 1.6 |
Intermediate = ร1.3 |
| Surge (Peak Hours) | ร 1.3 if 17:00โ20:00 |
Evening booking = ร1.3 |
| Loyalty Discount | โ5% if returning user |
โ325 PKR |
| Budget Alternative | Find cheaper provider | Suggest alternative |
| Severity | Action | Refund |
|---|---|---|
| Minor | Auto-credit | PKR 100 flat |
| Moderate | Partial refund | 30% of booking total |
| Serious | Escalate to human + freeze funds | Full review |
Provider risk scoring: cancellation/no-show events increment cancellation_rate. If rate > 20%, provider is flagged as HIGH RISK and deprioritized in matching.
- Node.js 18+
- Expo CLI (
npm install -g expo-cli) - Firebase project with Firestore enabled
- Google Maps API key (Distance Matrix enabled)
- Gemini API key
cd backend
npm install
# Create .env with: PORT, GEMINI_KEY, MAPS_KEY, FIREBASE_PROJECT_ID
# Place firebase-service-account.json in backend/
node -r dotenv/config index.jscd mobile
npm install
npx expo start
# Press 'w' for web, or scan QR with Expo Go app| Variable | Description |
|---|---|
PORT |
Backend server port (default: 5000) |
GEMINI_KEY |
Google Gemini API key for NLP processing |
MAPS_KEY |
Google Maps API key for distance calculations |
FIREBASE_PROJECT_ID |
Firebase project identifier |
| Component | Latency | Cost per Request |
|---|---|---|
| Gemini 2.5 Flash (NLP) | ~800msโ2s | ~$0.0001 (input) + ~$0.0004 (output) |
| Google Maps Distance Matrix | ~200ms | $5 per 1000 elements |
| Firestore Read/Write | ~50ms | $0.06 per 100K reads |
| Full Booking Flow | ~3โ5s | ~$0.005 total |
- Provider data is pre-seeded in Firestore (15 providers across 5 service categories)
- User authentication is simulated (hardcoded
user_idstrings) - WhatsApp notifications are simulated via console logs
- Review recency uses a fixed 5-day decay (no real timestamp tracking)
- Geocoding uses a mock lookup table for Islamabad sectors
- No real-time GPS tracking (timeline is simulated with
setTimeout) - No payment gateway integration (prices are calculated but not charged)
- No image/voice input support (text-only NLP)
- Provider availability resets require manual Firestore updates
- Surge pricing is time-slot-based, not demand-based
- No multi-language UI (interface is English-only; NLP supports Urdu input)
antigravity-service-app/
โโโ backend/
โ โโโ agents/
โ โ โโโ intentAgent.js # Gemini-powered NLP
โ โ โโโ matchingAgent.js # 6-factor provider ranking
โ โ โโโ pricingAgent.js # Dynamic pricing engine
โ โ โโโ bookingAgent.js # Booking + double-booking prevention
โ โ โโโ followupAgent.js # Timeline simulation + feedback
โ โ โโโ disputeAgent.js # Severity-based dispute resolution
โ โโโ docs/ # Stress test results & traces
โ โโโ workflows/ # State machine definitions
โ โโโ index.js # Express gateway
โ โโโ .env # API keys
โโโ mobile/
โ โโโ screens/
โ โ โโโ ChatInputScreen.js
โ โ โโโ ProviderListScreen.js
โ โ โโโ PricingScreen.js
โ โ โโโ BookingConfirmationScreen.js
โ โ โโโ LiveTrackingScreen.js
โ โ โโโ FeedbackScreen.js
โ โ โโโ DisputeScreen.js
โ โโโ config.js # API base URL config
โ โโโ App.js # Navigation + font loading
โโโ README.md
| Layer | Technology |
|---|---|
| Frontend | React Native (Expo SDK 55) |
| Backend | Express.js (Node.js) |
| Database | Cloud Firestore |
| NLP Engine | Google Gemini 2.5 Flash |
| Distance API | Google Maps Distance Matrix |
| Fonts | Inter (Google Fonts) |
| Icons | Expo Vector Icons (Ionicons, Feather) |
| Animations | React Native Animated API |
Built during a hackathon with โค๏ธ and Antigravity.