Pillar 1 becomes live code today. Build the detector that runs before every other layer — looks at the incoming message, decides which of 5 language pipelines should handle it, routes the request. Average latency under 50ms. Under 20¢/day per 1,000 messages.
Every WhatsApp message hitting your webhook is classified in under 50ms and routed to the matching language pipeline.
6 lines of Python. System prompt: 'classify text into fr, en, sw, ar, rn. Return JSON only.' anthropic.messages.create() → {'lang': 'fr', 'confidence': 0.97}. ~300ms latency, ~$0.001/call. Accurate on long + code-switched messages.
Facebook's pretrained lid.176.bin (130 MB, free). Load once at server boot. model.predict(text) → ('__label__fr', 0.94). Sub-5ms latency, zero cost, zero network call. Runs offline. Accuracy drops on very short + heavily code-switched text.
Hybrid logic. Run fastText first (free + fast). If confidence > 0.85 → trust it, route immediately. If confidence < 0.85 → ambiguous, escalate to Claude. ~80% of messages clear fastText directly; only 20% pay the Claude latency.
Simple switch statement → 5 language-specific pipelines (built in Lesson 4.3). 'fr' → French prompt + French KB shard. 'sw' → Swahili pipeline. And so on. The detector is the traffic cop; the pipelines do the work.
Code-switching: pick dominant, add 'also speaks X' note to prompt. Ultra-short ('hi', 'merci'): default to customer profile language, fallback English. Profile override: customer-set language ALWAYS beats auto-detect. Log every detection decision.
Top AI Africa deploys the full stack — language detection, multilingual prompts, native KB per language. WhatsApp agents that sound native in French, English, Swahili, Arabic, and Kirundi. Free 15-min strategy call.