First Responder Agent (a4i)
October 26, 2025 Β· View on GitHub
An intelligent multi-agent system for emergency response coordination and disaster management. The system orchestrates multiple specialized AI agents to discover disasters, locate relief resources, and synthesize actionable intelligence for first responders.
NEW: Now with a modern web UI powered by CopilotKit + Next.js!
π Table of Contents
- Quick Start - Web UI
- Architecture Overview
- Workflow Execution
- Package Management
- Deployment
- Runner
- Environment Configuration
- Core Components
- Tech Stack
- Key Features
- Project Structure
- Agent Communication
- Extensibility
π Quick Start - Web UI
Prerequisites
- Python 3.12+
- Node.js 18+
- Google Cloud credentials (for agent functionality)
Setup
- Clone and install Python dependencies:
# Create virtual environment with Python 3.12
uv venv --python 3.12
# Activate virtual environment
source .venv/bin/activate
# Install Python dependencies
uv pip install -e .
- Install Node.js dependencies:
cd ui
npm install
cd ..
- Configure environment variables:
Backend environment variables:
# Copy .env.example to .env and fill in your credentials
cp .env.example .env
# Edit .env and add your GOOGLE_API_KEY and GOOGLE_MAPS_API_KEY
Frontend environment variables:
# Copy ui/.env.local.example to ui/.env.local
cp ui/.env.local.example ui/.env.local
# Edit ui/.env.local and add your NEXT_PUBLIC_GOOGLE_MAPS_API_KEY
Note: The UI requires a Google Maps API key to display the interactive map. Get your API key from the Google Cloud Console and make sure to enable Maps JavaScript API, Places API, and Geocoding API.
- Run the development servers:
Terminal 1 - Agent Backend:
source .venv/bin/activate
cd agent
python main.py
Terminal 2 - Next.js UI:
cd ui
npm run dev
- Open the app:
- Web UI: http://localhost:3000
- Agent API: http://localhost:8000
Usage
- Open http://localhost:3000 in your browser
- The UI features a 3-column layout:
- Left: Interactive map showing disaster locations and relief resources
- Center: Chat interface for conversing with the agent
- Right: Agent activity panel showing real-time workflow progress
- Ask questions like:
- "What disasters are happening near San Francisco?"
- "Find relief resources in Los Angeles"
- "What's the weather situation in Miami?"
- Watch the map update with markers and the activity panel track agent execution
ποΈ Architecture Overview
The First Responder Agent follows a hierarchical multi-agent architecture with a root coordinator agent and specialized sub-agents for different domains:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β First Responder Root Agent β
β (Orchestrates workflow & coordinates) β
ββββββββββββββββββ¬βββββββββββββββββββββββ¬βββββββββββββββββββββββββββ
β β
ββββββββββΌβββββββββ ββββββββββΌβββββββββ ββββββββββββββββββ
β Disaster β β Relief β β Insights β
β Discovery β β Finder β β Agent β
β Agent β β Agent β β β
ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ ββββββββββββββββββ
β β
ββββββββββ΄βββββββββββ¬ββββββββ β
β β β β
βββββΌβββ ββββββΌβββββ βββΌβββ ββββΌβββββββ ββββββββββββ ββββββββββββ
βBigQ β βFEMA β βNOAAβ βShelter β βHospital β βSupply β
βData β βLive β βLiveβ βFinder β βFinder β βFinder β
βAgent β βAgent β βAg β βAgent β βAgent β βAgent β
ββββββββ βββββββββββ ββββββ βββββββββββ ββββββββββββ ββββββββββββ
π Workflow Execution
The system executes a coordinated workflow automatically:
- Location Input - User provides their location via chat interface
- Geocoding - Root agent uses
geocode_locationtool to convert location string to coordinates - Disaster Discovery - Root agent delegates to disaster_discovery_agent which:
- Queries BigQuery for historical storm data using
get_ongoing_storms_infotool - Delegates to fema_live_agent for active disaster declarations
- Delegates to noaa_live_agent for weather alerts
- Queries BigQuery for historical storm data using
- Relief Resource Discovery - Root agent delegates to relief_finder_agent which:
- Calls
find_shelterstool (combines BigQuery + Google Maps) - Calls
find_hospitalstool (combines BigQuery + Google Maps) - Calls
find_suppliestool (uses Google Maps)
- Calls
- Insights Synthesis - Root agent delegates to insights_agent for comprehensive analysis
- Map Updates - Throughout execution, tools automatically update the shared state with location markers
- Final Response - Root agent presents synthesized insights to user via chat
π¦ Package Management
This project uses UV for fast Python package management.
# Install dependencies
uv sync
# Add a dependency
uv add package_name
# Add a dev dependency
uv add --dev package_name
# Update dependencies
uv sync --upgrade
The uv.lock file ensures reproducible builds across environments.
π Deployment
The system is deployed to Google Cloud using the ADK deployment tool:
python deploy.py
π¬ Conversational Runner
After deployment, interact with the agent through a conversational chat interface:
uv run python runner.py
This starts an interactive chat loop where you can:
- Type messages to query the First Responder Agent
- Receive streaming responses in real-time
- Have multi-turn conversations
- Exit with
exitorquitcommands
The runner uses environment variables from .env to connect to your deployed agent.
π Environment Configuration
For required environment variables, refer .env.example
π¦ Core Components
Root Agent: first_responder_agent/agent.py
- Name:
first_responder - Model: Gemini 2.5 Flash
- Role: Main orchestrator that coordinates the workflow
- Tools:
geocode_location(converts location strings to coordinates) - Sub-agents: Disaster Discovery, Relief Finder, Insights
- State Management: Tracks locations, map center, current agent, and activity history
Disaster Discovery Agent: disaster_discovery_agent/agent.py
Discovers and locates disasters using multiple data sources:
-
BigQuery Storm Data Tool (
common/bigquery_tools.py)- Queries historical storm locations and data from BigQuery
- Proximity-based search (default 25-mile radius)
- Accesses
StormLocationsdataset
-
FEMA Live Agent (
disaster_discovery_agent/fema_live_agent/agent.py)- Queries active disaster declarations via OpenFEMA API
- Retrieves FEMA assistance programs and funding information
- Filters by state and disaster type
-
NOAA Live Agent (
disaster_discovery_agent/noaa_live_agent/agent.py)- Queries active weather alerts via NOAA Weather API
- Retrieves severe weather outlooks
- Location-based weather queries
Relief Finder Agent: relief_finder_agent/agent.py
Locates relief resources and support infrastructure:
-
Shelter Finder Tool (
relief_finder_agent/shelter_finder_tool.py)- Combines BigQuery shelter data with Google Maps Places API
- Locates emergency shelters and lodging facilities
- Provides comprehensive shelter information
-
Hospital Finder Tool (
relief_finder_agent/hospital_finder_tool.py)- Combines BigQuery hospital data with Google Maps Places API
- Locates medical facilities
- Queries hospital capacity and services
-
Supply Finder Tool (
relief_finder_agent/supply_finder_tool.py)- Uses Google Maps Places API to find pharmacies
- Locates relief supply distribution points
Insights Agent: insights_agent/agent.py
Synthesizes all collected data into comprehensive analysis:
- Combines disaster and relief data
- Generates actionable recommendations
- Prioritizes response actions
- Provides situational awareness
Common Utilities: common/
-
Geocoding (
common/geocoding.py)- Converts location strings to coordinates
- Uses Google Maps Geocoding API
-
BigQuery Tools (
common/bigquery_tools.py)- Queries storm data from BigQuery
StormLocationsdataset - Queries shelter data from BigQuery
Shelterdataset - Provides hospital capacity checking (placeholder)
- Provides supply inventory checking (placeholder)
- Queries storm data from BigQuery
-
Search Places Tool (
common/search_places_tool.py)- Searches for nearby places using Google Maps Places API
- Automatically updates map state with location markers
- Supports multiple place types (hospitals, shelters, pharmacies, etc.)
-
State Tools (
common/state_tools.py)- Manages agent activity tracking
- Updates shared state across agents
π§ Tech Stack
Backend
- Framework: Google ADK (Agent Development Kit)
- LLM Models:
- Gemini 2.5 Flash (root agent, sub-agents)
- Gemini 2.5 Pro (disaster discovery agent)
- API: FastAPI + Uvicorn
- Data Sources:
- BigQuery (historical storm data from
StormLocations, shelter data fromShelter) - FEMA OpenFEMA API (disaster declarations and assistance programs)
- NOAA Weather API (active weather alerts)
- Google Maps API (geocoding and places search)
- BigQuery (historical storm data from
- Language: Python 3.12+
- Package Manager: UV (fast Python package manager)
- Dependencies:
google-adk>=1.16.0- Agent frameworkfastapi>=0.104.0- Web API frameworkuvicorn>=0.24.0- ASGI serverag-ui-adk>=0.3.1- AG-UI protocol adapter for ADKpydantic>=2.12.2- Data validationpython-dotenv>=1.1.1- Environment configurationgooglemaps>=4.10.0- Google Maps API client
Frontend
- Framework: Next.js 16.0.0 (React 19.2.0)
- UI Library: CopilotKit React Components
- Styling: Tailwind CSS 4
- Language: TypeScript 5
- Map Libraries: Leaflet + React Leaflet
- Dependencies:
@copilotkit/react-core@^1.10.6- CopilotKit core@copilotkit/react-ui@^1.10.6- CopilotKit UI components@copilotkit/runtime@^1.10.6- CopilotKit runtime@ag-ui/client@^0.0.40- AG-UI client for ADK integrationleaflet@^1.9.4- Interactive mapsreact-leaflet@^5.0.0- React wrapper for Leaflet
π― Key Features
- Modern Web UI - Interactive 3-column layout with map, chat, and agent activity tracking
- Real-time Agent Monitoring - Visual feedback on agent execution and workflow progress
- Interactive Map - Leaflet-based map showing disaster locations and relief resources
- Automatic Workflow Execution - No manual intervention between steps
- Multi-Source Data Integration - Combines BigQuery, FEMA, NOAA, and Google Maps data
- Intelligent Synthesis - AI-powered analysis of complex disaster scenarios
- Scalable Architecture - Easy to add new agents and data sources
- Comprehensive Logging - Detailed execution tracking for debugging
- State Management - Shared state across agents for coordinated responses
π Project Structure
a4i/
βββ first_responder_agent/ # Core agent system
β βββ agent.py # Root agent
β βββ common/
β β βββ geocoding.py # Location geocoding
β β βββ bigquery_tools.py # BigQuery queries (storms, shelters)
β β βββ search_places_tool.py # Google Maps Places API integration
β β βββ state_tools.py # Agent state management
β βββ disaster_discovery_agent/
β β βββ agent.py # Disaster discovery coordinator
β β βββ fema_live_agent/
β β β βββ agent.py # FEMA OpenFEMA API queries
β β βββ noaa_live_agent/
β β βββ agent.py # NOAA Weather API queries
β βββ relief_finder_agent/
β β βββ agent.py # Relief finder coordinator
β β βββ shelter_finder_tool.py # Shelter location tool
β β βββ hospital_finder_tool.py # Hospital location tool
β β βββ supply_finder_tool.py # Supply location tool
β βββ insights_agent/
β βββ agent.py # Analysis & synthesis
βββ agent/ # FastAPI backend wrapper
β βββ main.py # FastAPI app with AG-UI ADK integration
β βββ __init__.py
βββ ui/ # Next.js frontend
β βββ app/
β β βββ api/copilotkit/
β β β βββ route.ts # CopilotKit API route with AG-UI client
β β βββ layout.tsx # Root layout with CopilotKit provider
β β βββ page.tsx # Main page with 3-column layout
β β βββ globals.css # Global styles
β βββ components/
β β βββ MapPanel.tsx # Interactive map component
β β βββ AgentProcessingPanel.tsx # Agent activity tracking panel
β β βββ LeafletMap.tsx # Leaflet map implementation
β β βββ ... # Other UI components
β βββ package.json # Node.js dependencies
β βββ next.config.ts # Next.js configuration
βββ deploy.py # Cloud deployment script (ADK)
βββ runner.py # CLI conversational runner
βββ pyproject.toml # Python project configuration
βββ uv.lock # UV lock file for dependencies
βββ .env.example # Example environment variables
βββ README.md # This file
π Agent Communication
Agents communicate through:
- Tool Calls - Agents invoke tools to query data (BigQuery, APIs, Google Maps)
- Sub-agent Delegation - Parent agents delegate to child agents for specialized tasks
- Shared State - All agents access and update shared state for coordination
- Activity Tracking - State tools track agent execution status (running, completed)
- Structured Results - All results returned as dictionaries with status and data
- Callback Hooks -
before_agent_callbackandafter_agent_callbackfor state management
π Extensibility
The architecture supports easy extension:
- Add New Data Sources - Create new tools in
common/or new sub-agents - Add Relief Resource Types - Create new finder tools following the existing pattern
- Enhance Analysis - Extend the Insights Agent with additional analysis capabilities
- Integrate New APIs - Add new API integrations as tools or sub-agents
- Customize UI - Add new components to the Next.js frontend
- Extend State - Add new state fields for tracking additional information