Inspiration Northern California lives one wildfire, one substation fault, or one spoofed SCADA packet away from a cascading blackout — and the first loads at risk are hospitals. At the same time, the industry is rushing to let LLMs "help" run grids, even though a language model will happily propose a dispatch that overloads a line to 118% of its thermal rating. We built GridZero to show the safe way to combine the two: let the AI propose, but let deterministic physics dispose.
What it does GridZero is an autonomous neuro-symbolic micro-grid and civic disaster digital twin of a 12-node South Bay grid (two hospitals, solar/wind/hydro generation, two battery storage sites, two substations, and commercial/residential load), fed by live San Jose weather telemetry from Open-Meteo (solar irradiance, wind, temperature — converted to real MW generation).
When a crisis hits — a Santa Cruz wildfire severing the northern corridors, a Metcalf 500kV transformer trip, or a SCADA telemetry-spoofing cyber attack — a 3-agent Gemini pipeline responds:
AGENT-01 (Topology & Fault Isolator) runs BFS reachability + Dijkstra min-impedance analysis to find severed lines and at-risk critical nodes. AGENT-02 (Battery & Load Forecaster) computes Megapack state-of-charge depletion windows and the minimum load shed needed to keep hospitals alive. AGENT-03 (Neuro-Symbolic Dispatch) drafts a dispatch plan — which the deterministic DC power-flow solver then verifies (nodal power balance, line thermal limits, hospital bus frequency 59.7–60.3 Hz). Draft #1 is visibly REJECTED (ERR_LINE_THERMAL_OVERLOAD_118PCT), corrected through a solver-feedback loop, and only the verified plan — islanded hospital buses at exactly 60.00 Hz, zero violations — is executed. Around the grid core sits a civic response layer: an SOS triage board for hospitals and vulnerable citizens, mobile Megapack/crew dispatch, and multi-lingual emergency alerts.
Everything is live, not mocked: crisis responses are enriched in real time by Gemini (the /api/crisis response carries llm_mode: live_gemini_verified plus the model's own engineering rationale), and if Gemini is ever unreachable, the deterministic solver still produces a safe, verified plan on its own.
How we built it Backend (FastAPI, ~1,100 lines of Python): a hand-written DC power-flow solver (susceptance-weighted phase angles, frequency droop Δf = K·(P_gen − P_load), BFS islanding detection), live Open-Meteo telemetry with thermal PV derating, three crisis presets whose draft plans are genuinely run through the solver, and an optional live-Gemini enrichment layer that is strictly advisory — the solver, never the LLM, has the final word. Benchmark, computed — not hardcoded: GET /api/benchmark runs a 20-contingency ablation suite (3 crisis scenarios × severity variants) through the solver at request time. Nothing is stored in code; the response even documents its own method. Current live results: the raw unverified LLM draft scores 100% hospital-blackout rate, 100% thermal-overload rate, 66 physics violations — the solver-corrected GridZero dispatch scores 0%, 0%, and 0 violations, at a higher renewable share (~79%). Frontend: a single-file tactical command center (HTML5 Canvas grid map, Chart.js telemetry, Web Audio alerts, SOS wizard) that also runs the full simulation in-browser if the backend is down — the demo cannot die. Deployment: full-stack on Vercel — the FastAPI app runs as a Python serverless function (api/index.py), with the Gemini key held only in server-side environment variables. Check /api/health: it reports llm_configured: true and the active model, without ever exposing the key. Challenges we ran into Vercel rewrites silently broke every route. Rewrites forward the destination path to a Python function, so FastAPI received every request as /api/index.py and 404'd the entire API. The fix: carry the original path through the rewrite as a query parameter and restore it in ASGI middleware before routing. Our Gemini key spoke the wrong dialect. The key is a Google Cloud (AQ.) key: Vertex AI was disabled in its project, and Gemini's JSON mode is not enabled on API v1. The working transport is the Developer API pinned to v1beta — and because gemini-3.8-flash is under heavy demand (503/504s), the client retries with backoff and falls across the Flash family (3.8 → 3.6 → 3.5-Lite → 3.1-Lite) with hard timeouts, so a slow model can never hang the crisis endpoint. Keeping the benchmark honest. Our first version had static benchmark numbers. We deleted them and made the endpoint compute all 20 runs live — the numbers in this write-up are whatever the solver produced when we last called it. Accomplishments that we're proud of A working neuro-symbolic loop where an LLM's unsafe plan is provably rejected by physics and corrected — visible on screen, not just claimed. A benchmark with zero hardcoded numbers: every figure in this submission is reproducible by calling /api/benchmark right now. Live Gemini working end-to-end in production (llm_mode: live_gemini_verified), with a deterministic fallback that keeps the grid safe even if the model goes down. A demo that cannot fail: backend down → the frontend runs the whole simulation in-browser. What we learned LLMs are good dispatch drafters and bad dispatch authorities — the winning pattern is a fast generative layer wrapped by a slow, boring, deterministic verifier. We also learned that "it works locally" means nothing on serverless: path rewriting, API version surfaces (v1 vs v1beta), and per-provider key types each silently changed behavior, and only reading the provider's actual error messages — which our API now surfaces, sanitized — got us to a working system.
Built With
- chart.js
- fastapi
- gemini-3.8-flash
- google-gemini-api
- html5
- javascript
- open-meteo-api
- pydantic
- python
- tailwind-css
- vercel