Skip to content
Yxp23Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

39 Commits

Folders and files

Repository files navigation

Last Call

A voice agent that phones restaurants at closing time, decides what food is safe to give away, and routes volunteer drivers to get it to a shelter before it goes bad. A garden that grows with every meal it saves.

Built solo in 24 hours at MHacks 2026 (theme: Digital Garden: build something that grows).


The story

It's 10 PM on a weeknight. A rice-bowl place on Main Street is closing. There are sixteen bowls left in the warmer, still good, made half an hour ago. Two miles away a shelter serves a late meal to people who haven't eaten since lunch.

Those bowls go in the bin. Not because anyone wants them to, but because nobody at closing time has the time to find a shelter that's still open, check whether the food is still safe, and find a driver who can get it there before it isn't. The staff are mopping floors. The window is an hour or two, and then the food is trash.

That gap, between food that's still good and people who need it, closes every night in every city. Last Call is built for that last hour.

The problem, in numbers

  • 1.05 billion tonnes of food were wasted worldwide in 2022, more than 1 billion meals a day, while 783 million people went hungry. Food service (restaurants, cafeterias, hotels) accounts for 28% of that waste. (UNEP Food Waste Index Report 2024)
  • Food loss and waste produces 8–10% of global greenhouse gas emissions. (UNEP)
  • In the US, 91 million tons of food went unsold or uneaten in 2021, and less than 2% of that surplus was donated. (ReFED, via AgFunderNews)

The bottleneck isn't goodwill. It's logistics at the worst possible moment: a closing kitchen, a food-safety clock that's already running, and volunteers who need to be told exactly where to go.

What Last Call does

  1. It calls the restaurant. At closing time, an ElevenLabs voice agent phones the manager and has an ordinary conversation: what's left, how much, how it's been stored, how long it's been out. Nobody fills in a form or opens an app.
  2. Food-safety rules decide. The answers run through a fixed rules engine (code, not a model's judgment) based on the FDA's 4-hour time-as-a-control rule: hot food can go out tonight if a late-serving shelter is open, chilled and shelf-stable food waits for a morning pickup, and anything at room temperature for over 4 hours is declined.
  3. The optimizer plans the night. Every new donation triggers a re-plan across all drivers, all pickups and all shelters, against each pickup's food-safety deadline and each shelter's receiving hours. It runs in milliseconds.
  4. The driver gets one clear text. The chosen volunteer gets an iMessage: what, where, deliver by when, with a directions link. They answer in plain words ("yes", "can't tonight", "running 10 min late", "picked up"). One offer at a time, never a pile.
  5. The garden grows. Every delivered meal counts toward tonight's CO₂ avoided, and the plant in the Tonight panel grows from seed to sprout to flower as the night goes on.

The demo

The command center walks through it in three steps:

Step What happens
1 · The call The voice agent calls Huron Bowl Kitchen live. The presenter plays the owner. The call is saved, the safety rules check the food, and the feed shows each step.
2 · One pickup, step by step An offer is texted to a real phone. The driver replies "yes". Route optimization is shown in four stages on the map: every candidate driver, how long each would take, who beats the deadline, and the plan's choice. Then the car drives the real road route to the shelter.
3 · The whole evening Four more restaurants are called one after another (one has nothing left, one has food that's been out too long and is declined). Play the night at 30×, then turn on Compare to see the same night planned the naive way.

The moment that matters: Maize & Blue Deli has 18 wraps with 18 minutes left on the 4-hour clock. Sending the nearest driver means sending one who's still busy with another pickup, so he arrives 4 minutes late and all 18 meals are lost. Last Call sends a free driver and arrives with 4 minutes to spare. Compare shows this side by side: 30 vs 12 meals on time, 0 vs 18 expired, for 4 extra minutes of driving.

Does the optimizer actually matter? The benchmark

Last Call's planner and "nearest available driver" dispatch planned the same 200 simulated Ann Arbor evenings (seed 42; 3–8 donations, 2–4 drivers, a mix of hot, chilled and bakery food per evening). Same drivers, same food, same travel times.

Nearest driver Last Call
Meals expired per evening (mean) 8.2 1.3 (84% fewer)
Meals delivered on time (mean) 114.9 123.2 (+7%)
Drive time per evening (mean) 29.8 min 26.9 min (−10%)
Evenings better / equal / worse 161 / 39 / 0
Planning time ~4 ms

Last Call never did worse on any evening. It saves more food and drives less, because it stops sending cars back and forth. The full results, with 95% confidence intervals and a scaling study up to 60 pickups per evening, are in backend/benchmark_results.json and on the dashboard's Benchmark page.

How it works (technical)

flowchart LR
    A[ElevenLabs voice agent<br/>calls the restaurant] -->|save_donation tool| B[FastAPI /intake]
    B --> C[safety.py<br/>rules engine]
    C -->|accept: serve tonight<br/>or chill for tomorrow| D[dispatch.replan_now]
    C -->|reject| F[(Neon Postgres)]
    D --> E[planner.plan_optimized<br/>insertion + local search]
    E --> F
    E --> G[driver_agent<br/>offers, one at a time]
    G -->|POST /send| H[Dispatcher<br/>Bun + Photon Spectrum]
    H -->|iMessage| I[Driver's phone]
    I -->|reply| H -->|/driver/inbound| G
    F --> J[React command center<br/>Mapbox satellite map]
Loading

Voice intake (ElevenLabs)

  • A conversational agent ("Last Call", running on Claude Haiku 4.5 inside ElevenLabs) is started from the dashboard with the restaurant's name and id as dynamic variables.
  • When the conversation has what it needs, it calls a save_donation client tool; the browser posts the structured JSON to POST /intake: has surplus, items and quantities, storage (kept_hot, refrigerated, room_temp, shelf_stable), hours out, whether it was already served to the public, whether it can be refrigerated tonight.
  • /intake validates it, runs the safety rules, saves the donation, re-plans, and narrates every step into the live feed.

Food-safety rules (backend/safety.py)

Pure functions with no database, network or AI, fully unit-tested:

  • No surplus → nothing to do.
  • Already served to the public → declined.
  • Room temperature for more than 4 hours → declined ("over 4 hours in the danger zone").
  • Kept hot → serve tonight if a late-serving, hot-accepting shelter is open now; otherwise chill overnight for a morning pickup if the restaurant can refrigerate it; otherwise declined.
  • Room temperature under 4 hours → serve tonight with a deadline of now + (4 h − time already out), or chill overnight.
  • Refrigerated / shelf-stable → pick up tomorrow.

The deadline that comes out of these rules is the hard constraint the optimizer plans against.

The optimizer (backend/planner.py)

Three planners share one interface and the same constraints; only the search differs:

  • plan_greedy, the baseline: nearest available driver, nearest eligible shelter, no reordering. It's what Compare and the benchmark measure against.
  • plan_insertion: donations taken in deadline order. For each one, every (driver, pickup position, dropoff position) slot is tried, and the cheapest feasible one is taken.
  • plan_optimized, the live planner: insertion, then local search (relocate a pickup to another driver or position, exchange pickups between drivers, retry anything unassigned) until no move improves or 300 ms runs out. The objective is lexicographic: maximize meals delivered before their deadline first, then minimize drive minutes.

Constraints every planner holds:

  • delivery before the donation's safe_until;
  • pickup no earlier than the food is ready;
  • delivery inside the shelter's receiving hours;
  • driver car capacity along the whole route;
  • shelter meal capacity;
  • the driver's own limit on open pickups;
  • the time the driver said they're free until;
  • pickup before dropoff;
  • accepted pickups stay with their driver, and food already on board starts on board.

Travel times come from the Mapbox Matrix API (real road routing), cached in Postgres, with a haversine fallback. Two planning windows run side by side: tonight (late shelters) and tomorrow morning (8 AM–12 PM for chilled food).

Every re-plan triggered by a new donation also runs the greedy planner on the same input and records why the decision differs. That's where the "Why" lines in the feed and the Compare card come from. GET /plan/explain/{id} returns every candidate driver for one pickup, with pickup time, time at the shelter and slack against the deadline. The step-by-step optimization view on the map is drawn from it.

Driver dispatch over iMessage (Photon Spectrum)

  • A small Bun service (dispatcher/) on Photon Spectrum sends and receives iMessages on a dedicated line. Outbound offers go through POST /send. Inbound replies are forwarded to POST /driver/inbound.
  • driver_agent.py keeps an offers table:
    • one pending offer per real driver;
    • offers expire after a timeout and move to the next driver;
    • a driver is never offered the same pickup twice;
    • a stale offer is withdrawn with an "Update:" text when the plan changes.
  • Replies are parsed with a fast keyword intent parser (accept, decline, capacity, running late, picked up, delivered). Ambiguous replies fall back to a Claude Haiku classifier that returns strict JSON.
  • Simulated drivers (Maya, Daniel, Priya) follow their planned routes on the demo clock. The real driver's car moves only after they've said yes.

Command center (frontend/)

  • Stack:
    • React 19 + TypeScript + Vite;
    • Tailwind;
    • Motion for animation;
    • TanStack Query, polling /state every 2 s;
    • react-map-gl on Mapbox GL (standard-satellite style, 3D pitch), with a Leaflet fallback;
    • @elevenlabs/react for the in-browser call.
  • Cars move along their actual road geometry, interpolated on the demo clock, and face their direction of travel.
  • The live feed narrates every step in plain English: Call, Safety, Planned, Why, Text sent, Driver replied, Picked up, Delivered.
  • Tonight's garden grows with kg CO₂e avoided from delivered meals (0.4 kg of food per meal, 2.5 kg CO₂e per kg of food), from seed to flowering.
  • How it works is a six-step animated explainer. Benchmark shows the 200-evening study.

Backend (backend/)

  • Python, FastAPI and psycopg, with a connection pool to Neon Postgres. The pool checks connections before use and uses keepalives so the database's SSL drops don't take the app down.
  • A demo clock (clock.py) that can pause or run at 1×, 10× or 30×, persisted so a restart keeps "9:30 PM tonight".
  • An event feed (events.py) that never raises, so a feed problem can't break /state.
  • 255 tests (pytest), none of which touch a real database.

Running it

Backend

cd backend
python -m venv .venv && .venv/bin/pip install -r requirements.txt
# .env (see .env.example): DATABASE_URL, MAPBOX_TOKEN, DISPATCHER_URL, REAL_DRIVER_PHONE, ANTHROPIC_API_KEY (optional)
.venv/bin/uvicorn main:app --reload --reload-exclude '.venv/*' --port 8000

Dispatcher (iMessage)

cd dispatcher
bun install
# .env: PROJECT_ID, PROJECT_SECRET (Photon Spectrum), BACKEND_URL, DISPATCHER_PORT
bun run dev

Frontend

cd frontend
npm ci
# .env.local: VITE_MAPBOX_TOKEN, VITE_ELEVENLABS_AGENT_ID
npm run dev   # http://localhost:3000

Voice agent: in ElevenLabs, give the agent a client tool named save_donation (with "wait for response" on) and the dynamic variables restaurant_name and restaurant_id. The browser runs the tool and posts the answers straight to the backend's /intake, so no public tunnel is needed. A webhook tool pointing at a public URL plus /intake works too.

Tests

cd backend && .venv/bin/python -m pytest -q

What's real and what's simulated

Real:

  • the voice call;
  • the safety rules;
  • the planner and its benchmark;
  • road travel times;
  • the iMessage to a real phone and the driver's replies;
  • the database and the event feed.

Simulated, for a 3-minute demo:

  • the other restaurants' call answers (scripted intake payloads that go through the same /intake path);
  • three of the four drivers;
  • the demo clock, so an evening plays out in a minute.

What's next

  • Real outbound phone calls to restaurants on a schedule at each one's closing time, instead of calls started from the dashboard.
  • Driver onboarding by text: sign up, set your usual nights, done.
  • Shelter-side confirmations: the shelter texts back when food arrives, which closes the loop and builds a donation receipt for the restaurant's tax deduction.
  • A garden that keeps growing: one plant per night, a season's garden per city.

Built with

ElevenLabs Conversational AI · Photon Spectrum (iMessage) · Mapbox GL + Matrix API · Neon Postgres · FastAPI · React · TypeScript · Vite · Tailwind · Motion · Bun

Built by Yash Patil at MHacks 2026.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages