Skip to main content
04 // Voice-First Agentic ERP191 Tests • mypy --strict

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.

RoleArchitect & Full-Stack Engineer
ContextGoogle Gemini Hackathon — Voice-Driven Agentic Workflow
Source Code
Test Suite
191 Tests
Type Safety
31 Files Strict
Demo E2E
~385 ms
INTERACTIVE SYSTEM SIMULATORLIVE CLIENT DEMO
GEMINI LIVE • 16kHz/24kHz PCMINT PAISE • 191 TESTS
DRAFT
PENDING_APPROVAL
CONFIRMING
COMMITTED
"Tiwari ji ke liye 5 carton Glucose biscuit aur do bag atta"
PARSER: RapidFuzz: Tiwari Traders (0.91) · Parle-G (0.88) · Aashirvaad (0.94)
DRAFT → CONFIRMING → COMMITTEDRULES PASS · SPOKEN "HAAN" -> INV-000001 (₹14,250)
LLM PROPOSES · RULES DECIDEE2E ~385ms · MYPY STRICT
01 // THE BOTTLENECK

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.

02 // THE SYSTEM

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

  1. 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.

  2. 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.

  3. 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.

  4. 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

Gemini LiveFastAPIWebSocketsSSESQLAlchemy 2.0Pydantic v2RapidFuzzReact 19TypeScriptCloud Run
Deployment & Runtime

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.