Skip to content

Koushik0901/Captain-Cargo---AI-Delivery-Tracking-System

Repository files navigation

🚒 Captain Cargo

The voice agent that actually knows where your package is.

You know the drill. You call customer support, wait 10 minutes on hold, finally get through, and then... "Could you hold while I check that?" 😀

Captain Cargo is different. Pick up the phone, ask "Where's my stuff?", and get an answer in milliseconds. No hold music. No sighing. Just your package status.

Built with FastAPI + Vapi + Sanity.io. Tested with 75 tests. Deployed and ready to go.


🎯 What Does This Do?

Imagine this:

You: "Hey, where's my package?"
Captain Cargo: "Your package TRK123456789 is on its way! Expected delivery: tomorrow by 5 PM."
You: "Thanks!"
Captain Cargo: "You're welcome! 🚚"

That's it. That's the whole interaction. No menus, no "press 1 for...", no "your call is important to us."


✨ Why Captain Cargo?

Feature What It Means For You
πŸ€– Conversational Talk like a human, get human answers
πŸ›‘οΈ Bulletproof Circuit breaker, retries, cache β€” won't crash when your database sneezes
πŸ“Š Observable Health checks, metrics, logs β€” know what's happening
πŸŽͺ Hallucination-Safe Only tells you what the database actually says
πŸ§ͺ Tested 75 tests. Every. Single. One. Passes.

πŸš€ Get It Running

One-Line Setup

git clone https://github.com/Koushik0901/Captain-Cargo---AI-Delivery-Tracking-System.git
cd Captain-Cargo---AI-Delivery-Tracking-System
pip install -r requirements.txt
cp .env.example .env  # Fill in your Sanity credentials

Start the Server

# For development (auto-reload on changes)
uvicorn server:app --reload

# For production
python server.py

Your webhook will be live at http://127.0.0.1:8000/webhook πŸŽ‰


πŸ”§ Configuration

Captain Cargo needs to know where your data lives. Here's the deal:

Variable What It Is Default Required?
SANITY_PROJECT_ID Your Sanity project ID β€” βœ… Yes
SANITY_DATASET Which dataset to query production ❌
SANITY_API_TOKEN Read-only API token β€” βœ… Yes
CACHE_TTL How long to cache results (seconds) 60 ❌
LOG_LEVEL DEBUG, INFO, WARNING, ERROR INFO ❌

Drop these in your .env file and you're golden.


πŸ“‘ API Endpoints

Health Checks β€” "Is this thing on?"

# Kubernetes liveness probe
curl http://localhost:8000/healthz
# β†’ {"status":"ok"}

# Readiness (includes dependency status)
curl http://localhost:8000/readyz
# β†’ {"status":"ready","dependencies":{"circuit_breaker":"closed","failure_count":0}}

# Metrics for monitoring
curl http://localhost:8000/metrics
# β†’ {"requests_total":100,"cache_hits_total":60,"cache_hit_rate":0.6,...}

The Main Event β€” Vapi Webhook

POST /webhook

{
  "message": {
    "content": "Where's my package ABC123?",
    "toolCalls": [
      {
        "function": {
          "name": "track_delivery",
          "arguments": "{\"trackingId\": \"ABC123\"}"
        }
      }
    ]
  }
}

Response:

{
  "status": "success",
  "message": "Your package ABC123 is in transit.",
  "delivery_details": {
    "tracking_number": "ABC123",
    "status": "in_transit",
    "estimated_delivery": "2024-01-16T17:00:00Z"
  }
}

πŸ—οΈ Under the Hood

                    πŸ“ž CALLER
                        β”‚
                        β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚     VAPI      β”‚  ← Speech β†’ Text, Text β†’ Speech
                β”‚   (The Voice)  β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
                        β”‚ POST /webhook πŸ“©
                        β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚  CAPTAIN CARGO β”‚  ← FastAPI webhook handler
                β”‚   (The Brain) β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
           β”‚            β”‚            β”‚
           β–Ό            β–Ό            β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚   πŸ—„οΈ     β”‚  β”‚   πŸ“Š     β”‚  β”‚   πŸ“     β”‚
    β”‚  Cache   β”‚  β”‚ Metrics  β”‚  β”‚  Logger  β”‚
    β”‚ (60s TTL)β”‚  β”‚          β”‚  β”‚          β”‚
    β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
         β”‚              β”‚              β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚
                        β–Ό
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β”‚    SANITY     β”‚  ← Your delivery data
                β”‚     CMS       β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ§ͺ Testing (Because We Care)

# Run all 75 tests
pytest tests/ -v

# 75 passed in 3.67s πŸŽ‰

Test Coverage

Category What It Tests
🧱 Unit Individual functions and classes
πŸ“ Contract Pydantic model validation
πŸ”— Integration Full request/response cycles

🎭 Evaluation Harness

Think of this as a "simulated caller" that runs through dozens of scenarios and scores Captain Cargo:

python scripts/eval_replay.py \
  --input eval/cases.jsonl \
  --server http://localhost:8000 \
  --report eval/report.md

Sample output:

Total Cases: 50 | Passed: 47 | Accuracy: 94%
Avg Latency: 127ms | P95 Latency: 312ms

Check out eval/report.md for a real example.


🎬 Demo Video

Watch Captain Cargo in action β†’ Demo Video

Shows: User calls β†’ Agent asks tracking ID β†’ Tool call β†’ Status response β†’ Fallback when backend's down


πŸ—£οΈ The Conversation Flow

Happy Path πŸ¦„

πŸ“ž Caller: "Where's my package?"

πŸ€– Vapi (STT): "Where's my package?"
πŸ€– Vapi (NLU): Intent: track_delivery

πŸ€– Vapi β†’ Captain Cargo: POST /webhook {trackingId: "ABC123"}

πŸ“¦ Captain Cargo β†’ Sanity: "Give me ABC123"
πŸ“¦ Sanity β†’ Captain Cargo: {status: "in_transit", ...}

πŸ€– Captain Cargo β†’ Vapi: {message: "Your package is in transit!"}

πŸ€– Vapi (TTS): "Your package ABC123 is in transit!"
πŸ“ž Caller: "Oh great, thanks!"

When Things Go Wrong 😬

πŸ“ž Caller: "Where's TRK999?"

πŸ€– Vapi β†’ Captain Cargo: POST /webhook {trackingId: "TRK999"}

⚑ Captain Cargo β†’ Sanity: (circuit breaker OPEN - Sanity is down)

πŸ€– Captain Cargo β†’ Vapi: {status: "fallback", message: "Having trouble accessing latest data..."}

πŸ€– Vapi (TTS): "I'm having trouble accessing the latest data. Please try again in a moment."
πŸ“ž Caller: "Okay, thanks anyway."

πŸŽ›οΈ Vapi Provider Configuration

Captain Cargo is provider-agnostic. Your webhook doesn't care about voice stuff β€” Vapi handles all that.

Speech-to-Text (STT) β€” "What did they say?"

Provider When To Use Setup
Deepgram Fast & accurate Vapi Dashboard β†’ Add Deepgram Key
AssemblyAI Good streaming Vapi Dashboard β†’ Add AssemblyAI Key
OpenAI Whisper Highest accuracy Vapi Dashboard β†’ Add OpenAI Key

Text-to-Speech (TTS) β€” "What should I say?"

Provider When To Use Setup
ElevenLabs Natural, emotional voices Vapi Dashboard β†’ Add ElevenLabs Key
OpenAI Fast, decent quality Vapi Dashboard β†’ Add OpenAI Key
Azure Enterprise needs Vapi Dashboard β†’ Add Azure Key

Want to Switch Providers?

  1. Go to Vapi Dashboard
  2. Pick your provider
  3. Enter API key
  4. That's it. Captain Cargo doesn't need to know. 😎

🏒 Project Structure

captain-cargo/
β”œβ”€β”€ server.py                 # FastAPI entry point πŸšͺ
β”œβ”€β”€ requirements.txt          # Python packages πŸ“¦
β”œβ”€β”€ .env.example              # Environment template πŸ“
β”œβ”€β”€ README.md                 # You are here πŸ‘‹
β”œβ”€β”€ specs/                    # Master plans πŸ—ΊοΈ
β”‚   └── 001-voice-agent-prod/
β”œβ”€β”€ models/                   # Pydantic models 🧱
β”‚   β”œβ”€β”€ webhook.py           # Webhook payload shapes
β”‚   └── delivery.py          # Delivery entity shapes
β”œβ”€β”€ services/                 # Business logic 🧠
β”‚   β”œβ”€β”€ cache.py             # 60s TTL cache
β”‚   β”œβ”€β”€ sanity_client.py     # Sanity API + circuit breaker
β”‚   └── response_builder.py   # Hallucination-safe responses
β”œβ”€β”€ middleware/               # HTTP middleware 🍡
β”‚   β”œβ”€β”€ correlation.py       # Correlation IDs
β”‚   └── validation.py        # Request validation
β”œβ”€β”€ utils/                    # Utilities πŸ› οΈ
β”‚   β”œβ”€β”€ config.py            # Environment validation
β”‚   β”œβ”€β”€ logger.py            # JSON structured logs
β”‚   └── normalization.py     # Tracking ID cleaning
β”œβ”€β”€ endpoints/               # API endpoints πŸ”Œ
β”‚   β”œβ”€β”€ health.py            # /healthz, /readyz
β”‚   └── metrics.py           # /metrics
β”œβ”€β”€ scripts/                  # Tools πŸ”§
β”‚   └── eval_replay.py      # Evaluation harness
└── tests/                    # 75 tests passing βœ…
    β”œβ”€β”€ unit/
    β”œβ”€β”€ contract/
    └── integration/

πŸš€ Deployment

Docker (One Command)

docker build -t captain-cargo .
docker run -p 8000:8000 \
  -e SANITY_PROJECT_ID=xxx \
  -e SANITY_API_TOKEN=xxx \
  captain-cargo

Kubernetes

apiVersion: apps/v1
kind: Deployment
metadata:
  name: captain-cargo
spec:
  replicas: 3
  containers:
  - name: captain-cargo
    image: captain-cargo-agent
    ports: [8000]
    env:
    - name: SANITY_PROJECT_ID
      valueFrom:
        secretKeyRef:
          name: sanity-creds
          key: project-id

πŸ§‘β€πŸ’» Contributing

See AGENTS.md for guidelines. We're friendly! πŸ™Œ


πŸ“„ License

MIT. Go forth and ship! 🚒


Captain Cargo β€” Because your customers deserve to know where their stuff is. πŸ“¦βœ¨

About

A production-grade voice agent for delivery tracking using FastAPI, Vapi (conversational AI), and Sanity.io.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors