pip install -r requirements.txt-
Google AI API Key
- Visit: https://aistudio.google.com/apikey
- Create a new API key
- Copy the key
-
OpenRouteService API Key
- Visit: https://openrouteservice.org/dev/#/signup
- Sign up for free account
- Get your API key from dashboard
-
OpenWeather API Key
- Visit: https://openweathermap.org/api
- Sign up for free account
- Get your API key
Create a .env file in the project root:
GOOGLE_API_KEY=your_google_api_key_here
ORS_API_KEY=your_ors_api_key_here
OPENWEATHER_API_KEY=your_openweather_api_key_herepython demo.pyThis will run 4 demo scenarios:
- Single route analysis
- Batch route analysis (parallel)
- Memory & preferences
- Observability
import asyncio
from saferouteai import SafeRouteOrchestrator
async def main():
# Create orchestrator
orchestrator = SafeRouteOrchestrator(session_id="my_session")
# Analyze a route
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 results
print(f"Risk Score: {result['summary']['risk_score']}/10")
print(f"Risk Level: {result['summary']['risk_level']}")
# Get safety alert
alert = result['safety_alert']['alert']['formatted_alert']
print(alert)
asyncio.run(main())routes = [
{"start": "37.7749,-122.4194", "destination": "37.6213,-122.3790"},
{"start": "37.8715,-122.2730", "destination": "37.8044,-122.2712"},
]
results = await orchestrator.batch_analyze_routes(routes)orchestrator.update_user_preferences({
"risk_tolerance": "low",
"alert_threshold": 3.0
})
result = await orchestrator.analyze_route_safety(...)The system includes fallback mechanisms:
- Route analysis: Uses straight-line distance if ORS key missing
- Weather: Returns moderate risk if OpenWeather key missing
- Crime data: Uses fallback assessment
Note: For full functionality, all API keys are recommended.
- 0-3: Safe ✅
- 4-6: Moderate ⚡
- 7-10: Hazardous
⚠️
{
"success": True,
"summary": {
"risk_score": 5.2,
"risk_level": "Moderate",
"distance_km": 12.5,
"duration_minutes": 18.3
},
"risk_assessment": {
"risk_breakdown": {...},
"primary_risks": [...]
},
"safety_alert": {
"alert": {
"formatted_alert": "..."
}
},
"route_optimization": {...} # Only if risk >= 4
}# Make sure you're in the project root
cd "capstone project"
python demo.py- Check
.envfile exists and has correct keys - Verify API keys are valid
- Check API quotas (free tiers have limits)
- Verify coordinates are in "lat,lon" format
- Check internet connection
- Review logs in
logs/directory
saferouteai/
├── agents/ # 5 specialized agents
├── memory/ # Session management
├── observability/ # Logging & tracing
└── orchestrator.py # Multi-agent coordinator
demo.py # Demo script
logs/ # Generated logs
sessions/ # Session data
- Run
demo.pyto see all features - Check
logs/for detailed operation logs - Review
sessions/for stored route history - Customize
saferouteai/config.pyfor your needs
- Use session IDs to track multiple users
- Enable memory to build route history
- Check trace statistics for performance insights
- Customize risk thresholds in config.py
Ready to analyze routes safely! 🛣️