MileMend: Autonomous Agentic AI Delivery Recovery System

Rescuing failed last-mile deliveries across India through autonomous multilingual WhatsApp engagement and Amazon Bedrock agentic reasoning.


Inspiration

In India's rapidly expanding e-commerce landscape, the last mile remains the most expensive and vulnerable leg of the supply chain. Between 25% and 35% of all first-attempt deliveries in India fail, directly resulting in catastrophic Return to Origin (RTO) churn:

  • Locked Premises & Gated Communities: Drivers arrive at apartment complexes where security guards deny entry or customers are briefly away.
  • Ambiguous Vernacular Addresses: Indian addresses routinely omit formal door numbers, relying instead on landmarks ("Opposite Hanuman Temple, behind old water tank"), confounding standard GPS mapping.
  • Cash-on-Delivery (COD) Timing Friction: Customers are unprepared with exact physical cash at the doorstep when an unannounced courier arrives.
  • Communication & Language Disconnect: Drivers call customers while on moving motorbikes. Customers decline unfamiliar phone numbers or struggle across language barriers when couriers speak a different regional dialect.

Every single RTO package incurs ₹150 to ₹250 in dead freight loss, packaging wear, and inventory lockup. For a mid-sized merchant shipping 20,000 orders monthly, RTO losses exceed ₹12,00,000 to ₹20,00,000 every month.

We asked ourselves: What if delivery failures could be rescued autonomously within seconds on the one application 500+ million Indians check every day — WhatsApp?

That vision inspired MileMend: an autonomous, event-driven agentic AI platform built on AWS that bridges couriers, customers, delivery agents, and operations managers in real time.


What It Does

MileMend detects delivery exceptions the second they occur and automatically recovers them through a policy-governed, multi-tier communication pipeline:

  1. Instant Event Intake: Ingests non-delivery reports (NDR) from courier webhooks (Delhivery, BlueDart, Shadowfax) or CSV batch uploads with automated header normalization.
  2. Proactive Multilingual WhatsApp Outreach: Dispatches approved Meta utility templates via AWS End User Messaging Social in the customer's native regional language (Telugu, Hindi, Gujarati, or English) with 1-tap quick action buttons:
    • Option 1: Try again today (Evening slot)
    • Option 2: Try tomorrow morning
    • Option 3: Update delivery address / landmark
    • Change language
  3. Agentic Reasoning via Amazon Bedrock: Understands natural vernacular responses, voice notes, and address corrections using Amazon Bedrock (Nova / Claude Sonnet), invoking strict policy tools to reschedule deliveries, save corrected geo-pins, or offer courtesy credits.
  4. Real-Time Stakeholder Synchronization: The moment a customer selects a solution:
    • The courier management system receives an automated update.
    • The Delivery Agent (Driver) receives a single, clean WhatsApp alert in direct English formatted with bold operational labels (*Order:*, *Customer:*, *Instruction:*, *Address:*).
    • The Operations Manager receives an executive summary alert on WhatsApp.
  5. Post-Resolution Intelligence: If the customer texts afterwards ("Thank you", "OK"), MileMend acknowledges the message politely without opening duplicate cases or sending spurious driver alerts.

Mathematical & Economic Impact Model

To measure the business impact of MileMend over traditional single-SMS courier blast systems, we modeled the unit economics of Return to Origin (RTO) in India:

1. Cumulative RTO Loss Equation

For a merchant with $N$ monthly shipments and a first-attempt failure rate of $\alpha$, the gross loss from unrecovered parcels without agentic intervention is:

$$\text{Loss}{\text{RTO}} = N \cdot \alpha \cdot (1 - R{\text{baseline}}) \times \left( C_{\text{forward}} + C_{\text{reverse}} + C_{\text{packaging}} + C_{\text{restock}} \right)$$

Where:

  • $N = 20,000$ shipments/month
  • $\alpha = 0.30$ (30% failure rate $= 6,000$ failed attempts)
  • $R_{\text{baseline}} = 0.325$ (32.5% recovery rate with traditional manual phone calls)
  • Total non-recoverable cost per RTO order $C_{\text{unit}} = ₹200.00$

$$\text{Loss}_{\text{traditional}} = 20,000 \times 0.30 \times (1 - 0.325) \times 200 = ₹8,10,000 \text{ per month}$$

2. Autonomous Recovery Net Savings

MileMend elevates the recovery success rate from $R_{\text{baseline}}$ to $R_{\text{MileMend}} = 78.0\%$:

$$S_{\text{gross}} = N \cdot \alpha \cdot \left( R_{\text{MileMend}} - R_{\text{baseline}} \right) \times C_{\text{unit}}$$

$$\Delta R = 0.780 - 0.325 = +45.5\% \text{ recovery gain}$$

$$S_{\text{gross}} = 6,000 \times 0.455 \times ₹200 = ₹5,46,000 \text{ gross freight saved / month}$$

Subtracting cloud messaging and LLM inference expenses ($C_{\text{cloud}} \approx ₹0.85$ per engaged case):

$$S_{\text{net}} = S_{\text{gross}} - (N \cdot \alpha \cdot C_{\text{cloud}}) = ₹5,46,000 - (6,000 \times 0.85) = \mathbf{₹5,40,900 \text{ net monthly savings}}$$

3. Resolution Velocity Speedup

Resolution duration drops by over 85%:

$$\text{Speedup} = \frac{T_{\text{manual}} - T_{\text{MileMend}}}{T_{\text{manual}}} \times 100\% = \frac{28.5\text{ min} - 4.2\text{ min}}{28.5\text{ min}} \times 100\% = \mathbf{85.26\% \text{ faster}}$$


How We Built It

MileMend was architected as a production-ready, cloud-native monorepo adhering to clean architecture, idempotency, and local-first development:

                  ┌────────────────────────────────────────┐
                  │ Courier Webhooks (Delhivery/Shopify)   │
                  │ CSV Upload / Direct REST API           │
                  └──────────────────┬─────────────────────┘
                                     │
                                     ▼
                      ┌────────────────────────────┐
                      │    FastAPI Case Engine     │
                      │  (Idempotency & Profiling) │
                      └──────────────┬─────────────┘
                                     │
                                     ▼                        
                           ┌────────────────────┐     
                           │  AWS End User      │     
                           │  Messaging Social  │     
                           │ (Meta WhatsApp API)│     
                           └──────────┬─────────┘     
                                    │
                                    ▼
                           ┌──────────────────────────────────────────────┐
                           │        Amazon Bedrock AgentCore              │
                           │    (Nova Lite / Claude Sonnet Model)         │
                           │  - Reschedule Delivery Tool                  │
                           │  - Address & Landmark Normalizer             │
                           │  - Courier Write-back API Sync               │
                           │  - Driver & Ops Manager Notification Tool    │
                           └──────────────────────┬───────────────────────┘
                                                │
                                                ▼
                           ┌──────────────────────────────────────────────┐
                           │  React 18 + Vite + Tailwind Operations UI    │
                           │  - Real-time KPI Command Center (0-fallback) │
                           │  - WhatsApp Conversation Dark Emulator       │
                           │  - On-Demand Monte Carlo 200-Case Simulator  │
                           └──────────────────────────────────────────────┘

Core Technologies

  • AWS End User Messaging Social: Primary engagement rail communicating directly via official Meta WhatsApp Business utility templates and two-way session messaging in Mumbai (ap-south-1).
  • Amazon Bedrock (Converse API & AgentCore): Dynamic multi-turn reasoning with safety guardrails and strict tool policies (the LLM cannot invoke external APIs directly; only validated policy tools execute actions).
  • AWS CDK v2 (TypeScript): Infrastructure as Code defining KMS encryption keys, DynamoDB tables with GSIs and TTL, S3 audit buckets, and EventBridge buses.
  • FastAPI & Python 3.12 Backend: Event routing, HMAC-SHA256 webhook signature verification, and conversation state machines.
  • React 18, Vite & Tailwind CSS Dashboard: Enterprise dark glassmorphic command center with a live WhatsApp conversation emulator, stakeholder notification trackers, and an on-demand Monte Carlo batch simulation engine.

Challenges We Faced

  1. Meta WhatsApp 24-Hour Session Constraints & TRAI Quiet Hours: Indian telecom regulations (TRAI) strictly prohibit commercial SMS between 9:00 PM and 8:00 AM IST. Meanwhile, Meta enforces a strict 24-hour customer service window for session messages. We engineered a centralized ChannelGateway policy engine that verifies consent, enforces quiet hours, dynamically chooses between templates and freeform text, and falls back to morning schedules automatically.

  2. Multilingual Vernacular Understanding & Language Switching: Customers often type replies in transliterated vernacular ("aaj shaam ko aao", "repu morning ivvandi"), or click "Change language" mid-conversation. We built deterministic regex interceptors paired with Bedrock system prompts to seamlessly switch context to English, Telugu, Hindi, or Gujarati without losing the order state or dropping the conversation turn.

  3. Stakeholder Notification Hygiene & Eliminating Spam: Initially, every conversational turn—even selecting "Change language"—fired an alert to delivery agents. We resolved this by building strict stakeholder notification filters: drivers and managers are only notified when a concrete delivery recovery decision occurs (RESOLVED or ESCALATED), and all messages to drivers are strictly sanitized into direct, clean English without internal system labels.

  4. Post-Resolution State Integrity: When customers sent courteous replies like "Thank you" or "Ok" after their delivery had already been rescheduled, the system mistakenly treated them as unassigned customers and spawned new cases. We implemented find_latest_case_by_phone to route follow-ups into the existing case's timeline and deliver a polite confirmation without creating ghost cases.


Accomplishments That We're Proud Of

  • Live End-to-End Verification on Real Phones: Tested successfully over live WhatsApp with actual customer numbers, dedicated delivery agent lines, and operations manager phones.
  • True Zero-State Telemetry: Completely eliminated hardcoded mock fallbacks so the dashboard accurately reflects live database metrics: 0 active cases, 0 resolved, and ₹0 spent when clean.
  • Bulletproof 67-Test Automated Suite: 67 continuous integration tests verifying HMAC verification, webhook parsing, Bedrock tool invocations, multilingual switching, and idempotency locks.
  • Authentic WhatsApp Simulator UI: Built a pixel-perfect, dark-mode WhatsApp conversation preview right inside the operations console with real timestamps and action pills.
  • On-Demand 200-Case Simulation Engine: Interactive Monte Carlo simulation allowing evaluators and judges to project logistics ROI on demand.

What We Learned

  • The Power of AWS End User Messaging Social: Moving from fragmented third-party BSPs to native AWS End User Messaging Social provides sub-second delivery latency, robust security with AWS IAM, and seamless integration with the broader AWS ecosystem.
  • Agentic AI Requires Tool Governance: LLMs excel at understanding messy human intent (spelling mistakes, colloquialisms, location descriptions), but must NEVER directly execute database writes or carrier API mutations. Separating reasoning (Bedrock) from execution (strict policy tools with validation schemas) is essential for enterprise safety.
  • Vernacular Accessibility Drives Conversion: Providing Telugu, Gujarati, and Hindi options immediately increased customer response rates compared to standard English-only alerts.

What's Next for MileMend

  • Voice AI Calls via Amazon Connect: Expanding outreach to non-literate buyers through automated, bi-directional voice agents speaking regional dialects.
  • ONDC (Open Network for Digital Commerce) Integration: Direct plug-ins for India's unified open e-commerce and logistics network.
  • Predictive Pre-Dispatch Risk Scoring: Machine learning models that flag high-risk delivery addresses before the parcel ever leaves the merchant warehouse, preempting delivery failures before dispatch.

Built With

  • amazon-bedrock
  • amazon-nova
  • amazon-web-services
  • aws-cdk
  • aws-dynamodb
  • aws-ec2
  • aws-end-user-messaging
  • aws-kms
  • aws-ses
  • aws-sns
  • bedrock-agentcore
  • boto3
  • claude-3-5-sonnet
  • fastapi
  • meta-cloud-api
  • pydantic
  • python
  • react
  • tailwind-css
  • typescript
  • uvicorn
  • vite
  • whatsapp-business-api
  • zod
Share this project:

Updates

Submission history