Prompt file imported from Fabien-data/AI-Recruitment-System (
.github/prompts/plan-optimizeChatbotSpeedAndMultilingualUnderstanding.prompt.md). Copyright stays with the author.
Plan: Optimize Chatbot Speed & Multilingual Understanding
TL;DR: Make the chatbot respond faster and understand Sinhala/Tamil/Singlish/Tanglish better by: (1) expanding fast-path classification to skip LLM for ~65% of messages, (2) compressing LLM prompts by ~50% tokens, (3) tuning max_tokens/timeouts for speed, (4) enriching language dictionaries, and (5) improving Singlish/Tanglish templates. No flow/state changes needed.
Phase 1: Fast-Path Expansion (Skip LLM for ~65% of messages)
Can run in parallel with Phase 2. Biggest speed win.
Step 1.1 ā Expand _fast_classify() in app/chatbot.py
- Add greetings in all 5 registers:
ayubowan,kohomada,vanakkam,hi, etc. āgreetingintent - Add common job titles in all forms (en/si/ta/singlish/tanglish):
driver,nurse,cook,security,ą¶»ą·ą¶ŗą¶Æą·ą¶»ą·,ą®ą®ąÆą®ąÆą®Øą®°ąÆ,driver velai,driver karannaājob_titleintent with entity extracted - Add country names:
dubai,qatar,saudi,kuwait,malaysia,singapore,maldives,ą¶Æą·ą¶¶ą·ą¶ŗą·,ą®ą®¤ąÆą®¤ą®¾ą®°ąÆ,ą®ą®µąÆą®¤ą®æ,dubai yanna,dubai poganumācountryintent - Add experience patterns:
ą¶ ą·ą·ą¶»ą·ą¶Æą· 5,5 ą®µą®°ąÆą®ą®®ąÆ,varudam 5āyears_experienceintent - Add CV phrases:
cv yawanawa,cv anuppurenācv_uploadintent - Return correct language code per token (currently returns
Nonefor yes/no ā should returnsi/ta/singlish/tanglishbased on which token matched)
Step 1.2 ā Expand language detector dictionaries in app/nlp/language_detector.py
- Add ~30 missing Singlish words:
wadeema(job),raakiyawa(job),salaris(salary),gaathe(money),passport,visa,interview,applay(apply misspelling),readiy(ready) - Add ~30 missing Tanglish words:
sambalam(salary),panam(money),vesa(visa),apply pannanum,ready-ah,ok-ah,seri-ah - Add common misspellings/variations Sri Lankans typically use
Phase 2: Prompt Compression & Quality (~50% fewer tokens)
Can run in parallel with Phase 1. Reduces latency per LLM call.
Step 2.1 ā Compress classify_message_async prompt (~800ā400 tokens)
- Replace verbose prose with compact table format:
intent | description | examples - Add 3 few-shot examples for Tanglish/Singlish edge cases (more effective than long descriptions)
- Remove redundant "IMPORTANT" and "Respond ONLY" sections ā GPT-5-mini follows instructions well
Step 2.2 ā Compress validate_intake_answer_async prompt (~300ā150 tokens)
- Compact validation rules into tight bullet format
Step 2.3 ā Compress classify_and_validate_async combined prompt (~600ā350 tokens)
- Most impactful ā handles all intake states in single LLM call
Step 2.4 ā Compress RAG system prompt language instruction (~500ā250 tokens)
- GPT-5-mini understands multilingual instructions natively ā remove verbose code-switch scenarios
- Keep the critical "match their communication style" rule
Step 2.5 ā Add few-shot examples for South Asian edge cases
"enna job irriki" ā vacancy_query/"dubai poganum" ā country/"aama" ā apply_intent- Few-shot examples are 5x more effective than prose rules for GPT-5-mini
Files: app/llm/rag_engine.py ā all prompt strings and both sync/async variants
Phase 3: Speed Tuning
Can implement in parallel with Phases 1-2
Step 3.1 ā Reduce max_tokens across all LLM calls:
| Call | Current | Target | Reason |
|---|---|---|---|
| classify_message_async | 200 | 150 | JSON output <100 tokens |
| validate_intake_answer_async | 120 | 100 | Short JSON |
| classify_and_validate_async | 280 | 200 | Combined JSON |
| generate_response_async | 220 | 180 | WhatsApp = short msgs |
| generate_missing_field_question | 80 | 60 | Single sentence |
| analyze_cv | 300 | 200 | Summary only |
Step 3.2 ā Tighten timeouts: 10sā8s for classify, 15sā10s for generate, 12sā9s for combined
Step 3.3 ā Increase cache TTL & size: 120sā300s, 500ā1000 entries ā same intent doesn't change in 5 minutes
File: app/llm/rag_engine.py ā constants and all create() calls
Phase 4: Template Enrichment
Independent of all other phases
Step 4.1 ā Clean up duplicate job_confirmed acknowledgment block in prompt_templates.py (currently defined twice with slightly different structure)
Step 4.2 ā Improve Tanglish/Singlish template naturalness
- Current:
"Eppo poiya ā which country poiya work pannanumnnu theriyuma?"(awkward mix) - Target:
"Enna naadu poiya work pannanum? Dubai, Qatar, Saudi ā sollunga da š"(natural code-switch)
Phase 5: Smarter Language-Aware Routing
Depends on Phase 1
Step 5.1 ā When _fast_classify() detects a Sinhala/Tamil/Singlish/Tanglish token, return the correct language code so the response uses matching templates without needing a separate LLM language detection call
Step 5.2 ā Ensure fast-path-handled messages get responses in the user's actual register (e.g., Tanglish input ā Tanglish template reply, not formal Tamil)
Relevant Files
- app/llm/rag_engine.py ā Prompt compression, max_tokens, timeouts, cache (main target)
- app/chatbot.py ā
_fast_classify()expansion, language routing - app/nlp/language_detector.py ā Dictionary expansion
- app/llm/prompt_templates.py ā Template cleanup & enrichment
Verification
- Test
_fast_classify()with inputs in all 5 languages ā verify correct intents for common patterns - Measure prompt token count before/after ā target 50% reduction
- Time LLM API calls ā target <800ms classify, <1.2s response generation
- End-to-end flow test in each language: English, Sinhala, Tamil, Singlish, Tanglish
- Verify cache hit ratio improves (add logging if needed)
- Regression: English flow must be unaffected
Decisions
- No streaming ā WhatsApp API sends complete messages; streaming would create multiple message bubbles
- Aggressive prompt compression ā GPT-5-mini reasons well with compact instructions
- Fast-path to ~65% ā Recruitment intents are highly predictable (greetings, job titles, countries, yes/no)
- Hybrid templates + LLM ā Templates for standard flow, LLM only for questions/unusual input
- Out of scope: Conversation flow/states, CV processing pipeline, recruitment sync, database schema