TARS
Voice-first multilingual FMCG field-sales order capture agent (Hinglish, Tanglish, Marathi) built on Gemini Live bidirectional PCM audio—treating the LLM strictly as an untrusted intent parser gated by a deterministic rules firewall and spoken confirmation state machine.
Problem Space
India's 12M+ kirana retail outlets still rely on error-prone phone/paper order capture, yet letting a voice LLM write directly to an ERP risks hallucinated SKUs, broken credit rules, and floating-point billing bugs.
Production Architecture
Streams 16kHz/24kHz PCM audio between a React PWA AudioWorklet and Gemini Live through a FastAPI OrderOrchestrator where pure Python rules enforce credit, discount, and stock invariants in exact integer paise before repo.py commits any invoice.
Execution Pipeline
- STAGE 01
Bidirectional PCM Voice Bridge
Web Audio API AudioWorklet streams 16kHz PCM audio over WebSocket to GeminiLiveBridge and plays 24kHz output audio with real-time barge-in support.
- STAGE 02
Multilingual Fuzzy Resolution
RapidFuzz token_set_ratio matches kirana outlets (≥0.85) and SKUs (≥0.80) across Hinglish, Tanglish, and Marathi, asking disambiguation questions below threshold.
- STAGE 03
Deterministic Rules Firewall
Pure zero-I/O functions evaluate credit limits, trade schemes, and stock in exact int paise—hard-locking breaches in PENDING_APPROVAL for the Manager Queue.
- STAGE 04
Audited Spoken Commit Gate
5-state machine (DRAFT → CONFIRMING → COMMITTED) resets on corrections, audits every tool call to live SSE traces, and commits ERP invoices solely through repo.py.
Key Engineering Trade-Offs & Decisions
- Enforced 8 non-negotiable invariants including 'LLM proposes, rules decide' and zero direct LLM-to-ERP writes.
- Eliminated float money bugs by keeping all pricing, credit, and scheme math in integer paise across Pydantic v2 DTOs and SQLAlchemy models.
- Built an automated 4-scene rehearsal runner (rehearse_demo.py) executing 12 audited tool calls in ~385–414 ms (9–13 ms median latency).
- Passed 184 backend pytest tests, 7 frontend vitest tests, ruff lint, and mypy --strict across all 31 backend files.
Tech Stack
Containerized with Docker Compose (backend :8000, frontend :5173) and pre-configured for Google Cloud Run (asia-south1) with WebSocket session affinity and Secret Manager.
Open-source repo: PRs, issues, and feature collabs are always welcome on GitHub.