A multi-agent AI system that analyzes route safety in real-time by combining crime data, weather conditions, traffic, time of day, and lighting conditions to provide safety recommendations.
SafeRouteAI is an autonomous multi-agent system built with Google AI Agent SDK that evaluates the safety of walking/driving routes by analyzing multiple risk factors and recommending safer alternatives when needed.
- Multi-Agent System: 5 specialized agents working together
- Real-Time Analysis: Weather, crime, lighting, and time-based risk assessment
- Route Optimization: Suggests safer alternative routes
- Memory & Sessions: Remembers user preferences and route history
- Observability: Comprehensive logging and tracing
- Parallel Processing: Batch route analysis support
- Route Analysis Agent: Extracts route coordinates, distance, and waypoints
- Safety Data Agent: Gathers weather, crime, lighting, and time-of-day data
- Risk Scoring Agent: Computes combined risk scores (0-10 scale)
- Route Optimization Agent: Suggests safer alternatives for high-risk routes
- Alert Agent: Generates human-readable safety guidance
- Sequential Agents: Route Analysis β Safety Data β Risk Scoring β Alert
- Parallel Agents: Batch route analysis with concurrent processing
- Conditional Agents: Route Optimization only triggers for moderate/high risk routes
- Loop Agents: Session memory maintains history across multiple analyses
- Route Planning Tool: OpenRouteService integration for route calculation
- Weather Tool: OpenWeather API for real-time weather conditions
- Lighting Tool: Sunrise-sunset API for daylight assessment
- Crime Data Tool: Fallback crime risk assessment (extensible for real APIs)
- Time Safety Tool: Time-of-day risk calculation
- Risk Calculator Tool: Combined risk score computation
- Route Comparison Tool: Compare original vs alternative routes
- Alert Formatter Tool: Format safety alerts with appropriate severity
- OpenRouteService: Free tier routing API
- OpenWeather: Free tier weather API
- Sunrise-Sunset API: Free daylight times API
- Crime Data: Extensible for police.uk, city datasets, or Kaggle datasets
β Multi-Agent System
- Agent powered by LLM (Gemini 2.0 Flash)
- Sequential agents (pipeline pattern)
- Parallel agents (batch processing)
- Conditional agents (optimization only when needed)
β Tools
- Custom tools (route, weather, lighting, crime, risk calculation)
- Built-in tools (Google Search available via SDK)
- OpenAPI tools (OpenRouteService, OpenWeather)
β Sessions & Memory
- InMemorySessionService (session_manager.py)
- Long-term memory (route history, user preferences)
- Context engineering (session-based state management)
β Observability
- Logging (file and console handlers)
- Tracing (operation timing and context)
- Metrics (operation statistics)
- Clone the repository
git clone <repository-url>
cd "capstone project"- Install dependencies
pip install -r requirements.txt- Set up environment variables
cp .env.example .env
# Edit .env and add your API keys- Get API Keys (all free tiers available):
- Google AI: https://aistudio.google.com/apikey
- OpenRouteService: https://openrouteservice.org/dev/#/signup
- OpenWeather: https://openweathermap.org/api
import asyncio
from saferouteai import SafeRouteOrchestrator
async def main():
orchestrator = SafeRouteOrchestrator(session_id="my_session")
result = await orchestrator.analyze_route_safety(
start="37.7749,-122.4194", # San Francisco
destination="37.6213,-122.3790", # SFO Airport
route_type="driving-car"
)
print(f"Risk Score: {result['summary']['risk_score']}/10")
print(f"Risk Level: {result['summary']['risk_level']}")
print(result['safety_alert']['alert']['formatted_alert'])
asyncio.run(main())python demo.pyThe demo showcases:
- Single route analysis
- Batch route analysis (parallel agents)
- Memory and user preferences
- Observability features
Risk scores are calculated on a 0-10 scale:
- 0-3: Safe - Route is safe to travel
- 4-6: Moderate - Exercise caution
- 7-10: Hazardous - Consider alternative route or delay travel
- Weather Risk (0-3): Rain, storms, extreme temperatures, poor visibility
- Crime Risk (0-3): Crime data near route (extensible for real APIs)
- Lighting Risk (0-2): Dark hours increase risk
- Time Risk (0-2): Late night/early morning hours increase risk
capstone project/
βββ saferouteai/
β βββ __init__.py
β βββ config.py # Configuration
β βββ orchestrator.py # Multi-agent orchestrator
β βββ agents/
β β βββ route_analysis_agent.py
β β βββ safety_data_agent.py
β β βββ risk_scoring_agent.py
β β βββ route_optimization_agent.py
β β βββ alert_agent.py
β βββ memory/
β β βββ __init__.py
β β βββ session_manager.py # Session & memory management
β βββ observability/
β βββ __init__.py
β βββ logger.py # Logging setup
β βββ tracer.py # Operation tracing
βββ demo.py # Demo script
βββ requirements.txt
βββ .env.example
βββ README.md
The system includes 5 example routes for evaluation:
- Downtown to Airport
- University to Park
- City Walk
- Evening Commute
- Late Night Route
- Risk scores for each route
- Safety recommendations
- Alternative route suggestions
- Session statistics (average risk, high-risk routes)
- Operation performance (tracing stats)
- "Is this route safe right now?" - Real-time risk assessment
- "Recommend a safer alternative." - Route optimization for high-risk routes
- "Alert me if risk changes." - Session memory tracks route history
β
Problem Statement: Real-world safety problem for route planning
β
System Design: Multi-agent architecture with 5 specialized agents
β
Agent Architecture: Sequential, parallel, and conditional patterns
β
Tools: 8+ custom tools for route, weather, safety data
β
Pseudocode: Clear agent coordination in orchestrator
β
Demo Flow: Complete demo script with 4 scenarios
β
Evaluation Notes: Risk scoring, route comparison, statistics
Edit saferouteai/config.py to customize:
- Model selection (default: gemini-2.0-flash-exp)
- Risk thresholds (moderate: 4, hazardous: 7)
- API endpoints
- Logging levels
- Real crime data API integration (police.uk, city datasets)
- Traffic and accident data integration
- Real-time route monitoring and alerts
- Mobile app integration
- Historical route safety trends
This project is part of a capstone submission demonstrating multi-agent AI systems.
- Google AI Agent SDK
- OpenRouteService for routing
- OpenWeather for weather data
- Sunrise-Sunset API for daylight times
Built with Google AI Agent SDK | Multi-Agent System | Real-Time Safety Analysis