Inside one turn: a workflow, not an agent loop
The steps are known in advance and the cost of a wrong step is a double booking, so code decides the next step. The model is used only to read words. Every turn returns the list of tools it called — the transcript is also the audit trail.
One turn, step by step
Every inbound WhatsApp message follows the same ten steps. Pick a message and watch it travel. Red-marked steps can stop the flow.
The booking transaction, line by line
The most important code in the system: capacity.commit(). Click a line — or let it step through.
The language layer and the LLM boundary
Rules read English, Hinglish, Hindi, Gujarati, Marathi, Punjabi and Marwari with no model call: clock times (11:30, 7 baje, 7 बजे), durations (dedh ghanta, डेढ़ घंटा), choices ("pehla"), safety words and urgency claims. A model is called only when rules return UNKNOWN.
Checks in code after the model replies
Strict JSON shape for the fallback
{
"intent": ["REPORT_DELAY","EARLY_ARRIVAL","ASK_OPTIONS",
"CHECK_STATUS","CHOOSE","DECLINE",
"ASK_HUMAN","SAFETY","UNKNOWN"],
"eta": { "kind": ["CLOCK","DELAY","WINDOW","VAGUE"],
"clock": "^([01][0-9]|2[0-3]):[0-5][0-9]$",
"delay_min": "0..720",
"window": ["HH:MM","HH:MM"],
"hedged": true },
"limits": { "earliest_start": null, "latest_gate_out": null },
"shipment_hint": ["MORNING","EVENING","HEAVY","REEFER",null],
"choice": "1..3",
"safety": false,
"evidence": { "": "" }
}
// additionalProperties: false — anything else is UNKNOWN
// The model's output can change what we ask, never what we book. From prototype to pilot
The decision engine runs in the demo. The production layer around it is now in the repository, with 64 offline tests (40 of them for the WhatsApp channel). The driver channel runs on WhatsApp through Twilio: it has been played end to end through a local simulator that sends Twilio-signed webhooks and delivery receipts, but a round trip on the live Twilio Sandbox has not been run yet (steps in docs/twilio_live_test.md). It has also not yet run against Cognito, a real Redis server, LangSmith or the Anthropic API.
| Layer | Component · technology | File in the repo | Demo engine |
|---|---|---|---|
| Inbound | FastAPI; WhatsApp Business Cloud API webhook, signature verified | app.py | workflow.handle(phone, text, as_of, external_id) |
| Identity | Driver = WhatsApp number; coordinator = Cognito sign-in (email or mobile) | setuhaul/auth.py | Phone looked up in drivers |
| Sessions | Redis: sessions, tokens, history, dedupe, per-driver lock, rate limit | setuhaul/session_store.py | conversations + inbound_messages tables |
| Orchestration | LangGraph StateGraph: verify → dedupe → read → safety → dispatch | setuhaul/graph.py | Session.run() |
| Words | Rules; Claude Haiku via LangChain only when rules say UNKNOWN, strict JSON checked in code | setuhaul/nlu.py · setuhaul/llm.py | Rules; a clarifying question instead of the model |
| Tools | ETA, feasibility, planner, booking, escalation — plain Python | eta · timeline · planner · capacity · escalation | Same |
| System of record | MVP 1: SQLite on the server (one writer, overlap trigger, nightly backups). MVP 2: Postgres (EXCLUDE constraint) or MongoDB | setuhaul/db.py | SQLite, BEGIN IMMEDIATE and triggers |
| Outbound | Outbox drained to WhatsApp, SMS, e-mail, phone task | app.py send_whatsapp() | Outbox table |
| Observability | LangSmith trace per turn, phones masked, guardrail tags | setuhaul/tracing.py | audit_log table |
| Humans | Coordinator console: approve, reject, hand-offs, board | app.py /console/* | This prototype's Hand-offs page |
| Cost | One small server (app + SQLite + Redis) ≈ ₹3,000 a month for MVP 1; MVP 2 adds a managed Postgres or MongoDB (about ₹5,000 a month) (see the walkthrough script's cost tables) | ||