A newer version of the Gradio SDK is available:
6.9.0
metadata
title: Fire Rescue Simulator Game
emoji: ๐ฅ
colorFrom: red
colorTo: blue
sdk: gradio
sdk_version: 6.0.1
app_file: app.py
pinned: true
license: mit
short_description: Multi-stage MCP-driven advisor fights fires autonomously
tags:
- mcp-1st-birthday
- mcp-in-action-track-creative
- agent
- mcp
- game
๐ฅ Fire Rescue Simulator Game
๐ Project Overview
Watch a multi-stage LLM advisor assess, plan, execute, summarize, and debrief every fire-fight cycle while you collaborate or take over manually.
Key Highlights
- Multi-stage advisor (Assess โ Plan โ Execute โ Cycle Summary โ After-Action)
- 10 FastMCP tools cover scenario control, deployment, repositioning, removal, and analytics (idle units, coverage, building threats).
- Real-time Gradio 6 UI: 10ร10 emoji grid, animated status HUD, AI chat timeline, event logs, and clickable placement controls.
- Auto-execute toggle lets players hand full control to the AI or approve every deployment manuallyโincluding adding new fires for stress tests.
- Advisor model switcher directly in the control panel lets you hop between GPT-OSS 120B/20B, Llama-3.1 8B, and OpenAI GPT-5.1 backends.
- AI Battle Report Overlay: After each victory/defeat the agent compiles charts, highlights, risks, and next actions before you rerun.
- Submission-ready metadata: README + prompts + PRD/dev plan + Space tags prepared for the hackathon checklist.
๐ ๏ธ MCP Toolbelt
fire_rescue_mcp/mcp_server.py spins up a FastMCP server that any agent can call (Gradio app, CLI clients, or external copilots). Tools are grouped below:
Scenario + Control
| Tool | Purpose |
|---|---|
reset_scenario |
Build a fresh grid with configurable fire/building/unit caps plus optional seed |
get_world_state |
Snapshot tick, fires, units, buildings, metrics, and emoji map |
step_simulation |
Advance the simulation loop a given number of ticks |
deploy_unit |
Spawn ๐ / ๐ at legal coordinates (never on fire/buildings) |
move_unit |
Remove + redeploy a specific unit in a single call |
remove_unit |
Free a deployment slot when a unit is idle or poorly placed |
Analysis + Planning
| Tool | Purpose |
|---|---|
find_idle_units |
Report units whose coverage radius misses every fire |
find_uncovered_fires |
Fires lacking coverage plus their building-threat status |
find_building_threats |
Fires within 2 cells of buildings + who, if anyone, covers them |
analyze_coverage |
Aggregates idle units, uncovered fires, building threats, and high-intensity hotspots for the planner |
๐ค AI Workflow (Assess โ Debrief)
- Assess (Stage 1) โ Calls the analytic MCP tools to classify intensity, coverage, building threats, idle units, and threat level.
- Plan (Stage 2) โ Chooses a strategy (
deploy_new,optimize_existing,balanced, etc.) and determines how many actions are justified. - Execute (Stage 3) โ Emits JSON recommendations (deploy/move/remove) that the service can auto-execute or queue for the player.
- Cycle Summary (Stage 4) โ Condenses every loop into a headline, highlights, risks, and next-focus bullets for the Gradio timeline.
- After-Action Report โ Once the scenario ends, the agent merges all summaries + metrics into a โbattle reportโ overlay with charts and actionable follow-ups.
- Human-in-the-loop โ Players can pause, inspect reasoning, toggle auto-execute, or manually override/augment deployments at any point.
Prompts for every stage live in prompts.yaml, making it easy to retune instructions without touching Python.
๐ฎ Gameplay Loop & UI Experience
- Start/reset from the control bar or open the accordion to tweak fire count, intensity, building cluster size, max unit slots, and seed.
- The advisor refreshes roughly every 10 ticks. When it is โthinking,โ the HUD animates, and the chat timeline streams stage-by-stage logs.
- Auto-Execute default = ON. Turn it off to require manual approvals (or to stress-test AI reasoning while you handle deployments yourself).
- Click any grid cell to deploy trucks/helis, remove an existing unit, or even ignite a new fire (
๐ฅ Fireoption) in sandbox mode. - Event log + player action chips record everything the human does (deploy, remove, ignite) for inclusion inside the after-action report.
- When success/failure triggers, the overlay shows the outcome, AI battle report, charts (threat trend, coverage, advisor cadence), and manual action summary.
๐ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Gradio 6 Web UI โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Control Panelโ โ 10ร10 Grid โ โ AI Advisor Timeline โ โ
โ โ Start/Pause โ โ ๐ฒ๐ฅ๐๐ข๐ โ โ โข Stage 1-3 logs โ โ
โ โ Reset/Config โ โ Click Deploy โ โ โข Cycle summaries โ โ
โ โ Auto-Execute โ โ Ignite Fires โ โ โข After-action report โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Background Service โ
โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Simulation Engine โโโโโบโ AI Advisor Agent โ โ
โ โ โข Fire spread โ โ โข HuggingFace Inference Provider โ โ
โ โ โข Unit behavior โ โ โข MCP Tool Invocation โ โ
โ โ โข Win/Lose logic โ โ โข Stage 1-4 orchestration โ โ
โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MCP Server (FastMCP) โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โreset_scenarioโ โget_world_ โ โdeploy_unit โ โmove_unit โ โ
โ โโโโโโโโโโโโโโโ โstate โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โstep_ โ โโโโโโโโโโโโโโโ โfind_uncov- โ โfind_build-โ โ
โ โsimulation โ โfind_idle_ โ โered_fires โ โing_threatsโ โ
โ โโโโโโโโโโโโโโโ โunits โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ analyze_coverage โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐งฉ Core Components
app.pyโ Gradio 6 Blocks UI, CSS-heavy HUD, timers, and event handlers for start/pause/reset, auto-execute toggles, and grid interactions.service.pyโ Threaded simulation service with 1s ticks, 10-tick advisor cadence, change-tracked UI diffing, player action tracking, and after-action orchestration.agent.pyโ Multi-stage LLM pipeline that bridges HuggingFaceโs OpenAI-compatible endpoint and native OpenAI APIs, alongside JSON-repair helpers and retry/backoff logic.simulation.pyโ 10ร10 grid-based simulation (fire spread, win/lose rules, unit power/range, building cluster generator, seedable randomness).models.pyโ Dataclasses for world/units/fires/events and serialization helpers used by both Gradio and MCP servers.prompts.yamlโ Configuration for every stage (Assess/Plan/Execute/Summary/After-Action) and model defaults (max_completion_tokens=10000).fire_rescue_mcp/mcp_server.pyโ FastMCP server exposing the sharedSimulationEngineas tools plus helper functions for emoji maps and coverage math.- Product docs โ
fire_rescue_mcp_prd_v3.md(goal/flow) +fire_rescue_mcp_dev_plan_v3.md(implementation milestones) keep the hackathon deliverables aligned.
๐ฏ Game Rules
- Grid: 10ร10 (Chebyshev distance for coverage). Building clusters are procedurally generated but always contiguous.
- Units:
Unit Icon Range Power Notes Fire Truck ๐ 1 tile (8 neighbors) 40% intensity cut Fastest building-defense option Helicopter ๐ 2 tiles 25% per tick Reaches tucked-away or multiple fires - Win: Every fire < 10% intensity (or gone) before 200 ticks.
- Lose: Building integrity < 50% or tick limit hits 200 (time out).
- Map legend: ๐ฒ Forest ยท ๐ข Building ยท ๐ฅ Fire โฅ10% ยท ๐จ Smoke <10% ยท ๐ Truck ยท ๐ Heli.
- Manual testing: Use the grid radio to ignite fires mid-run and watch how the AI responds.
๐ Quick Start
Prerequisites
- Python 3.10+
- uv (optional but fastest)
- HuggingFace API token with access to the OpenAI-compatible inference endpoint (set as
HF_TOKEN)
Environment Variables
export HF_TOKEN=your-huggingface-token-here
# Optional: enable OpenAI GPT-5 models via the new dropdown
export OPENAI_API_KEY=your-openai-key-here
Or create .env next to agent.py:
HF_TOKEN=hf_xxx
OPENAI_API_KEY=sk-...
Launch the Gradio app
# Run with uv (auto activates .venv/.venv)
uv run python app.py
# Or plain Python
python -m app
# Or use the helper restart script for local runs
./restart.sh
Visit http://localhost:7860 to start simulating.
Run the FastMCP server by itself
# Expose MCP tools locally
uv run fire-rescue-mcp
# or explicitly
uv run python -m fire_rescue_mcp.mcp_server
Point your MCP-compatible client at the printed address; all tools described above will be available immediately.
๐ Project Structure
fire-rescue-mcp/
โโโ app.py # Gradio Blocks UI + timers + CSS
โโโ service.py # Simulation loop, advisor cadence, change tracking
โโโ simulation.py # Grid-based fire/units logic & win/lose checks
โโโ agent.py # Multi-stage HuggingFace LLM advisor + after-action writer
โโโ models.py # Dataclasses for world, units, fires, events
โโโ prompts.yaml # Stage prompts + model config
โโโ fire_rescue_mcp/
โ โโโ mcp_server.py # FastMCP tool definitions (10 total)
โโโ fire_rescue_mcp_prd_v3.md # Product requirements / success criteria
โโโ fire_rescue_mcp_dev_plan_v3.md # Development plan & milestones
โโโ pyproject.toml # Project + script definitions
โโโ requirements.txt # Minimal dependency pin list
โโโ README.md # You are here
๐ ๏ธ Technologies Used
| Technology | Purpose |
|---|---|
| Gradio 6 | Responsive Blocks UI, timers, and theming |
| FastMCP | Lightweight MCP server for exposing tools |
| HuggingFace Inference (OpenAI-compatible) | Runs the GPT-OSS 120B/20B and Llama-3.1 8B lineup without vendor lock-in |
| OpenAI Python SDK | Native client for the GPT-5.1 advisor option plus JSON-mode retries |
| UV | Dependency + virtualenv manager |
| Python 3.10+ / dataclasses | Core simulation + service logic |
๐ Real-World Impact / Extensions
- Live wildfire training feed โ Connect real incident telemetry so agencies can rehearse, monitor, or replay responses using the simulator as a digital twin.
- Fire academy decision sandbox โ Turn the UI into a classroom โdecision sand tableโ that logs cadet choices and feeds them back through the LLM for coaching.
- Crisis-planning wargames โ Adapt the scenario generator for municipal tabletop drills, letting planners stress-test evacuations or inter-agency resource sharing.